Переглянути джерело

Fix creation of snapshot via SnapshotService; add test

Enis Afgan 10 роки тому
батько
коміт
cc0caddbd2

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

@@ -317,9 +317,7 @@ class AWSSnapshotService(BaseSnapshotService):
         """
         Creates a new snapshot of a given volume.
         """
-        volume_id = volume.volume_id if isinstance(
-            volume,
-            AWSVolume) else volume
+        volume_id = volume.id if isinstance(volume, AWSVolume) else volume
 
         ec2_snap = self.provider.ec2_conn.create_snapshot(
             volume_id,

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

@@ -383,8 +383,7 @@ class OpenStackSnapshotService(BaseSnapshotService):
         """
         Creates a new snapshot of a given volume.
         """
-        volume_id = volume.id if \
-            isinstance(volume, OpenStackVolume) else volume
+        volume_id = volume.id if isinstance(volume, OpenStackVolume) else volume
 
         os_snap = self.provider.cinder.volume_snapshots.create(
             volume_id, name=name,

+ 13 - 2
test/test_block_store_service.py

@@ -193,8 +193,8 @@ class CloudBlockStoreServiceTestCase(ProviderTestBase):
                                              get_snap.name,
                                              test_snap.name))
 
-                # Create volume creation based on this snapshot
-                sv_name = "CBUnitTestSnapVol-{0}".format(uuid.uuid4())
+                # Test volume creation based on this snapshot
+                sv_name = "CBUnitTestSnapVol-{0}".format(name)
                 snap_vol = self.provider.block_store.volumes.create(
                     sv_name,
                     1,
@@ -210,3 +210,14 @@ class CloudBlockStoreServiceTestCase(ProviderTestBase):
                 len(found_snaps) == 0,
                 "Snapshot %s should have been deleted but still exists." %
                 snap_name)
+
+            # Test creation of a snap via SnapshotService
+            snap_too_name = "CBSnapToo-{0}".format(name)
+            test_snap_too = self.provider.block_store.snapshots.create(
+                name=snap_too_name, volume=test_vol, description=snap_too_name)
+            with helpers.cleanup_action(lambda: cleanup_snap(test_snap_too)):
+                test_snap_too.wait_till_ready()
+                self.assertTrue(
+                    test_snap_too.id in repr(test_snap_too),
+                    "repr(obj) should contain the object id so that the object"
+                    " can be reconstructed, but does not.")