]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix Pure get pgroup volume snapshot name
authorPatrick East <patrick.east@purestorage.com>
Fri, 11 Sep 2015 21:12:03 +0000 (14:12 -0700)
committerPatrick East <patrick.east@purestorage.com>
Fri, 11 Sep 2015 21:59:59 +0000 (14:59 -0700)
When creating a volume from a consistency group snapshot we have to go
look up the volume level snapshot from the group. Previously we could
just directly get to the cgsnapshot model from the snapshot. After we
switched to using the snapshot objects however we cannot do that (at
least not until we have cgsnapshot objects too).

As an interim solution we did a query to the REST API on the array to
just list all of the snapshots. Unfortunately that doesn’t work on all
versions of the Purity REST API. To have a more usable solution we need
to do a db lookup to get the pgsnapshot.

It’s not ideal, and will be removed ASAP, but for now we need to at
least not regress in functionality.

Change-Id: I73a4ad5883bf33ce282b5a49aa8acba66ffcb84f
Closes-Bug: #1494934

cinder/tests/unit/test_pure.py
cinder/volume/drivers/pure.py

index 39b2c677b08bd7120a96364ac301e48a18db9ddc..a003156c5598c2af7fc25fbe11f648790d949b7a 100644 (file)
@@ -642,33 +642,23 @@ class PureBaseVolumeDriverTestCase(PureDriverTestCase):
         self.assertEqual(expected_name, actual_name)
 
     def test_get_pgroup_snap_name_from_snapshot(self):
-        cgsnapshot_id = 'b919b266-23b4-4b83-9a92-e66031b9a921'
-        volume_id = 'a3b8b294-8494-4a72-bec7-9aadec561332'
-        pgsnap_name_base = ('consisgroup-0cfc0e4e-5029-4839-af20-184fbc42a9ed'
-                            '-cinder.cgsnapshot-%s-cinder.volume-%s-cinder')
-        pgsnap_name = pgsnap_name_base % (cgsnapshot_id, volume_id)
-
-        target_pgsnap_dict = {
-            'source': 'volume-a3b8b294-8494-4a72-bec7-9aadec561332-cinder',
-            'serial': '590474D16E6708FD00015075',
-            'size': 1073741824,
-            'name': pgsnap_name,
-            'created': '2015-08-11T22:25:43Z'
-        }
-
-        # Simulate another pgroup snapshot for another volume in the same group
-        other_volume_id = '73f6af5e-43cd-4c61-8f57-21f312e4523d'
-        other_pgsnap_dict = target_pgsnap_dict.copy()
-        other_pgsnap_dict['name'] = pgsnap_name_base % (cgsnapshot_id,
-                                                        other_volume_id)
 
-        snap_list = [other_pgsnap_dict, target_pgsnap_dict]
-
-        self.array.list_volumes.return_value = snap_list
+        cgsnapshot_id = 'b919b266-23b4-4b83-9a92-e66031b9a921'
+        volume_name = 'volume-a3b8b294-8494-4a72-bec7-9aadec561332'
+        cg_id = '0cfc0e4e-5029-4839-af20-184fbc42a9ed'
+        pgsnap_name_base = (
+            'consisgroup-%s-cinder.cgsnapshot-%s-cinder.%s-cinder')
+        pgsnap_name = pgsnap_name_base % (cg_id, cgsnapshot_id, volume_name)
+
+        self.driver.db = mock.MagicMock()
+        mock_cgsnap = mock.MagicMock()
+        mock_cgsnap.id = cgsnapshot_id
+        mock_cgsnap.consistencygroup_id = cg_id
+        self.driver.db.cgsnapshot_get.return_value = mock_cgsnap
 
         mock_snap = mock.Mock()
         mock_snap.cgsnapshot_id = cgsnapshot_id
-        mock_snap.volume_id = volume_id
+        mock_snap.volume_name = volume_name
 
         actual_name = self.driver._get_pgroup_snap_name_from_snapshot(
             mock_snap
index f4029c738cd00ca4be43b9e2f1aba31587dd6615..71e92812b77c9df533992eb40c024180bd9b2711 100644 (file)
@@ -27,6 +27,7 @@ from oslo_log import log as logging
 from oslo_utils import excutils
 from oslo_utils import units
 
+from cinder import context
 from cinder import exception
 from cinder.i18n import _, _LE, _LI, _LW
 from cinder import objects
@@ -701,13 +702,17 @@ class PureBaseVolumeDriver(san.SanDriver):
 
     def _get_pgroup_snap_name_from_snapshot(self, snapshot):
         """Return the name of the snapshot that Purity will use."""
-        pg_snaps = self._array.list_volumes(snap=True, pgroup=True)
-        for pg_snap in pg_snaps:
-            pg_snap_name = pg_snap['name']
-            if (snapshot.cgsnapshot_id in pg_snap_name and
-                    snapshot.volume_id in pg_snap_name):
-                return pg_snap_name
-        return None
+
+        # TODO(patrickeast): Remove DB calls once the cgsnapshot objects are
+        # available to use and can be associated with the snapshot objects.
+        ctxt = context.get_admin_context()
+        cgsnapshot = self.db.cgsnapshot_get(ctxt, snapshot.cgsnapshot_id)
+
+        pg_vol_snap_name = "%(group_snap)s.%(volume_name)s-cinder" % {
+            'group_snap': self._get_pgroup_snap_name(cgsnapshot),
+            'volume_name': snapshot.volume_name
+        }
+        return pg_vol_snap_name
 
     @staticmethod
     def _generate_purity_host_name(name):