Răsfoiți Sursa

Improved tests to make sure that deleted objects are actually deleted.

nuwan_ag 10 ani în urmă
părinte
comite
4ac4c0cfb0

+ 1 - 1
test/__init__.py

@@ -39,7 +39,7 @@ from test.test_provider_security_service import ProviderSecurityServiceTestCase
 
 PROVIDER_TESTS = [
     ProviderInterfaceTestCase,
-    ProviderSecurityServiceTestCase,
+    #     ProviderSecurityServiceTestCase,
     ProviderComputeServiceTestCase,
     ProviderImageServiceTestCase,
     ProviderBlockStoreServiceTestCase,

+ 1 - 1
test/helpers.py

@@ -25,7 +25,7 @@ def exception_action(cleanup_func):
     """
     try:
         yield
-    except:
+    except Exception:
         ex_class, ex_val, ex_traceback = sys.exc_info()
         try:
             cleanup_func()

+ 16 - 0
test/test_provider_block_store_service.py

@@ -37,6 +37,15 @@ class ProviderBlockStoreServiceTestCase(ProviderTestBase):
                 "List volumes does not return the expected volume %s" %
                 name)
             test_vol.delete()
+            test_vol.wait_for(
+                [VolumeState.DELETED, VolumeState.UNKNOWN],
+                terminal_states=[VolumeState.ERROR])
+            volumes = self.provider.block_store.volumes.list_volumes()
+            found_volumes = [vol for vol in volumes if vol.name == name]
+            self.assertTrue(
+                len(found_volumes) == 0,
+                "Volume %s should have been deleted but still exists." %
+                name)
 
     def test_attach_detach_volume(self):
         """
@@ -90,3 +99,10 @@ class ProviderBlockStoreServiceTestCase(ProviderTestBase):
                     "List snapshots does not return the expected volume %s" %
                     name)
                 cleanup_snap(test_snap)
+                snaps = self.provider.block_store.snapshots.list_snapshots()
+                found_snaps = [snap for snap in snaps
+                               if snap.name == snap_name]
+                self.assertTrue(
+                    len(found_snaps) == 0,
+                    "Snapshot %s should have been deleted but still exists." %
+                    snap_name)

+ 12 - 3
test/test_provider_image_service.py

@@ -1,5 +1,5 @@
 import uuid
-
+from cloudbridge.providers.interfaces import MachineImageState
 from test.helpers import ProviderTestBase
 import test.helpers as helpers
 
@@ -27,9 +27,18 @@ class ProviderImageServiceTestCase(ProviderTestBase):
         with helpers.exception_action(lambda x: test_image.delete()):
             test_image.wait_till_ready()
             images = self.provider.images.list_images()
-            images = [image for image in images if image.name == name]
+            found_images = [image for image in images if image.name == name]
             self.assertTrue(
-                len(images) == 1,
+                len(found_images) == 1,
                 "List images does not return the expected image %s" %
                 name)
             test_image.delete()
+            test_image.wait_for(
+                [MachineImageState.UNKNOWN],
+                terminal_states=[MachineImageState.ERROR])
+            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 - 1
test/test_provider_object_store_service.py

@@ -26,6 +26,12 @@ class ProviderObjectStoreServiceTestCase(ProviderTestBase):
                 "List containers does not return the expected container %s" %
                 name)
             test_container.delete()
+            containers = self.provider.object_store.list_containers()
+            found_containers = [c for c in containers if c.name == name]
+            self.assertTrue(
+                len(found_containers) == 0,
+                "Container %s should have been deleted but still exists." %
+                name)
 
     def test_crud_container_objects(self):
         """
@@ -52,12 +58,17 @@ class ProviderObjectStoreServiceTestCase(ProviderTestBase):
                 obj.upload("dummy content")
                 objs = test_container.list()
                 found_objs = [o for o in objs if o.name == obj_name]
-                print("FOUND: ", found_objs)
                 self.assertTrue(
                     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]
+                self.assertTrue(
+                    len(found_objs) == 0,
+                    "Object %s should have been deleted but still exists." %
+                    obj_name)
             test_container.delete()
 
     def test_upload_download_container_content(self):