From ab59c7f615fc870f5a7a1f7154ad5f091a438858 Mon Sep 17 00:00:00 2001 From: Shay Halsband Date: Tue, 10 Nov 2015 18:17:25 +0200 Subject: [PATCH] XtremIO add support for create CG from CG src The method of creating CG from source was extended to support create CG from other CG, this patch adds this capability for XtremIO. The driver will: 1. Take an XtremIO snapshot of the source CG. 2. Renames the volumes of the snapset to fit Cinder IDs. 3. Create a new CG with the renamed volumes. DocImpact: update capabities Change-Id: I3ce791cf718f45c29d87e133eeebd6c68d340b0d Implements: blueprint xtremio-cg-from-cg --- cinder/tests/unit/test_emc_xtremio.py | 14 ++++++ cinder/volume/drivers/emc/xtremio.py | 44 +++++++++++++------ .../xtremio-cg-from-cg-e05cf286e3a1e943.yaml | 4 ++ 3 files changed, 48 insertions(+), 14 deletions(-) create mode 100644 releasenotes/notes/xtremio-cg-from-cg-e05cf286e3a1e943.yaml diff --git a/cinder/tests/unit/test_emc_xtremio.py b/cinder/tests/unit/test_emc_xtremio.py index 1dac8aeb3..5daed8f26 100644 --- a/cinder/tests/unit/test_emc_xtremio.py +++ b/cinder/tests/unit/test_emc_xtremio.py @@ -521,6 +521,20 @@ class EMCXIODriverISCSITestCase(test.TestCase): [new_vol1], d.cgsnapshot, [snapshot1]) + new_cg_obj = fake_cg.fake_consistencyobject_obj(d.context, id=5) + snapset2_name = new_cg_obj.id + new_vol1.id = '192eb39b-6c2f-420c-bae3-3cfd117f0001' + new_vol2 = fake_volume.fake_volume_obj(d.context) + snapset2 = {'vol-list': [xms_data['volumes'][2]['vol-id']], + 'name': snapset2_name, + 'index': 1} + xms_data['snapshot-sets'].update({5: snapset2, + snapset2_name: snapset2}) + self.driver.create_consistencygroup_from_src(d.context, new_cg_obj, + [new_vol2], + None, None, + cg_obj, [new_vol1]) + @mock.patch('requests.request') class EMCXIODriverTestCase(test.TestCase): diff --git a/cinder/volume/drivers/emc/xtremio.py b/cinder/volume/drivers/emc/xtremio.py index 5b95557d5..cbdbfb1a4 100644 --- a/cinder/volume/drivers/emc/xtremio.py +++ b/cinder/volume/drivers/emc/xtremio.py @@ -395,7 +395,7 @@ class XtremIOVolumeDriver(san.SanDriver): """Creates a volume from a snapshot.""" if snapshot.get('cgsnapshot_id'): # get array snapshot id from CG snapshot - snap_by_anc = self.get_snapset_ancestors(snapshot.cgsnapshot) + snap_by_anc = self._get_snapset_ancestors(snapshot.cgsnapshot) snapshot_id = snap_by_anc[snapshot['volume_id']] else: snapshot_id = snapshot['id'] @@ -595,8 +595,7 @@ class XtremIOVolumeDriver(san.SanDriver): return model_update, volumes - def get_snapset_ancestors(self, cgsnapshot): - snapset_name = self._get_cgsnap_name(cgsnapshot) + def _get_snapset_ancestors(self, snapset_name): snapset = self.client.req('snapshot-sets', name=snapset_name)['content'] volume_ids = [s[XTREMIO_OID_INDEX] for s in snapset['vol-list']] @@ -617,21 +616,38 @@ class XtremIOVolumeDriver(san.SanDriver): :param volumes: a list of volume dictionaries in the group. :param cgsnapshot: the dictionary of the cgsnapshot as source. :param snapshots: a list of snapshot dictionaries in the cgsnapshot. - :returns: model_update, volumes_model_update + :param source_cg: the dictionary of a consistency group as source. + :param source_vols: a list of volume dictionaries in the source_cg. + :returns model_update, volumes_model_update """ - if cgsnapshot and snapshots: - snap_by_anc = self.get_snapset_ancestors(cgsnapshot) + if not (cgsnapshot and snapshots and not source_cg or + source_cg and source_vols and not cgsnapshot): + msg = _("create_consistencygroup_from_src only supports a " + "cgsnapshot source or a consistency group source. " + "Multiple sources cannot be used.") + raise exception.InvalidInput(msg) + + if cgsnapshot: + snap_name = self._get_cgsnap_name(cgsnapshot) + snap_by_anc = self._get_snapset_ancestors(snap_name) for volume, snapshot in zip(volumes, snapshots): real_snap = snap_by_anc[snapshot['volume_id']] self.create_volume_from_snapshot(volume, {'id': real_snap}) - create_data = {'consistency-group-name': group['id'], - 'vol-list': [v['id'] for v in volumes]} - self.client.req('consistency-groups', 'POST', data=create_data, - ver='v2') - else: - msg = _("create_consistencygroup_from_src only supports a" - " cgsnapshot source, other sources cannot be used.") - raise exception.InvalidInput(msg) + + elif source_cg: + data = {'consistency-group-id': source_cg['id'], + 'snapshot-set-name': group['id']} + self.client.req('snapshots', 'POST', data, ver='v2') + snap_by_anc = self._get_snapset_ancestors(group['id']) + for volume, src_vol in zip(volumes, source_vols): + snap_vol_name = snap_by_anc[src_vol['id']] + self.client.req('volumes', 'PUT', {'name': volume['id']}, + name=snap_vol_name) + + create_data = {'consistency-group-name': group['id'], + 'vol-list': [v['id'] for v in volumes]} + self.client.req('consistency-groups', 'POST', data=create_data, + ver='v2') return None, None diff --git a/releasenotes/notes/xtremio-cg-from-cg-e05cf286e3a1e943.yaml b/releasenotes/notes/xtremio-cg-from-cg-e05cf286e3a1e943.yaml new file mode 100644 index 000000000..c0232e2ae --- /dev/null +++ b/releasenotes/notes/xtremio-cg-from-cg-e05cf286e3a1e943.yaml @@ -0,0 +1,4 @@ +--- +features: + - support for creating a consistency group from + consistency group in XtremIO. -- 2.45.2