From: Alon Marx Date: Fri, 9 Oct 2015 21:00:49 +0000 (+0300) Subject: Updates in consistency_group in xiv/ds8k driver X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=e05277a3c4ef3bb2e4fc22364a8b09de012702de;p=openstack-build%2Fcinder-build.git Updates in consistency_group in xiv/ds8k driver 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 --- diff --git a/cinder/tests/unit/test_ibm_xiv_ds8k.py b/cinder/tests/unit/test_ibm_xiv_ds8k.py index e7fe0a769..de831cb42 100644 --- a/cinder/tests/unit/test_ibm_xiv_ds8k.py +++ b/cinder/tests/unit/test_ibm_xiv_ds8k.py @@ -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") diff --git a/cinder/volume/drivers/ibm/xiv_ds8k.py b/cinder/volume/drivers/ibm/xiv_ds8k.py index 93caceaa4..774d2e802 100644 --- a/cinder/volume/drivers/ibm/xiv_ds8k.py +++ b/cinder/volume/drivers/ibm/xiv_ds8k.py @@ -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)