Skip to content

Commit 4dc78e4

Browse files
author
zhiyong.dai
committed
Add "consistency group set" command
Add "consistency group set" command in volume v2 (v2 only). Change-Id: I53116015388b7a4b0e15813f52c1246166bb0fc1 Implements: bp cinder-command-support Partial-Bug: #1613964
1 parent e05c8d7 commit 4dc78e4

5 files changed

Lines changed: 133 additions & 2 deletions

File tree

doc/source/command-objects/consistency-group.rst

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,32 @@ List consistency groups.
8282

8383
List additional fields in output
8484

85+
consistency group set
86+
---------------------
87+
88+
Set consistency group properties.
89+
90+
.. program:: consistency group set
91+
.. code:: bash
92+
93+
os consistency group set
94+
[--name <name>]
95+
[--description <description>]
96+
<consistency-group>
97+
98+
.. option:: --name <name>
99+
100+
New consistency group name
101+
102+
.. option:: --description <description>
103+
104+
New consistency group description
105+
106+
.. _consistency_group_set-consistency-group:
107+
.. describe:: <consistency-group>
108+
109+
Consistency group to modify (name or ID)
110+
85111
consistency group show
86112
----------------------
87113

@@ -97,4 +123,3 @@ Display consistency group details.
97123
.. describe:: <consistency-group>
98124

99125
Consistency group to display (name or ID)
100-

openstackclient/tests/unit/volume/v2/test_consistency_group.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,70 @@ def test_consistency_group_list_with_long(self):
355355
self.assertEqual(self.data_long, list(data))
356356

357357

358+
class TestConsistencyGroupSet(TestConsistencyGroup):
359+
360+
consistency_group = (
361+
volume_fakes.FakeConsistencyGroup.create_one_consistency_group())
362+
363+
def setUp(self):
364+
super(TestConsistencyGroupSet, self).setUp()
365+
366+
self.consistencygroups_mock.get.return_value = (
367+
self.consistency_group)
368+
# Get the command object to test
369+
self.cmd = consistency_group.SetConsistencyGroup(self.app, None)
370+
371+
def test_consistency_group_set_name(self):
372+
new_name = 'new_name'
373+
arglist = [
374+
'--name', new_name,
375+
self.consistency_group.id,
376+
]
377+
verifylist = [
378+
('name', new_name),
379+
('description', None),
380+
('consistency_group', self.consistency_group.id),
381+
]
382+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
383+
384+
result = self.cmd.take_action(parsed_args)
385+
386+
# Set expected values
387+
kwargs = {
388+
'name': new_name,
389+
}
390+
self.consistencygroups_mock.update.assert_called_once_with(
391+
self.consistency_group.id,
392+
**kwargs
393+
)
394+
self.assertIsNone(result)
395+
396+
def test_consistency_group_set_description(self):
397+
new_description = 'new_description'
398+
arglist = [
399+
'--description', new_description,
400+
self.consistency_group.id,
401+
]
402+
verifylist = [
403+
('name', None),
404+
('description', new_description),
405+
('consistency_group', self.consistency_group.id),
406+
]
407+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
408+
409+
result = self.cmd.take_action(parsed_args)
410+
411+
# Set expected values
412+
kwargs = {
413+
'description': new_description,
414+
}
415+
self.consistencygroups_mock.update.assert_called_once_with(
416+
self.consistency_group.id,
417+
**kwargs
418+
)
419+
self.assertIsNone(result)
420+
421+
358422
class TestConsistencyGroupShow(TestConsistencyGroup):
359423
columns = (
360424
'availability_zone',

openstackclient/volume/v2/consistency_group.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def get_parser(self, prog_name):
151151
parser.add_argument(
152152
'--all-projects',
153153
action="store_true",
154-
help=_('Show detail for all projects. Admin only. '
154+
help=_('Show details for all projects. Admin only. '
155155
'(defaults to False)')
156156
)
157157
parser.add_argument(
@@ -180,6 +180,43 @@ def take_action(self, parsed_args):
180180
for s in consistency_groups))
181181

182182

183+
class SetConsistencyGroup(command.Command):
184+
_description = _("Set consistency group properties")
185+
186+
def get_parser(self, prog_name):
187+
parser = super(SetConsistencyGroup, self).get_parser(prog_name)
188+
parser.add_argument(
189+
'consistency_group',
190+
metavar='<consistency-group>',
191+
help=_('Consistency group to modify (name or ID)')
192+
)
193+
parser.add_argument(
194+
'--name',
195+
metavar='<name>',
196+
help=_('New consistency group name'),
197+
)
198+
parser.add_argument(
199+
'--description',
200+
metavar='<description>',
201+
help=_('New consistency group description'),
202+
)
203+
return parser
204+
205+
def take_action(self, parsed_args):
206+
volume_client = self.app.client_manager.volume
207+
kwargs = {}
208+
if parsed_args.name:
209+
kwargs['name'] = parsed_args.name
210+
if parsed_args.description:
211+
kwargs['description'] = parsed_args.description
212+
if kwargs:
213+
consistency_group_id = utils.find_resource(
214+
volume_client.consistencygroups,
215+
parsed_args.consistency_group).id
216+
volume_client.consistencygroups.update(
217+
consistency_group_id, **kwargs)
218+
219+
183220
class ShowConsistencyGroup(command.ShowOne):
184221
_description = _("Display consistency group details.")
185222

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
features:
3+
- Add ``consistency group set`` command in volume v2.
4+
[Bug `1613964 <https://bugs.launchpad.net/python-openstackclient/+bug/1613964>`_]

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@ openstack.volume.v2 =
518518
consistency_group_create = openstackclient.volume.v2.consistency_group:CreateConsistencyGroup
519519
consistency_group_delete = openstackclient.volume.v2.consistency_group:DeleteConsistencyGroup
520520
consistency_group_list = openstackclient.volume.v2.consistency_group:ListConsistencyGroup
521+
consistency_group_set = openstackclient.volume.v2.consistency_group:SetConsistencyGroup
521522
consistency_group_show = openstackclient.volume.v2.consistency_group:ShowConsistencyGroup
522523

523524
consistency_group_snapshot_create = openstackclient.volume.v2.consistency_group_snapshot:CreateConsistencyGroupSnapshot

0 commit comments

Comments
 (0)