Просмотр исходного кода

Fix and test for image_id property on instance.

Nuwan Goonasekera 10 лет назад
Родитель
Сommit
616758d331

+ 5 - 1
cloudbridge/cloud/providers/openstack/resources.py

@@ -292,7 +292,11 @@ class OpenStackInstance(BaseInstance):
         """
         Get the image ID for this instance.
         """
-        return self._os_instance.image.get("id")
+        # In OpenStack, the Machine Image of a running instance may
+        # be deleted, so make sure the image exists before attempting to
+        # retrieve its id
+        return (self._os_instance.image.get("id")
+                if self._os_instance.image else "")
 
     @property
     def placement_zone(self):

+ 3 - 0
test/test_compute_service.py

@@ -126,6 +126,9 @@ class CloudComputeServiceTestCase(ProviderTestBase):
             self.assertEqual(test_instance.image_id, image_id,
                              "Image id {0} is not equal to the expected id"
                              " {1}".format(test_instance.image_id, image_id))
+            self.assertEqual(
+                test_instance.image_id,
+                helpers.get_provider_test_data(self.provider, "image"))
             self.assertIsInstance(test_instance.public_ips, list)
             self.assertIsInstance(test_instance.private_ips, list)
             self.assertEqual(