]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Prophetstor driver needs to return snapshot objects
authorrick.chen <rick.chen@prophetstor.com>
Tue, 26 May 2015 04:47:27 +0000 (12:47 +0800)
committerrick.chen <rick.chen@prophetstor.com>
Fri, 5 Jun 2015 03:59:39 +0000 (11:59 +0800)
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
cinder/volume/drivers/prophetstor/dplcommon.py

index 42aa199f08e1c3bab919e13678478ad43eb4767b..eab0f753c843b576646cd0753dc1c1a43c6ae62c 100644 (file)
@@ -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)
index b647e2d3d6e1a59f8eb514104120f06a4904f042..ce8819fd54dc4466b1e0294c65941e9a287b38b2 100644 (file)
@@ -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)