From a2b096b7b4ad3a6498e208b160a5f5677c7044eb Mon Sep 17 00:00:00 2001 From: junboli Date: Tue, 4 Jul 2017 21:54:03 +0800 Subject: [PATCH] Use GroupSnapshotStatus enum field The GroupSnapshotStatus and GroupSnapshotStatusField have been defined already, This change just replaces the omissive group snapshot string status with group snapshot enum field. Change-Id: Ib7317c8d610e215f38d1ef5afe582ff44af006bd Partial-Implements: bp cinder-object-fields --- .../tests/functional/test_group_snapshots.py | 25 +++++++++++-------- .../tests/unit/api/v3/test_group_snapshots.py | 10 +++++--- .../tests/unit/objects/test_group_snapshot.py | 8 +++--- .../unit/volume/drivers/hpe/test_hpe3par.py | 2 +- cinder/volume/manager.py | 11 ++++---- 5 files changed, 33 insertions(+), 23 deletions(-) diff --git a/cinder/tests/functional/test_group_snapshots.py b/cinder/tests/functional/test_group_snapshots.py index e84127cec4b..b7d05a1c6c9 100644 --- a/cinder/tests/functional/test_group_snapshots.py +++ b/cinder/tests/functional/test_group_snapshots.py @@ -15,6 +15,7 @@ from oslo_utils import uuidutils +from cinder.objects import fields from cinder.tests.functional import functional_helpers @@ -92,18 +93,19 @@ class GroupSnapshotsTest(functional_helpers._FunctionalTestBase): # Check it's there found_group_snapshot = self._poll_group_snapshot_while( - created_group_snapshot_id, ['creating']) + created_group_snapshot_id, [fields.GroupSnapshotStatus.CREATING]) self.assertEqual(created_group_snapshot_id, found_group_snapshot['id']) self.assertEqual(created_group_id, found_group_snapshot['group_id']) - self.assertEqual('available', found_group_snapshot['status']) + self.assertEqual(fields.GroupSnapshotStatus.AVAILABLE, + found_group_snapshot['status']) # Delete the group snapshot self.api.delete_group_snapshot(created_group_snapshot_id) # Wait (briefly) for deletion. Delay is due to the 'message queue' found_group_snapshot = self._poll_group_snapshot_while( - created_group_snapshot_id, ['deleting']) + created_group_snapshot_id, [fields.GroupSnapshotStatus.DELETING]) # Delete the original group self.api.delete_group(created_group_id, @@ -203,7 +205,7 @@ class GroupSnapshotsTest(functional_helpers._FunctionalTestBase): # Wait (briefly) for deletion. Delay is due to the 'message queue' found_group_snapshot = self._poll_group_snapshot_while( - created_group_snapshot_id, ['deleting']) + created_group_snapshot_id, [fields.GroupSnapshotStatus.DELETING]) # Delete the original group self.api.delete_group(created_group_id, @@ -322,22 +324,25 @@ class GroupSnapshotsTest(functional_helpers._FunctionalTestBase): self.assertTrue(uuidutils.is_uuid_like(group_snapshot1['id'])) group_snapshot_id = group_snapshot1['id'] - self._poll_group_snapshot_while(group_snapshot_id, 'creating') + self._poll_group_snapshot_while(group_snapshot_id, + fields.GroupSnapshotStatus.CREATING) group_snapshot1 = self.api.get_group_snapshot(group_snapshot_id) - self.assertEqual("available", group_snapshot1['status']) + self.assertEqual(fields.GroupSnapshotStatus.AVAILABLE, + group_snapshot1['status']) # reset group snapshot status - self.api.reset_group_snapshot(group_snapshot_id, - {"reset_status": {"status": "error"}}) + self.api.reset_group_snapshot(group_snapshot_id, {"reset_status": { + "status": fields.GroupSnapshotStatus.ERROR}}) group_snapshot1 = self.api.get_group_snapshot(group_snapshot_id) - self.assertEqual("error", group_snapshot1['status']) + self.assertEqual(fields.GroupSnapshotStatus.ERROR, + group_snapshot1['status']) # Delete group, volume and group snapshot self.api.delete_group_snapshot(group_snapshot_id) found_group_snapshot = self._poll_group_snapshot_while( - group_snapshot_id, ['deleting']) + group_snapshot_id, [fields.GroupSnapshotStatus.DELETING]) self.api.delete_group(group_id, {'delete': {'delete-volumes': True}}) diff --git a/cinder/tests/unit/api/v3/test_group_snapshots.py b/cinder/tests/unit/api/v3/test_group_snapshots.py index 93326480a73..d464c4e5f90 100644 --- a/cinder/tests/unit/api/v3/test_group_snapshots.py +++ b/cinder/tests/unit/api/v3/test_group_snapshots.py @@ -84,7 +84,8 @@ class GroupSnapshotsAPITestCase(test.TestCase): res_dict['group_snapshot']['description']) self.assertEqual('test_group_snapshot', res_dict['group_snapshot']['name']) - self.assertEqual('creating', res_dict['group_snapshot']['status']) + self.assertEqual(fields.GroupSnapshotStatus.CREATING, + res_dict['group_snapshot']['status']) group_snapshot.destroy() @@ -422,7 +423,7 @@ class GroupSnapshotsAPITestCase(test.TestCase): group_snapshot = utils.create_group_snapshot( self.context, group_id=self.group.id, - status='available') + status=fields.GroupSnapshotStatus.AVAILABLE) req = fakes.HTTPRequest.blank('/v3/%s/group_snapshots/%s' % (fake.PROJECT_ID, group_snapshot.id), version=GROUP_MICRO_VERSION) @@ -431,7 +432,8 @@ class GroupSnapshotsAPITestCase(test.TestCase): group_snapshot = objects.GroupSnapshot.get_by_id(self.context, group_snapshot.id) self.assertEqual(http_client.ACCEPTED, res_dict.status_int) - self.assertEqual('deleting', group_snapshot.status) + self.assertEqual(fields.GroupSnapshotStatus.DELETING, + group_snapshot.status) group_snapshot.destroy() @@ -439,7 +441,7 @@ class GroupSnapshotsAPITestCase(test.TestCase): group_snapshot = utils.create_group_snapshot( self.context, group_id=self.group.id, - status='available') + status=fields.GroupSnapshotStatus.AVAILABLE) group2 = utils.create_group( self.context, status='creating', diff --git a/cinder/tests/unit/objects/test_group_snapshot.py b/cinder/tests/unit/objects/test_group_snapshot.py index 1f1416e1eed..b51924f5a90 100644 --- a/cinder/tests/unit/objects/test_group_snapshot.py +++ b/cinder/tests/unit/objects/test_group_snapshot.py @@ -19,6 +19,7 @@ import six from cinder import exception from cinder import objects +from cinder.objects import fields from cinder.tests.unit import fake_constants as fake from cinder.tests.unit import objects as test_objects from cinder.tests.unit.objects.test_group import fake_group @@ -29,7 +30,7 @@ fake_group_snapshot = { 'project_id': fake.PROJECT_ID, 'name': 'fake_name', 'description': 'fake_description', - 'status': 'creating', + 'status': fields.GroupSnapshotStatus.CREATING, 'group_id': fake.GROUP_ID, } @@ -90,7 +91,7 @@ class TestGroupSnapshot(test_objects.BaseObjectsTestCase): @mock.patch('cinder.db.sqlalchemy.api.group_snapshot_destroy') def test_destroy(self, group_snapshot_destroy, utcnow_mock): group_snapshot_destroy.return_value = { - 'status': 'deleted', + 'status': fields.GroupSnapshotStatus.DELETED, 'deleted': True, 'deleted_at': utcnow_mock.return_value} group_snapshot = objects.GroupSnapshot(context=self.context, @@ -100,7 +101,8 @@ class TestGroupSnapshot(test_objects.BaseObjectsTestCase): admin_context = group_snapshot_destroy.call_args[0][0] self.assertTrue(admin_context.is_admin) self.assertTrue(group_snapshot.deleted) - self.assertEqual('deleted', group_snapshot.status) + self.assertEqual(fields.GroupSnapshotStatus.DELETED, + group_snapshot.status) self.assertEqual(utcnow_mock.return_value.replace(tzinfo=pytz.UTC), group_snapshot.deleted_at) diff --git a/cinder/tests/unit/volume/drivers/hpe/test_hpe3par.py b/cinder/tests/unit/volume/drivers/hpe/test_hpe3par.py index 38704ae8730..24dc897c8dd 100644 --- a/cinder/tests/unit/volume/drivers/hpe/test_hpe3par.py +++ b/cinder/tests/unit/volume/drivers/hpe/test_hpe3par.py @@ -5050,7 +5050,7 @@ class HPE3PARBaseDriver(object): optional=group_snap_optional)] # delete the snapshot of the consistency group - group_snapshot.status = 'deleting' + group_snapshot.status = fields.GroupSnapshotStatus.DELETING self.driver.delete_group_snapshot(context.get_admin_context(), group_snapshot, []) diff --git a/cinder/volume/manager.py b/cinder/volume/manager.py index 9a15b0bb221..baae6899cb0 100644 --- a/cinder/volume/manager.py +++ b/cinder/volume/manager.py @@ -3578,11 +3578,12 @@ class VolumeManager(manager.CleanableManager, fields.SnapshotStatus.ERROR_DELETING, fields.SnapshotStatus.ERROR] and model_update['status'] not in - ['error_deleting', 'error']): + [fields.GroupSnapshotStatus.ERROR_DELETING, + fields.GroupSnapshotStatus.ERROR]): model_update['status'] = snap_model['status'] if model_update: - if model_update['status'] == 'error': + if model_update['status'] == fields.GroupSnapshotStatus.ERROR: msg = (_('Error occurred when creating group_snapshot ' '%s.') % group_snapshot.id) LOG.error(msg) @@ -3593,7 +3594,7 @@ class VolumeManager(manager.CleanableManager, except exception.CinderException: with excutils.save_and_reraise_exception(): - group_snapshot.status = 'error' + group_snapshot.status = fields.GroupSnapshotStatus.ERROR group_snapshot.save() # Update snapshot status to 'error' if driver returns # None for snapshots_model_update. @@ -3631,7 +3632,7 @@ class VolumeManager(manager.CleanableManager, snapshot.progress = '100%' snapshot.save() - group_snapshot.status = 'available' + group_snapshot.status = fields.GroupSnapshotStatus.AVAILABLE group_snapshot.save() LOG.info("group_snapshot %s: created successfully", @@ -3762,7 +3763,7 @@ class VolumeManager(manager.CleanableManager, except exception.CinderException: with excutils.save_and_reraise_exception(): - group_snapshot.status = 'error' + group_snapshot.status = fields.GroupSnapshotStatus.ERROR group_snapshot.save() # Update snapshot status to 'error' if driver returns # None for snapshots_model_update.