From 07a8213437e41311335fe59c433c690475a34e6b Mon Sep 17 00:00:00 2001 From: Dongdong Zhou Date: Wed, 8 May 2013 21:06:41 +0100 Subject: Pass None to image if booted from volume in live migration The destination check in live migration will fetch the image information from glance and it will throw ImageNotFound if the instance is booted from volume since there is no image id on the instance Fix bug 1170596 Change-Id: Ie683a3ca5d6430c52ead77b41f98fbcb4114ea1e --- nova/scheduler/driver.py | 6 +++++- nova/tests/scheduler/test_scheduler.py | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/nova/scheduler/driver.py b/nova/scheduler/driver.py index 506c77cff..4ad6b8513 100644 --- a/nova/scheduler/driver.py +++ b/nova/scheduler/driver.py @@ -258,7 +258,11 @@ class Scheduler(object): # If dest is not specified, have scheduler pick one. if dest is None: instance_type = flavors.extract_instance_type(instance_ref) - image = self.image_service.show(context, instance_ref['image_ref']) + if not instance_ref['image_ref']: + image = None + else: + image = self.image_service.show(context, + instance_ref['image_ref']) request_spec = {'instance_properties': instance_ref, 'instance_type': instance_type, 'instance_uuids': [instance_ref['uuid']], diff --git a/nova/tests/scheduler/test_scheduler.py b/nova/tests/scheduler/test_scheduler.py index 60d45fed4..f4f607647 100644 --- a/nova/tests/scheduler/test_scheduler.py +++ b/nova/tests/scheduler/test_scheduler.py @@ -808,6 +808,31 @@ class SchedulerTestCase(test.TestCase): None, ignore_hosts) self.assertEqual('fake_host2', result) + def test_live_migration_dest_check_no_image(self): + instance = self._live_migration_instance() + instance['image_ref'] = '' + + # Confirm dest is picked by scheduler if not set. + self.mox.StubOutWithMock(self.driver, 'select_hosts') + self.mox.StubOutWithMock(flavors, 'extract_instance_type') + + request_spec = {'instance_properties': instance, + 'instance_type': {}, + 'instance_uuids': [instance['uuid']], + 'image': None + } + ignore_hosts = [instance['host']] + filter_properties = {'ignore_hosts': ignore_hosts} + + flavors.extract_instance_type(instance).AndReturn({}) + self.driver.select_hosts(self.context, request_spec, + filter_properties).AndReturn(['fake_host2']) + + self.mox.ReplayAll() + result = self.driver._live_migration_dest_check(self.context, instance, + None, ignore_hosts) + self.assertEqual('fake_host2', result) + def test_live_migration_auto_set_dest(self): instance = self._live_migration_instance() -- cgit