From: Patrick East Date: Fri, 11 Sep 2015 21:12:03 +0000 (-0700) Subject: Fix Pure get pgroup volume snapshot name X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=d2170a9e13047ea9a05ed78c4e6da61a5dfc46e2;p=openstack-build%2Fcinder-build.git Fix Pure get pgroup volume snapshot name 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 --- diff --git a/cinder/tests/unit/test_pure.py b/cinder/tests/unit/test_pure.py index 39b2c677b..a003156c5 100644 --- a/cinder/tests/unit/test_pure.py +++ b/cinder/tests/unit/test_pure.py @@ -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 diff --git a/cinder/volume/drivers/pure.py b/cinder/volume/drivers/pure.py index f4029c738..71e92812b 100644 --- a/cinder/volume/drivers/pure.py +++ b/cinder/volume/drivers/pure.py @@ -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):