]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Updates in consistency_group in xiv/ds8k driver
authorAlon Marx <alonma@il.ibm.com>
Fri, 9 Oct 2015 21:00:49 +0000 (00:00 +0300)
committerAlon Marx <alonma@il.ibm.com>
Mon, 19 Oct 2015 11:33:36 +0000 (14:33 +0300)
The changes are:
1. ability to modify a consistecy group (update_consistencygroup)
2. ability to create a consistency group from a cgsnapshot or from
   another consistency group (create_consistencygroup_from_src)

Change-Id: I8da0e86ec321bf67b59fef8426fdd637dfe83bbe
Implements: bp xiv-ds8k-cg-updates

cinder/tests/unit/test_ibm_xiv_ds8k.py
cinder/volume/drivers/ibm/xiv_ds8k.py

index e7fe0a769bd09d6e5cde7125f0becf42ada0d21f..de831cb42765f97dd0dcc71a66d4a4cf3fa38987 100644 (file)
@@ -33,6 +33,7 @@ from cinder.volume.drivers.ibm import xiv_ds8k
 from cinder.volume import volume_types
 
 FAKE = "fake"
+FAKE2 = "fake2"
 CANNOT_DELETE = "Can not delete"
 TOO_BIG_VOLUME_SIZE = 12000
 POOL_SIZE = 100
@@ -42,6 +43,11 @@ VOLUME = {'size': 16,
           'id': 1,
           'consistencygroup_id': CONSISTGROUP_ID,
           'status': 'available'}
+VOLUME2 = {'size': 32,
+           'name': FAKE2,
+           'id': 2,
+           'consistencygroup_id': CONSISTGROUP_ID,
+           'status': 'available'}
 
 MANAGED_FAKE = "managed_fake"
 MANAGED_VOLUME = {'size': 16,
@@ -55,6 +61,10 @@ REPLICATED_VOLUME = {'size': 64,
 
 CONTEXT = {}
 
+FAKESNAPSHOT = 'fakesnapshot'
+SNAPSHOT = {'name': 'fakesnapshot',
+            'id': 3}
+
 CONSISTGROUP = {'id': CONSISTGROUP_ID, }
 CG_SNAPSHOT_ID = 1
 CG_SNAPSHOT = {'id': CG_SNAPSHOT_ID,
@@ -217,6 +227,19 @@ class XIVDS8KFakeProxyDriver(object):
 
         return {'status': 'deleted'}, volumes
 
+    def update_consistencygroup(
+            self, context, group,
+            add_volumes, remove_volumes):
+
+        model_update = {'status': 'available'}
+        return model_update, None, None
+
+    def create_consistencygroup_from_src(
+            self, context, group, volumes, cgsnapshot, snapshots,
+            source_cg=None, source_vols=None):
+
+        return None, None
+
     def create_cgsnapshot(self, ctxt, cgsnapshot):
         snapshots = []
         for volume in self.volumes.values():
@@ -346,7 +369,7 @@ class XIVDS8KVolumeDriverTest(test.TestCase):
         self.driver.delete_volume(VOLUME)
 
     def test_create_volume_should_fail_if_no_pool_space_left(self):
-        """Vertify that the xiv_ds8k_proxy validates volume pool space."""
+        """Verify that the xiv_ds8k_proxy validates volume pool space."""
 
         self.driver.do_setup(None)
         self.assertRaises(exception.VolumeBackendAPIException,
@@ -838,3 +861,86 @@ class XIVDS8KVolumeDriverTest(test.TestCase):
         self.assertRaises(exception.VolumeBackendAPIException,
                           self.driver.delete_cgsnapshot,
                           ctxt, CG_SNAPSHOT)
+
+    def test_update_consistencygroup_without_volumes(self):
+        """Test update_consistencygroup when there are no volumes specified."""
+
+        self.driver.do_setup(None)
+
+        ctxt = context.get_admin_context()
+
+        # Update consistency group
+        model_update, added, removed = self.driver.update_consistencygroup(
+            ctxt, CONSISTGROUP, [], [])
+
+        self.assertEqual('available',
+                         model_update['status'],
+                         "Consistency Group update failed")
+        self.assertFalse(added,
+                         "added volumes list is not empty")
+        self.assertFalse(removed,
+                         "removed volumes list is not empty")
+
+    def test_update_consistencygroup_with_volumes(self):
+        """Test update_consistencygroup when there are volumes specified."""
+
+        self.driver.do_setup(None)
+
+        ctxt = context.get_admin_context()
+
+        # Update consistency group
+        model_update, added, removed = self.driver.update_consistencygroup(
+            ctxt, CONSISTGROUP, [VOLUME], [VOLUME2])
+
+        self.assertEqual('available',
+                         model_update['status'],
+                         "Consistency Group update failed")
+        self.assertFalse(added,
+                         "added volumes list is not empty")
+        self.assertFalse(removed,
+                         "removed volumes list is not empty")
+
+    def test_create_consistencygroup_from_src_without_volumes(self):
+        """Test create_consistencygroup_from_src with no volumes specified."""
+
+        self.driver.do_setup(None)
+
+        ctxt = context.get_admin_context()
+
+        # Create consistency group from source
+        model_update, volumes_model_update = (
+            self.driver.create_consistencygroup_from_src(
+                ctxt, CONSISTGROUP, [], CG_SNAPSHOT, []))
+
+        # model_update can be None or return available in status
+        if model_update:
+            self.assertEqual('available',
+                             model_update['status'],
+                             "Consistency Group create from source failed")
+        # volumes_model_update can be None or return available in status
+        if volumes_model_update:
+            self.assertFalse(volumes_model_update,
+                             "volumes list is not empty")
+
+    def test_create_consistencygroup_from_src_with_volumes(self):
+        """Test create_consistencygroup_from_src with volumes specified."""
+
+        self.driver.do_setup(None)
+
+        ctxt = context.get_admin_context()
+
+        # Create consistency group from source
+        model_update, volumes_model_update = (
+            self.driver.create_consistencygroup_from_src(
+                ctxt, CONSISTGROUP, [VOLUME], CG_SNAPSHOT, [SNAPSHOT]))
+
+        # model_update can be None or return available in status
+        if model_update:
+            self.assertEqual('available',
+                             model_update['status'],
+                             "Consistency Group create from source failed")
+        # volumes_model_update can be None or return available in status
+        if volumes_model_update:
+            self.assertEqual('available',
+                             volumes_model_update['status'],
+                             "volumes list status failed")
index 93caceaa4a45920985c10554bcfe3e23c06c5cf6..774d2e802ff5665dd00864a8676694975918b0c7 100644 (file)
@@ -262,3 +262,19 @@ class XIVDS8KDriver(san.SanDriver,
         """Deletes a consistency group snapshot."""
 
         return self.xiv_ds8k_proxy.delete_cgsnapshot(context, cgsnapshot)
+
+    def update_consistencygroup(self, context, group,
+                                add_volumes, remove_volumes):
+        """Adds or removes volume(s) to/from an existing consistency group."""
+
+        return self.xiv_ds8k_proxy.update_consistencygroup(
+            context, group, add_volumes, remove_volumes)
+
+    def create_consistencygroup_from_src(
+            self, context, group, volumes, cgsnapshot, snapshots,
+            source_cg=None, source_vols=None):
+        """Creates a consistencygroup from source."""
+
+        return self.xiv_ds8k_proxy.create_consistencygroup_from_src(
+            context, group, volumes, cgsnapshot, snapshots,
+            source_cg, source_vols)