diff options
-rw-r--r-- | nova/compute/api.py | 6 | ||||
-rw-r--r-- | nova/tests/compute/test_compute.py | 16 |
2 files changed, 21 insertions, 1 deletions
diff --git a/nova/compute/api.py b/nova/compute/api.py index f31aefb9b..518678524 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -2020,7 +2020,11 @@ class API(base.Base): raise exception.FlavorNotFound(flavor_id=flavor_id) # NOTE(markwash): look up the image early to avoid auth problems later - image = self.image_service.show(context, instance['image_ref']) + image_ref = instance.get('image_ref') + if image_ref: + image = self.image_service.show(context, image_ref) + else: + image = {} if same_instance_type and flavor_id: raise exception.CannotResizeToSameFlavor() diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py index 3101e3aa2..36a6a36a6 100644 --- a/nova/tests/compute/test_compute.py +++ b/nova/tests/compute/test_compute.py @@ -6155,6 +6155,22 @@ class ComputeAPITestCase(BaseTestCase): self.context, instance) self.compute.terminate_instance(self.context, instance=instance) + def test_resize_no_image(self): + def _fake_prep_resize(_context, **args): + image = args['image'] + self.assertEqual(image, {}) + + instance = self._create_fake_instance(params={'image_ref': ''}) + instance = db.instance_get_by_uuid(self.context, instance['uuid']) + instance = jsonutils.to_primitive(instance) + self.compute.run_instance(self.context, instance=instance) + + self.stubs.Set(self.compute_api.scheduler_rpcapi, + 'prep_resize', _fake_prep_resize) + + self.compute_api.resize(self.context, instance, None) + self.compute.terminate_instance(self.context, instance=instance) + def test_migrate(self): instance = self._create_fake_instance() instance = db.instance_get_by_uuid(self.context, instance['uuid']) |