Fix to tackle instances without an image assigned
fixes bug #1233103 Change-Id: I4d4d7bdff09b6748e14ebac8293050513fb18ed2
This commit is contained in:
parent
2245becc28
commit
e36f9f32fe
@ -82,7 +82,14 @@ class Client(object):
|
|||||||
instance.flavor[attr] = getattr(flavor, attr, default)
|
instance.flavor[attr] = getattr(flavor, attr, default)
|
||||||
|
|
||||||
def _with_image(self, instance):
|
def _with_image(self, instance):
|
||||||
iid = instance.image['id']
|
try:
|
||||||
|
iid = instance.image['id']
|
||||||
|
except TypeError:
|
||||||
|
instance.image = None
|
||||||
|
instance.kernel_id = None
|
||||||
|
instance.ramdisk_id = None
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
image = self.nova_client.images.get(iid)
|
image = self.nova_client.images.get(iid)
|
||||||
except novaclient.exceptions.NotFound:
|
except novaclient.exceptions.NotFound:
|
||||||
|
@ -132,6 +132,14 @@ class TestNovaClient(test.BaseTestCase):
|
|||||||
a.image = {'id': args[0]}
|
a.image = {'id': args[0]}
|
||||||
return [a]
|
return [a]
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def fake_instance_image_missing(*args, **kwargs):
|
||||||
|
a = mock.MagicMock()
|
||||||
|
a.id = 42
|
||||||
|
a.flavor = {'id': 666}
|
||||||
|
a.image = None
|
||||||
|
return [a]
|
||||||
|
|
||||||
def test_instance_get_all_by_host_unknown_image(self):
|
def test_instance_get_all_by_host_unknown_image(self):
|
||||||
with patch.object(self.nv.nova_client.servers, 'list',
|
with patch.object(self.nv.nova_client.servers, 'list',
|
||||||
side_effect=self.fake_servers_list_unknown_image):
|
side_effect=self.fake_servers_list_unknown_image):
|
||||||
@ -196,3 +204,11 @@ class TestNovaClient(test.BaseTestCase):
|
|||||||
instance = results[0]
|
instance = results[0]
|
||||||
self.assertIsNone(instance.kernel_id)
|
self.assertIsNone(instance.kernel_id)
|
||||||
self.assertEqual(instance.ramdisk_id, 21)
|
self.assertEqual(instance.ramdisk_id, 21)
|
||||||
|
|
||||||
|
def test_with_missing_image_instance(self):
|
||||||
|
instances = self.fake_instance_image_missing()
|
||||||
|
results = self.nv._with_flavor_and_image(instances)
|
||||||
|
instance = results[0]
|
||||||
|
self.assertIsNone(instance.kernel_id)
|
||||||
|
self.assertIsNone(instance.image)
|
||||||
|
self.assertIsNone(instance.ramdisk_id)
|
||||||
|
Loading…
Reference in New Issue
Block a user