2
0
Эх сурвалжийг харах

Adding test for instance creation from custom image

almahmoud 7 жил өмнө
parent
commit
e6aa888ac1

+ 7 - 4
cloudbridge/cloud/providers/azure/resources.py

@@ -1342,10 +1342,13 @@ class AzureInstance(BaseInstance):
         """
         # Not tested for resource group images
         reference_dict = self._vm.storage_profile.image_reference.as_dict()
-        return ':'.join([reference_dict['publisher'],
-                         reference_dict['offer'],
-                         reference_dict['sku'],
-                         reference_dict['version']])
+        if reference_dict.get('publisher'):
+            return ':'.join([reference_dict['publisher'],
+                             reference_dict['offer'],
+                             reference_dict['sku'],
+                             reference_dict['version']])
+        else:
+            return reference_dict['id']
 
     @property
     def zone_id(self):

+ 1 - 1
setup.cfg

@@ -3,7 +3,7 @@ branch = True
 source = cloudbridge
 omit =
   cloudbridge/cloud/interfaces/*
-  __init__.py
+  cloudbridge/__init__.py
 
 [nosetests]
 with-coverage=1

+ 38 - 1
test/test_image_service.py

@@ -1,5 +1,5 @@
 from cloudbridge.cloud.interfaces import MachineImageState
-from cloudbridge.cloud.interfaces.resources import MachineImage
+from cloudbridge.cloud.interfaces.resources import Instance, MachineImage
 
 from test import helpers
 from test.helpers import ProviderTestBase
@@ -19,6 +19,7 @@ class CloudImageServiceTestCase(ProviderTestBase):
         label is the expected one and whether list_images is functional.
         """
         instance_label = "cb-crudimage-{0}".format(helpers.get_uuid())
+        img_inst_label = "cb-crudimage-{0}".format(helpers.get_uuid())
 
         # Declare these variables and late binding will allow
         # the cleanup method access to the most current values
@@ -40,6 +41,42 @@ class CloudImageServiceTestCase(ProviderTestBase):
             img.refresh()
             self.assertGreater(img.min_disk, 0, "Minimum disk"
                                " size required by image is invalid")
+            create_instance_from_image(img)
+
+        def create_instance_from_image(img):
+            img_instance = None
+            with helpers.cleanup_action(lambda: helpers.cleanup_test_resources(
+                    img_instance)):
+                img_instance = self.provider.compute.instances.create(
+                    img_inst_label, img,
+                    helpers.get_provider_test_data(self.provider, 'vm_type'),
+                    subnet=subnet,
+                    zone=helpers.get_provider_test_data(
+                        self.provider, 'placement'),
+                    key_pair=None,
+                    vm_firewalls=None,
+                    launch_config=None,
+                    user_data=None)
+                self.assertIsInstance(img_instance, Instance)
+                self.assertEqual(
+                    img_instance.label, img_inst_label,
+                    "Instance label {0} is not equal to the expected label"
+                    " {1}".format(img_instance.label, img_inst_label))
+                image_id = img.id
+                self.assertEqual(img_instance.image_id, image_id,
+                                 "Image id {0} is not equal to the expected id"
+                                 " {1}".format(img_instance.image_id,
+                                               image_id))
+                self.assertIsInstance(img_instance.public_ips, list)
+                if img_instance.public_ips:
+                    self.assertTrue(
+                        img_instance.public_ips[0],
+                        "public ip should contain a"
+                        " valid value if a list of public_ips exist")
+                self.assertIsInstance(img_instance.private_ips, list)
+                self.assertTrue(img_instance.private_ips[0],
+                                "private ip should"
+                                " contain a valid value")
 
         with helpers.cleanup_action(lambda: helpers.cleanup_test_resources(
                 test_instance, net)):