Skip to content

Commit

Permalink
Do not fail to build a snapshot if base image is not found
Browse files Browse the repository at this point in the history
This fixes bug #968066

Change-Id: I1959e4dd7cb19acef54f0e857f4d8b3d40985b77
  • Loading branch information
Julien Danjou authored and vishvananda committed Apr 3, 2012
1 parent ccb93c4 commit 477ced4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
34 changes: 34 additions & 0 deletions nova/tests/test_libvirt.py
Expand Up @@ -712,6 +712,40 @@ def test_snapshot_no_image_architecture(self):
self.assertEquals(snapshot['status'], 'active')
self.assertEquals(snapshot['name'], snapshot_name)

@test.skip_if(missing_libvirt(), "Test requires libvirt")
def test_snapshot_no_original_image(self):
self.flags(image_service='nova.image.fake.FakeImageService')

# Start test
image_service = utils.import_object(FLAGS.image_service)

# Assign a non-existent image
test_instance = copy.deepcopy(self.test_instance)
test_instance["image_ref"] = '661122aa-1234-dede-fefe-babababababa'

instance_ref = db.instance_create(self.context, test_instance)
properties = {'instance_id': instance_ref['id'],
'user_id': str(self.context.user_id)}
snapshot_name = 'test-snap'
sent_meta = {'name': snapshot_name, 'is_public': False,
'status': 'creating', 'properties': properties}
recv_meta = image_service.create(context, sent_meta)

self.mox.StubOutWithMock(connection.LibvirtConnection, '_conn')
connection.LibvirtConnection._conn.lookupByName = self.fake_lookup
self.mox.StubOutWithMock(connection.utils, 'execute')
connection.utils.execute = self.fake_execute

self.mox.ReplayAll()

conn = connection.LibvirtConnection(False)
conn.snapshot(self.context, instance_ref, recv_meta['id'])

snapshot = image_service.show(context, recv_meta['id'])
self.assertEquals(snapshot['properties']['image_state'], 'available')
self.assertEquals(snapshot['status'], 'active')
self.assertEquals(snapshot['name'], snapshot_name)

def test_attach_invalid_volume_type(self):
self.create_fake_libvirt_mock()
connection.LibvirtConnection._conn.lookupByName = self.fake_lookup
Expand Down
8 changes: 6 additions & 2 deletions nova/virt/libvirt/connection.py
Expand Up @@ -619,7 +619,11 @@ def snapshot(self, context, instance, image_href):

(image_service, image_id) = nova.image.get_image_service(
context, instance['image_ref'])
base = image_service.show(context, image_id)
try:
base = image_service.show(context, image_id)
except exception.ImageNotFound:
base = {}

_image_service = nova.image.get_image_service(context, image_href)
snapshot_image_service, snapshot_image_id = _image_service
snapshot = snapshot_image_service.show(context, snapshot_image_id)
Expand All @@ -635,7 +639,7 @@ def snapshot(self, context, instance, image_href):
'ramdisk_id': instance['ramdisk_id'],
}
}
if 'architecture' in base['properties']:
if 'architecture' in base.get('properties', {}):
arch = base['properties']['architecture']
metadata['properties']['architecture'] = arch

Expand Down

0 comments on commit 477ced4

Please sign in to comment.