summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikola Dipanov <ndipanov@redhat.com>2013-05-20 17:33:47 +0200
committerNikola Dipanov <ndipanov@redhat.com>2013-05-20 17:44:11 +0200
commit4465b705fc7cb7a150a7f8d6f70ccf6c20ff3284 (patch)
treebb612709c0f9ded7c5f9d39d139acec00233844e
parent5c3113b066e61cbc5d8d4d464f8200d4cb5e8395 (diff)
downloadnova-4465b705fc7cb7a150a7f8d6f70ccf6c20ff3284.tar.gz
nova-4465b705fc7cb7a150a7f8d6f70ccf6c20ff3284.tar.xz
nova-4465b705fc7cb7a150a7f8d6f70ccf6c20ff3284.zip
Fix resize when instance has no image
This patch makes it possible to resize an instance that has no image supplied (was booted from volume), by avoiding calling the image service and thus causing an uncaught exception, if there was no image suplied in the first place. Fixes bug: 1182114 blueprint: improve-boot-from-volume Change-Id: I67d63a7aef699b555897582c74b04e857db7aafb
-rw-r--r--nova/compute/api.py6
-rw-r--r--nova/tests/compute/test_compute.py16
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'])