Skip to content

Commit

Permalink
Segmented images not deleted cleanly from swift.
Browse files Browse the repository at this point in the history
Ensure the manifest is deleted in addition to the image data segments.

Fixes Bug #1144681

Change-Id: I64dd07e6b7a1c4bcbb0a230ec3b7f4d365ec5ae8
  • Loading branch information
Therese McHale authored and Stuart McLaren committed Mar 14, 2013
1 parent e75764e commit 157cce7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
8 changes: 4 additions & 4 deletions glance/store/swift.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,11 +409,11 @@ def delete(self, location, connection=None):
# since we're simply sending off parallelizable requests
# to Swift to delete stuff. It's not like we're going to
# be hogging up network or file I/O here...
connection.delete_object(
obj_container, segment['name'])
connection.delete_object(obj_container,
segment['name'])

else:
connection.delete_object(location.container, location.obj)
# Delete object (or, in segmented case, the manifest)
connection.delete_object(location.container, location.obj)

except swiftclient.ClientException, e:
if e.http_status == httplib.NOT_FOUND:
Expand Down
29 changes: 26 additions & 3 deletions glance/tests/functional/store/test_swift.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,15 @@ def test_object_chunking(self):
self.assertTrue(headers.get('content-length'))

# Since we used a 5 MB image with a 2 MB chunk size, we should
# expect to see the manifest object and three data objects for
# a total of 4
self.assertEqual(4, len(segments), 'Got segments %s' % segments)
# expect to see three data objects
self.assertEqual(3, len(segments), 'Got segments %s' % segments)

# Add an object that should survive the delete operation
non_image_obj = image_id + '0'
swift_put_object(self.swift_client,
manifest_container,
non_image_obj,
'XXX')

store.delete(location)

Expand All @@ -260,6 +266,23 @@ def test_object_chunking(self):
manifest_container,
segment)

# Verify the manifest is gone too
self.assertRaises(swiftclient.ClientException,
swift_head_object,
self.swift_client,
manifest_container,
swift_location.obj)

# Verify that the non-image object was not deleted
headers = swift_head_object(self.swift_client,
manifest_container,
non_image_obj)
self.assertTrue(headers.get('content-length'))

# Clean up
self.swift_client.delete_object(manifest_container,
non_image_obj)

def stash_image(self, image_id, image_data):
container_name = self.swift_config['swift_store_container']
swift_put_object(self.swift_client,
Expand Down

0 comments on commit 157cce7

Please sign in to comment.