Merge lp:~danilo/simplestreams/ignore-inactive-images into lp:simplestreams

Proposed by Данило Шеган
Status: Merged
Merged at revision: 433
Proposed branch: lp:~danilo/simplestreams/ignore-inactive-images
Merge into: lp:simplestreams
Diff against target: 15 lines (+5/-0)
1 file modified
simplestreams/mirrors/ (+5/-0)
To merge this branch: bzr merge lp:~danilo/simplestreams/ignore-inactive-images
Reviewer Review Type Date Requested Status
simplestreams-dev Pending
Review via email:

Description of the change

If connection to glance is broken during GlanceMirror.sync(), and image would be left over in "status": "saving".

Glance itself tries to protect against that, however when it is restarted (eg. "service glance-api restart"), it does not clean the image up. (I still think glance should be fixed to at least clean up "saving" images when it's gracefully restarted, so I'll file a bug about that if I can find exactly where to do that :).

This change makes load_product() ignore any images that do not have "status": "active". I wasn't sure if I should maybe only check for status != "saving" instead, but it seems images can only have deleted, active or saving status, so this should be good.

Note that this isn't perfect. The image in "saving" state is never cleaned up, but at least the resulting cloud works. If we want to clean up broken images, it'd be hard to do on the simplestreams side (glance is better placed to do that: it knows if anything is going on with any of them, eg. is it being currently updated or not).

I didn't provide any tests though: load_products is currently untested and would need some serious refactoring or mocking and faking to get any decent test for this.

To post a comment you must log in.
Revision history for this message
Scott Moser (smoser) wrote :

is status going to be guaranteed to be there in all image response?
I suspect it is, but should be reasonable sure of that so we dont get a KeyError on image['status']

Revision history for this message
Данило Шеган (danilo) wrote :

That's a good point. I'll double check glance code once again, though it seemed to me that image is first created with {"status": "saving"}, and on successful upload completion turned into {"status": "active"}. Will report back when I look at it (tomorrow).

Of course, there's no harm in doing image.get('status') as well to ensure we don't hit the problem even if things change in glance.

433. By Данило Шеган on 2016-05-20

Switch to .get('status') to not barf when image does not have status defined.

434. By Данило Шеган on 2016-05-20

Be consistent in using .get().

Revision history for this message
Данило Шеган (danilo) wrote :

I've confirmed that status is always defined from the looks of it, but switched to .get('status') just in case.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'simplestreams/mirrors/'
2--- simplestreams/mirrors/ 2016-05-05 12:35:42 +0000
3+++ simplestreams/mirrors/ 2016-05-20 15:34:01 +0000
4@@ -179,6 +179,11 @@
5 if props.get('content_id') != my_cid:
6 continue
8+ if image.get('status') != "active":
9+ LOG.warn("Ignoring inactive image %s with status '%s'" % (
10+ image['id'], image.get('status')))
11+ continue
13 source_content_id = props.get('source_content_id')
15 product = props.get('product_name')


People subscribed via source and target branches