Răsfoiți Sursa

Fixed bug in find() method and added test case to catch it.

Nuwan Goonasekera 10 ani în urmă
părinte
comite
134111c7be

+ 3 - 5
cloudbridge/cloud/providers/aws/services.py

@@ -249,7 +249,7 @@ class AWSVolumeService(BaseVolumeService):
         """
         Searches for a volume by a given list of attributes.
         """
-        filtr = {'Name': name}
+        filtr = {'tag:Name': name}
         aws_vols = self.provider.ec2_conn.get_all_volumes(filters=filtr)
         cb_vols = [AWSVolume(self.provider, vol) for vol in aws_vols]
         return ClientPagedResultList(self.provider, cb_vols,
@@ -298,7 +298,7 @@ class AWSSnapshotService(BaseSnapshotService):
         """
         Searches for a snapshot by a given list of attributes.
         """
-        filtr = {'Name': name}
+        filtr = {'tag-value': name}
         snaps = [AWSSnapshot(self.provider, snap) for snap in
                  self.provider.ec2_conn.get_all_snapshots(filters=filtr)]
         return ClientPagedResultList(self.provider, snaps,
@@ -396,9 +396,7 @@ class AWSImageService(BaseImageService):
         """
         Searches for an image by a given list of attributes
         """
-        filters = {
-            'name': name
-        }
+        filters = {'tag:Name': name}
         images = [AWSMachineImage(self.provider, image) for image in
                   self.provider.ec2_conn.get_all_images(filters=filters)]
         return ClientPagedResultList(self.provider, images,

+ 3 - 2
cloudbridge/cloud/providers/openstack/services.py

@@ -356,13 +356,14 @@ class OpenStackSnapshotService(BaseSnapshotService):
         """
         Searches for a volume by a given list of attributes.
         """
-        search_opts = {'name': name,
+        search_opts = {'name': name,  # TODO: Cinder is ignoring name
                        'limit': oshelpers.os_result_limit(self.provider,
                                                           limit),
                        'marker': marker}
         cb_snaps = [
             OpenStackSnapshot(self.provider, snap) for
-            snap in self.provider.cinder.volume_snapshots.list(search_opts)]
+            snap in self.provider.cinder.volume_snapshots.list(search_opts)
+            if snap.name == name]
 
         return oshelpers.to_server_paged_list(self.provider, cb_snaps, limit)
 

+ 23 - 3
test/test_block_store_service.py

@@ -50,12 +50,21 @@ class CloudBlockStoreServiceTestCase(ProviderTestBase):
                 name)
 
             # check find
-            find_volumes = self.provider.block_store.volumes.find(name=name)
+            find_vols = self.provider.block_store.volumes.find(name=name)
             self.assertTrue(
-                len(find_volumes) == 1,
+                len(find_vols) == 1,
                 "Find volumes does not return the expected volume %s" %
                 name)
 
+            # check non-existent find
+            # TODO: Moto has a bug with filters causing the following test
+            # to fail. Need to add tag based filtering support for volumes
+#             find_vols = self.provider.block_store.volumes.find(
+#                 name="non_existent_vol")
+#             self.assertTrue(
+#                 len(find_vols) == 0,
+#                 "Find() for a non-existent volume returned %s" % find_vols)
+
             get_vol = self.provider.block_store.volumes.get(
                 test_vol.id)
             self.assertTrue(
@@ -150,12 +159,23 @@ class CloudBlockStoreServiceTestCase(ProviderTestBase):
                     name)
 
                 # check find
-                find_snap = self.provider.block_store.snapshots.find(name=name)
+                find_snap = self.provider.block_store.snapshots.find(
+                    name=snap_name)
                 self.assertTrue(
                     len(find_snap) == 1,
                     "Find snaps does not return the expected snapshot %s" %
                     name)
 
+                # check non-existent find
+                # TODO: Moto has a bug with filters causing the following test
+                # to fail. Need to add tag based filtering support for snaps
+#                 find_snap = self.provider.block_store.snapshots.find(
+#                     name="non_existent_snap")
+#                 self.assertTrue(
+#                     len(find_snap) == 0,
+#                     "Find() for a non-existent snap returned %s" %
+#                     find_snap)
+
                 get_snap = self.provider.block_store.snapshots.get(
                     test_snap.id)
                 self.assertTrue(

+ 7 - 0
test/test_compute_service.py

@@ -55,6 +55,13 @@ class CloudComputeServiceTestCase(ProviderTestBase):
                 "Find instances does not return the expected instance %s" %
                 name)
 
+            # check non-existent find
+            find_instances = self.provider.compute.instances.find(
+                name="non_existent")
+            self.assertTrue(
+                len(find_instances) == 0,
+                "Find() for a non-existent image returned %s" % find_instances)
+
             get_inst = self.provider.compute.instances.get(
                 inst.id)
             self.assertTrue(

+ 8 - 0
test/test_image_service.py

@@ -68,6 +68,14 @@ class CloudImageServiceTestCase(ProviderTestBase):
                     "Iter images does not return the expected image %s" %
                     name)
 
+                # check non-existent find
+                found_images = self.provider.compute.images.find(
+                    name="non_existent")
+                self.assertTrue(
+                    len(found_images) == 0,
+                    "Find() for a non-existent image returned %s" %
+                    found_images)
+
                 get_img = self.provider.compute.images.get(
                     test_image.id)
                 self.assertTrue(