From f12aab8035a85d58dd105c9f1faaff8515ed84db Mon Sep 17 00:00:00 2001 From: Xing Yang Date: Tue, 30 Dec 2014 22:23:44 -0500 Subject: [PATCH] Kilo Consistency Group CLI update This patch addresses the following: * Modify Consistency Group * Add CLI to update a consistency group, i.e., changing name and description, adding existing volumes to CG and removing volumes from CG. cinder consisgroup-update --name --description --add-volumes --remove-volumes Implements: blueprint consistency-groups-kilo-update Change-Id: I76317dc006c1f80e2e6c83218e9566f1d37d935e --- .../tests/unit/v2/test_consistencygroups.py | 38 ++++++++++++++++- cinderclient/tests/unit/v2/test_shell.py | 18 ++++++++ cinderclient/v2/shell.py | 42 +++++++++++++++++++ 3 files changed, 96 insertions(+), 2 deletions(-) diff --git a/cinderclient/tests/unit/v2/test_consistencygroups.py b/cinderclient/tests/unit/v2/test_consistencygroups.py index e16973f48..32f57bd97 100644 --- a/cinderclient/tests/unit/v2/test_consistencygroups.py +++ b/cinderclient/tests/unit/v2/test_consistencygroups.py @@ -17,7 +17,6 @@ from cinderclient.tests.unit import utils from cinderclient.tests.unit.v2 import fakes - cs = fakes.FakeClient() @@ -47,7 +46,7 @@ class ConsistencygroupsTest(utils.TestCase): 'project_id': None}} cs.assert_called('POST', '/consistencygroups', body=expected) - def test_update_consistencygroup(self): + def test_update_consistencygroup_name(self): v = cs.consistencygroups.list()[0] expected = {'consistencygroup': {'name': 'cg2'}} v.update(name='cg2') @@ -57,6 +56,41 @@ class ConsistencygroupsTest(utils.TestCase): cs.consistencygroups.update(v, name='cg2') cs.assert_called('PUT', '/consistencygroups/1234', body=expected) + def test_update_consistencygroup_description(self): + v = cs.consistencygroups.list()[0] + expected = {'consistencygroup': {'description': 'cg2 desc'}} + v.update(description='cg2 desc') + cs.assert_called('PUT', '/consistencygroups/1234', body=expected) + cs.consistencygroups.update('1234', description='cg2 desc') + cs.assert_called('PUT', '/consistencygroups/1234', body=expected) + cs.consistencygroups.update(v, description='cg2 desc') + cs.assert_called('PUT', '/consistencygroups/1234', body=expected) + + def test_update_consistencygroup_add_volumes(self): + v = cs.consistencygroups.list()[0] + uuids = 'uuid1,uuid2' + expected = {'consistencygroup': {'add_volumes': uuids}} + v.update(add_volumes=uuids) + cs.assert_called('PUT', '/consistencygroups/1234', body=expected) + cs.consistencygroups.update('1234', add_volumes=uuids) + cs.assert_called('PUT', '/consistencygroups/1234', body=expected) + cs.consistencygroups.update(v, add_volumes=uuids) + cs.assert_called('PUT', '/consistencygroups/1234', body=expected) + + def test_update_consistencygroup_remove_volumes(self): + v = cs.consistencygroups.list()[0] + uuids = 'uuid3,uuid4' + expected = {'consistencygroup': {'remove_volumes': uuids}} + v.update(remove_volumes=uuids) + cs.assert_called('PUT', '/consistencygroups/1234', body=expected) + cs.consistencygroups.update('1234', remove_volumes=uuids) + cs.assert_called('PUT', '/consistencygroups/1234', body=expected) + cs.consistencygroups.update(v, remove_volumes=uuids) + cs.assert_called('PUT', '/consistencygroups/1234', body=expected) + + def test_update_consistencygroup_none(self): + self.assertEqual(None, cs.consistencygroups.update('1234')) + def test_update_consistencygroup_no_props(self): cs.consistencygroups.update('1234') diff --git a/cinderclient/tests/unit/v2/test_shell.py b/cinderclient/tests/unit/v2/test_shell.py index 2004ae5b1..66777987e 100644 --- a/cinderclient/tests/unit/v2/test_shell.py +++ b/cinderclient/tests/unit/v2/test_shell.py @@ -801,3 +801,21 @@ class ShellTest(utils.TestCase): def test_list_transfer_all_tenants(self): self.run_command('transfer-list --all-tenants=1') self.assert_called('GET', '/os-volume-transfer/detail?all_tenants=1') + + def test_consistencygroup_update(self): + self.run_command('consisgroup-update ' + '--name cg2 --description desc2 ' + '--add-volumes uuid1,uuid2 ' + '--remove-volumes uuid3,uuid4 ' + '1234') + expected = {'consistencygroup': {'name': 'cg2', + 'description': 'desc2', + 'add_volumes': 'uuid1,uuid2', + 'remove_volumes': 'uuid3,uuid4'}} + self.assert_called('PUT', '/consistencygroups/1234', + body=expected) + + def test_consistencygroup_update_bad_request(self): + self.assertRaises(exceptions.BadRequest, + self.run_command, + 'consisgroup-update 1234') diff --git a/cinderclient/v2/shell.py b/cinderclient/v2/shell.py index f9efb7fc0..be5f9b7c1 100644 --- a/cinderclient/v2/shell.py +++ b/cinderclient/v2/shell.py @@ -1973,6 +1973,48 @@ def do_consisgroup_delete(cs, args): "consistency groups.") +@utils.arg('consistencygroup', + metavar='', + help='Name or ID of a consistency group.') +@utils.arg('--name', metavar='', + help='New name for consistency group. Default=None.') +@utils.arg('--description', metavar='', + help='New description for consistency group. Default=None.') +@utils.arg('--add-volumes', + metavar='', + help='UUID of one or more volumes ' + 'to be added to the consistency group, ' + 'separated by commas. Default=None.') +@utils.arg('--remove-volumes', + metavar='', + help='UUID of one or more volumes ' + 'to be removed from the consistency group, ' + 'separated by commas. Default=None.') +@utils.service_type('volumev2') +def do_consisgroup_update(cs, args): + """Updates a consistencygroup.""" + kwargs = {} + + if args.name is not None: + kwargs['name'] = args.name + + if args.description is not None: + kwargs['description'] = args.description + + if args.add_volumes is not None: + kwargs['add_volumes'] = args.add_volumes + + if args.remove_volumes is not None: + kwargs['remove_volumes'] = args.remove_volumes + + if not kwargs: + msg = ('At least one of the following args must be supplied: ' + 'name, description, add-volumes, remove-volumes.') + raise exceptions.BadRequest(code=400, message=msg) + + _find_consistencygroup(cs, args.consistencygroup).update(**kwargs) + + @utils.arg('--all-tenants', dest='all_tenants', metavar='<0|1>',