Browse Source

Added tests for get methods.

nuwan_ag 10 years ago
parent
commit
93847f7844

+ 3 - 2
cloudbridge/providers/openstack/resources.py

@@ -579,7 +579,7 @@ class OpenStackContainerObject(ContainerObject):
         string.
         """
         self._provider.swift.put_object(self.cbcontainer.name, self.name,
-                                       data)
+                                        data)
 
     def delete(self):
         """
@@ -589,7 +589,8 @@ class OpenStackContainerObject(ContainerObject):
         :return: True if successful
         """
         try:
-            self._provider.swift.delete_object(self.cbcontainer.name, self.name)
+            self._provider.swift.delete_object(self.cbcontainer.name,
+                                               self.name)
         except ClientException as err:
             if err.http_status == 404:
                 return True

+ 38 - 1
test/test_provider_block_store_service.py

@@ -30,6 +30,24 @@ class ProviderBlockStoreServiceTestCase(ProviderTestBase):
                 len(found_volumes) == 1,
                 "List volumes does not return the expected volume %s" %
                 name)
+
+            get_vol = self.provider.block_store.volumes.get_volume(
+                test_vol.volume_id)
+            self.assertTrue(
+                found_volumes[0].volume_id ==
+                get_vol.volume_id == test_vol.volume_id,
+                "Ids returned by list: {0} and get: {1} are not as "
+                " expected: {2}" .format(found_volumes[0].volume_id,
+                                         get_vol.volume_id,
+                                         test_vol.volume_id))
+            self.assertTrue(
+                found_volumes[0].name ==
+                get_vol.name == test_vol.name,
+                "Names returned by list: {0} and get: {1} are not as "
+                " expected: {2}" .format(found_volumes[0].name,
+                                         get_vol.name,
+                                         test_vol.name))
+
             test_vol.delete()
             test_vol.wait_for(
                 [VolumeState.DELETED, VolumeState.UNKNOWN],
@@ -55,7 +73,8 @@ class ProviderBlockStoreServiceTestCase(ProviderTestBase):
             test_vol = self.provider.block_store.volumes.create_volume(
                 name, 1, test_instance.placement_zone)
             with helpers.exception_action(lambda: test_vol.delete()):
-                test_vol.wait_till_ready(interval=self.get_test_wait_interval())
+                test_vol.wait_till_ready(
+                    interval=self.get_test_wait_interval())
                 test_vol.attach(test_instance, '/dev/sda2')
                 test_vol.wait_for(
                     [VolumeState.IN_USE],
@@ -102,6 +121,24 @@ class ProviderBlockStoreServiceTestCase(ProviderTestBase):
                     len(found_snaps) == 1,
                     "List snapshots does not return the expected volume %s" %
                     name)
+
+                get_snap = self.provider.block_store.snapshots.get_snapshot(
+                    test_snap.snapshot_id)
+                self.assertTrue(
+                    found_snaps[0].snapshot_id ==
+                    get_snap.snapshot_id == test_snap.snapshot_id,
+                    "Ids returned by list: {0} and get: {1} are not as "
+                    " expected: {2}" .format(found_snaps[0].snapshot_id,
+                                             get_snap.snapshot_id,
+                                             test_snap.snapshot_id))
+                self.assertTrue(
+                    found_snaps[0].name ==
+                    get_snap.name == test_snap.name,
+                    "Names returned by list: {0} and get: {1} are not as "
+                    " expected: {2}" .format(found_snaps[0].name,
+                                             get_snap.name,
+                                             test_snap.name))
+
                 cleanup_snap(test_snap)
                 snaps = self.provider.block_store.snapshots.list_snapshots()
                 found_snaps = [snap for snap in snaps

+ 18 - 0
test/test_provider_compute_service.py

@@ -24,6 +24,24 @@ class ProviderComputeServiceTestCase(ProviderTestBase):
                 len(found_instances) == 1,
                 "List instances does not return the expected instance %s" %
                 name)
+
+            get_inst = self.provider.compute.get_instance(
+                inst.instance_id)
+            self.assertTrue(
+                found_instances[0].instance_id ==
+                get_inst.instance_id == inst.instance_id,
+                "Ids returned by list: {0} and get: {1} are not as "
+                " expected: {2}" .format(found_instances[0].instance_id,
+                                         get_inst.instance_id,
+                                         inst.instance_id))
+            self.assertTrue(
+                found_instances[0].name ==
+                get_inst.name == inst.name,
+                "Names returned by list: {0} and get: {1} are not as "
+                " expected: {2}" .format(found_instances[0].name,
+                                         get_inst.name,
+                                         inst.name))
+
             inst.terminate()
             inst.wait_for(
                 [InstanceState.TERMINATED, InstanceState.UNKNOWN],

+ 27 - 9
test/test_provider_image_service.py

@@ -33,17 +33,35 @@ class ProviderImageServiceTestCase(ProviderTestBase):
                     len(found_images) == 1,
                     "List images does not return the expected image %s" %
                     name)
+
+                get_img = self.provider.images.get_image(
+                    test_image.image_id)
+                self.assertTrue(
+                    found_images[0].image_id ==
+                    get_img.image_id == test_image.image_id,
+                    "Ids returned by list: {0} and get: {1} are not as "
+                    " expected: {2}" .format(found_images[0].image_id,
+                                             get_img.image_id,
+                                             test_image.image_id))
+                self.assertTrue(
+                    found_images[0].name ==
+                    get_img.name == test_image.name,
+                    "Names returned by list: {0} and get: {1} are not as "
+                    " expected: {2}" .format(found_images[0].name,
+                                             get_img.name,
+                                             test_image.name))
+
                 test_image.delete()
                 test_image.wait_for(
                     [MachineImageState.UNKNOWN],
                     terminal_states=[MachineImageState.ERROR],
                     interval=self.get_test_wait_interval())
-            # TODO: Images take a long time to deregister on EC2. Needs
-            # investigation
-#                 images = self.provider.images.list_images()
-#                 found_images = [image for image in images
-#                                 if image.name == name]
-#                 self.assertTrue(
-#                     len(found_images) == 0,
-#                     "Image %s should have been deleted but still exists." %
-#                     name)
+                # TODO: Images take a long time to deregister on EC2. Needs
+                # investigation
+                images = self.provider.images.list_images()
+                found_images = [image for image in images
+                                if image.name == name]
+                self.assertTrue(
+                    len(found_images) == 0,
+                    "Image %s should have been deleted but still exists." %
+                    name)

+ 12 - 0
test/test_provider_object_store_service.py

@@ -30,6 +30,17 @@ class ProviderObjectStoreServiceTestCase(ProviderTestBase):
                 len(found_containers) == 1,
                 "List containers does not return the expected container %s" %
                 name)
+
+            get_container = self.provider.object_store.get_container(
+                test_container.name)
+            self.assertTrue(
+                found_containers[0].name ==
+                get_container.name == test_container.name,
+                "Names returned by list: {0} and get: {1} are not as "
+                " expected: {2}" .format(found_containers[0].name,
+                                         get_container.name,
+                                         test_container.name))
+
             test_container.delete()
             containers = self.provider.object_store.list_containers()
             found_containers = [c for c in containers if c.name == name]
@@ -67,6 +78,7 @@ class ProviderObjectStoreServiceTestCase(ProviderTestBase):
                     len(found_objs) == 1,
                     "List container objects does not return the expected"
                     " object %s" % obj_name)
+
                 obj.delete()
                 objs = test_container.list()
                 found_objs = [o for o in objs if o.name == obj_name]