From 59fe56954fe92aa3c9ec975993e82296f8d5446c Mon Sep 17 00:00:00 2001 From: "rick.chen" Date: Tue, 26 May 2015 12:47:27 +0800 Subject: [PATCH] Prophetstor driver needs to return snapshot objects Use snapshot objects instead of snapshot dictionaries of create_cgsnapshot and delete_cgsnapshot. Change-Id: I416cb53483c9106ff434dc659667c398868c91e6 Partially-Closes-Bug: #1458127 --- cinder/tests/unit/test_prophetstor_dpl.py | 21 ++++++--- .../volume/drivers/prophetstor/dplcommon.py | 45 +++++++++---------- 2 files changed, 34 insertions(+), 32 deletions(-) diff --git a/cinder/tests/unit/test_prophetstor_dpl.py b/cinder/tests/unit/test_prophetstor_dpl.py index 42aa199f0..eab0f753c 100644 --- a/cinder/tests/unit/test_prophetstor_dpl.py +++ b/cinder/tests/unit/test_prophetstor_dpl.py @@ -22,6 +22,7 @@ from oslo_utils import units from cinder import exception from cinder import test +from cinder.tests.unit import fake_snapshot from cinder.volume import configuration as conf from cinder.volume.drivers.prophetstor import dpl_iscsi as DPLDRIVER from cinder.volume.drivers.prophetstor import dplcommon as DPLCOMMON @@ -739,17 +740,23 @@ class TestProphetStorDPLDriver(test.TestCase): add_volumes=None, remove_volumes=[remove_vol]) - def test_create_consistency_group_snapshot(self): - self.DB_MOCK.snapshot_get_all_for_cgsnapshot.return_value = ( - [DATA_OUT_SNAPSHOT_CG]) + @mock.patch('cinder.objects.snapshot.SnapshotList.get_all_for_cgsnapshot') + def test_create_consistency_group_snapshot(self, get_all_for_cgsnapshot): + snapshot_obj = fake_snapshot.fake_snapshot_obj(self.context) + snapshot_obj.consistencygroup_id = \ + DATA_IN_CG_SNAPSHOT['consistencygroup_id'] + get_all_for_cgsnapshot.return_value = [snapshot_obj] self.DPL_MOCK.create_vdev_snapshot.return_value = DATA_OUTPUT model_update, snapshots = self.dpldriver.create_cgsnapshot( - self.context, DATA_IN_CG_SNAPSHOT) + self.context, snapshot_obj) self.assertDictMatch({'status': 'available'}, model_update) - def test_delete_consistency_group_snapshot(self): - self.DB_MOCK.snapshot_get_all_for_cgsnapshot.return_value = ( - [DATA_OUT_SNAPSHOT_CG]) + @mock.patch('cinder.objects.snapshot.SnapshotList.get_all_for_cgsnapshot') + def test_delete_consistency_group_snapshot(self, get_all_for_cgsnapshot): + snapshot_obj = fake_snapshot.fake_snapshot_obj(self.context) + snapshot_obj.consistencygroup_id = \ + DATA_IN_CG_SNAPSHOT['consistencygroup_id'] + get_all_for_cgsnapshot.return_value = [snapshot_obj] self.DPL_MOCK.delete_cgsnapshot.return_value = DATA_OUTPUT model_update, snapshots = self.dpldriver.delete_cgsnapshot( self.context, DATA_IN_CG_SNAPSHOT) diff --git a/cinder/volume/drivers/prophetstor/dplcommon.py b/cinder/volume/drivers/prophetstor/dplcommon.py index b647e2d3d..ce8819fd5 100644 --- a/cinder/volume/drivers/prophetstor/dplcommon.py +++ b/cinder/volume/drivers/prophetstor/dplcommon.py @@ -33,6 +33,7 @@ import six from cinder import exception from cinder.i18n import _, _LI, _LW, _LE +from cinder import objects from cinder.openstack.common import loopingcall from cinder.volume import driver from cinder.volume.drivers.prophetstor import options @@ -907,26 +908,24 @@ class DPLCOMMONDriver(driver.ConsistencyGroupVD, driver.ExtendVD, def create_cgsnapshot(self, context, cgsnapshot): """Creates a cgsnapshot.""" - cgId = cgsnapshot['consistencygroup_id'] - cgsnapshot_id = cgsnapshot['id'] - snapshots = self.db.snapshot_get_all_for_cgsnapshot( - context, cgsnapshot_id) - + snapshots = objects.SnapshotList().get_all_for_cgsnapshot( + context, cgsnapshot['id']) model_update = {} LOG.info(_LI('Start to create cgsnapshot for consistency group' - ': %(group_name)s'), {'group_name': cgId}) - + ': %(group_name)s'), + {'group_name': cgsnapshot['consistencygroup_id']}) try: - self.dpl.create_vdev_snapshot(self._conver_uuid2hex(cgId), - self._conver_uuid2hex(cgsnapshot_id), - cgsnapshot['name'], - cgsnapshot['description'], - True) + self.dpl.create_vdev_snapshot( + self._conver_uuid2hex(cgsnapshot['consistencygroup_id']), + self._conver_uuid2hex(cgsnapshot['id']), + cgsnapshot['name'], + cgsnapshot.get('description', ''), + True) for snapshot in snapshots: - snapshot['status'] = 'available' + snapshot.status = 'available' except Exception as e: msg = _('Failed to create cg snapshot %(id)s ' - 'due to %(reason)s.') % {'id': cgsnapshot_id, + 'due to %(reason)s.') % {'id': cgsnapshot['id'], 'reason': six.text_type(e)} raise exception.VolumeBackendAPIException(data=msg) @@ -936,27 +935,23 @@ class DPLCOMMONDriver(driver.ConsistencyGroupVD, driver.ExtendVD, def delete_cgsnapshot(self, context, cgsnapshot): """Deletes a cgsnapshot.""" - cgId = cgsnapshot['consistencygroup_id'] - cgsnapshot_id = cgsnapshot['id'] - snapshots = self.db.snapshot_get_all_for_cgsnapshot( - context, cgsnapshot_id) - + snapshots = objects.SnapshotList().get_all_for_cgsnapshot( + context, cgsnapshot['id']) model_update = {} model_update['status'] = cgsnapshot['status'] LOG.info(_LI('Delete cgsnapshot %(snap_name)s for consistency group: ' '%(group_name)s'), {'snap_name': cgsnapshot['id'], 'group_name': cgsnapshot['consistencygroup_id']}) - try: - self.dpl.delete_vdev_snapshot(self._conver_uuid2hex(cgId), - self._conver_uuid2hex(cgsnapshot_id), - True) + self.dpl.delete_vdev_snapshot( + self._conver_uuid2hex(cgsnapshot['consistencygroup_id']), + self._conver_uuid2hex(cgsnapshot['id']), True) for snapshot in snapshots: - snapshot['status'] = 'deleted' + snapshot.status = 'deleted' except Exception as e: msg = _('Failed to delete cgsnapshot %(id)s due to ' - '%(reason)s.') % {'id': cgsnapshot_id, + '%(reason)s.') % {'id': cgsnapshot['id'], 'reason': six.text_type(e)} raise exception.VolumeBackendAPIException(data=msg) -- 2.45.2