Skip to content

Commit 1925a9e

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Add "consistency group set" command"
2 parents 5408d02 + 4dc78e4 commit 1925a9e

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
@@ -86,6 +86,32 @@ List consistency groups.
8686

8787
List additional fields in output
8888

89+
consistency group set
90+
---------------------
91+
92+
Set consistency group properties.
93+
94+
.. program:: consistency group set
95+
.. code:: bash
96+
97+
os consistency group set
98+
[--name <name>]
99+
[--description <description>]
100+
<consistency-group>
101+
102+
.. option:: --name <name>
103+
104+
New consistency group name
105+
106+
.. option:: --description <description>
107+
108+
New consistency group description
109+
110+
.. _consistency_group_set-consistency-group:
111+
.. describe:: <consistency-group>
112+
113+
Consistency group to modify (name or ID)
114+
89115
consistency group show
90116
----------------------
91117

@@ -101,4 +127,3 @@ Display consistency group details.
101127
.. describe:: <consistency-group>
102128

103129
Consistency group to display (name or ID)
104-

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

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

396396

397+
class TestConsistencyGroupSet(TestConsistencyGroup):
398+
399+
consistency_group = (
400+
volume_fakes.FakeConsistencyGroup.create_one_consistency_group())
401+
402+
def setUp(self):
403+
super(TestConsistencyGroupSet, self).setUp()
404+
405+
self.consistencygroups_mock.get.return_value = (
406+
self.consistency_group)
407+
# Get the command object to test
408+
self.cmd = consistency_group.SetConsistencyGroup(self.app, None)
409+
410+
def test_consistency_group_set_name(self):
411+
new_name = 'new_name'
412+
arglist = [
413+
'--name', new_name,
414+
self.consistency_group.id,
415+
]
416+
verifylist = [
417+
('name', new_name),
418+
('description', None),
419+
('consistency_group', self.consistency_group.id),
420+
]
421+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
422+
423+
result = self.cmd.take_action(parsed_args)
424+
425+
# Set expected values
426+
kwargs = {
427+
'name': new_name,
428+
}
429+
self.consistencygroups_mock.update.assert_called_once_with(
430+
self.consistency_group.id,
431+
**kwargs
432+
)
433+
self.assertIsNone(result)
434+
435+
def test_consistency_group_set_description(self):
436+
new_description = 'new_description'
437+
arglist = [
438+
'--description', new_description,
439+
self.consistency_group.id,
440+
]
441+
verifylist = [
442+
('name', None),
443+
('description', new_description),
444+
('consistency_group', self.consistency_group.id),
445+
]
446+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
447+
448+
result = self.cmd.take_action(parsed_args)
449+
450+
# Set expected values
451+
kwargs = {
452+
'description': new_description,
453+
}
454+
self.consistencygroups_mock.update.assert_called_once_with(
455+
self.consistency_group.id,
456+
**kwargs
457+
)
458+
self.assertIsNone(result)
459+
460+
397461
class TestConsistencyGroupShow(TestConsistencyGroup):
398462
columns = (
399463
'availability_zone',

openstackclient/volume/v2/consistency_group.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def get_parser(self, prog_name):
159159
parser.add_argument(
160160
'--all-projects',
161161
action="store_true",
162-
help=_('Show detail for all projects. Admin only. '
162+
help=_('Show details for all projects. Admin only. '
163163
'(defaults to False)')
164164
)
165165
parser.add_argument(
@@ -188,6 +188,43 @@ def take_action(self, parsed_args):
188188
for s in consistency_groups))
189189

190190

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

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)