]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
XtremIO add support for create CG from CG src
authorShay Halsband <shay.halsband@emc.com>
Tue, 10 Nov 2015 16:17:25 +0000 (18:17 +0200)
committerShay Halsband <shay.halsband@emc.com>
Sun, 20 Dec 2015 08:51:03 +0000 (10:51 +0200)
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
cinder/volume/drivers/emc/xtremio.py
releasenotes/notes/xtremio-cg-from-cg-e05cf286e3a1e943.yaml [new file with mode: 0644]

index 1dac8aeb3a90276e42c69b4746b7ce3919e07f4f..5daed8f2697e6b6437c10a5978ab4b7dacf71ac2 100644 (file)
@@ -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):
index 5b95557d52fbc409b823b4b29c87f4a034dd057c..cbdbfb1a48b221af0a8fb541f95f5c7541601cdc 100644 (file)
@@ -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 (file)
index 0000000..c0232e2
--- /dev/null
@@ -0,0 +1,4 @@
+---
+features:
+  - support for creating a consistency group from
+    consistency group in XtremIO.