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 <name> --description <description>
    --add-volumes <uuid1,uuid2,...> --remove-volumes <uuid5,uuid6,...>

Implements: blueprint consistency-groups-kilo-update
Change-Id: I76317dc006c1f80e2e6c83218e9566f1d37d935e
This commit is contained in:
Xing Yang
2014-12-30 22:23:44 -05:00
parent 8ba6242d64
commit f12aab8035
3 changed files with 96 additions and 2 deletions

View File

@@ -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')

View File

@@ -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')

View File

@@ -1973,6 +1973,48 @@ def do_consisgroup_delete(cs, args):
"consistency groups.")
@utils.arg('consistencygroup',
metavar='<consistencygroup>',
help='Name or ID of a consistency group.')
@utils.arg('--name', metavar='<name>',
help='New name for consistency group. Default=None.')
@utils.arg('--description', metavar='<description>',
help='New description for consistency group. Default=None.')
@utils.arg('--add-volumes',
metavar='<uuid1,uuid2,......>',
help='UUID of one or more volumes '
'to be added to the consistency group, '
'separated by commas. Default=None.')
@utils.arg('--remove-volumes',
metavar='<uuid3,uuid4,......>',
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>',