Skip to content

Commit 4a62c73

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "volume: Add 'volume qos set --no-property' option"
2 parents d0a17d4 + 629eb33 commit 4a62c73

File tree

9 files changed

+131
-25
lines changed

9 files changed

+131
-25
lines changed

doc/source/cli/command-objects/volume-qos.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,16 @@ Set QoS specification properties
116116
.. code:: bash
117117
118118
openstack volume qos set
119+
[--no-property]
119120
[--property <key=value> [...] ]
120121
<qos-spec>
121122
123+
.. option:: --no-property
124+
125+
Remove all properties from :ref:`\<snapshot\> <volume_qos_set-qos-spec>`
126+
(specify both :option:`--no-property` and :option:`--property` to
127+
remove the current properties before setting new properties.)
128+
122129
.. option:: --property <key=value>
123130

124131
Property to add or modify for this QoS specification (repeat option to set multiple properties)

openstackclient/tests/functional/volume/v1/test_qos.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ def test_volume_qos_set_show_unset(self):
5252

5353
name = uuid.uuid4().hex
5454
cmd_output = self.openstack(
55-
'volume qos create ' + '--consumer front-end '
56-
'--property Alpha=a ' + name,
55+
'volume qos create '
56+
+ '--consumer front-end '
57+
+ '--property Alpha=a '
58+
+ name,
5759
parse_output=True,
5860
)
5961
self.addCleanup(self.openstack, 'volume qos delete ' + name)
@@ -64,8 +66,9 @@ def test_volume_qos_set_show_unset(self):
6466
# Test volume qos set
6567
raw_output = self.openstack(
6668
'volume qos set '
67-
+ '--property Alpha=c '
69+
+ '--no-property '
6870
+ '--property Beta=b '
71+
+ '--property Charlie=c '
6972
+ name,
7073
)
7174
self.assertOutput('', raw_output)
@@ -76,11 +79,14 @@ def test_volume_qos_set_show_unset(self):
7679
parse_output=True,
7780
)
7881
self.assertEqual(name, cmd_output['name'])
79-
self.assertEqual({'Alpha': 'c', 'Beta': 'b'}, cmd_output['properties'])
82+
self.assertEqual(
83+
{'Beta': 'b', 'Charlie': 'c'},
84+
cmd_output['properties'],
85+
)
8086

8187
# Test volume qos unset
8288
raw_output = self.openstack(
83-
'volume qos unset ' + '--property Alpha ' + name,
89+
'volume qos unset ' + '--property Charlie ' + name,
8490
)
8591
self.assertOutput('', raw_output)
8692

openstackclient/tests/functional/volume/v2/test_qos.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ def test_volume_qos_set_show_unset(self):
5252

5353
name = uuid.uuid4().hex
5454
cmd_output = self.openstack(
55-
'volume qos create ' + '--consumer front-end '
56-
'--property Alpha=a ' + name,
55+
'volume qos create '
56+
+ '--consumer front-end '
57+
+ '--property Alpha=a '
58+
+ name,
5759
parse_output=True,
5860
)
5961
self.addCleanup(self.openstack, 'volume qos delete ' + name)
@@ -65,8 +67,9 @@ def test_volume_qos_set_show_unset(self):
6567
# Test volume qos set
6668
raw_output = self.openstack(
6769
'volume qos set '
68-
+ '--property Alpha=c '
70+
+ '--no-property '
6971
+ '--property Beta=b '
72+
+ '--property Charlie=c '
7073
+ name,
7174
)
7275
self.assertOutput('', raw_output)
@@ -77,11 +80,14 @@ def test_volume_qos_set_show_unset(self):
7780
parse_output=True,
7881
)
7982
self.assertEqual(name, cmd_output['name'])
80-
self.assertEqual({'Alpha': 'c', 'Beta': 'b'}, cmd_output['properties'])
83+
self.assertEqual(
84+
{'Beta': 'b', 'Charlie': 'c'},
85+
cmd_output['properties'],
86+
)
8187

8288
# Test volume qos unset
8389
raw_output = self.openstack(
84-
'volume qos unset ' + '--property Alpha ' + name,
90+
'volume qos unset ' + '--property Charlie ' + name,
8591
)
8692
self.assertOutput('', raw_output)
8793

openstackclient/tests/functional/volume/v3/test_qos.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ def test_volume_qos_set_show_unset(self):
5252

5353
name = uuid.uuid4().hex
5454
cmd_output = self.openstack(
55-
'volume qos create ' + '--consumer front-end '
56-
'--property Alpha=a ' + name,
55+
'volume qos create '
56+
+ '--consumer front-end '
57+
+ '--property Alpha=a '
58+
+ name,
5759
parse_output=True,
5860
)
5961
self.addCleanup(self.openstack, 'volume qos delete ' + name)
@@ -65,8 +67,9 @@ def test_volume_qos_set_show_unset(self):
6567
# Test volume qos set
6668
raw_output = self.openstack(
6769
'volume qos set '
68-
+ '--property Alpha=c '
70+
+ '--no-property '
6971
+ '--property Beta=b '
72+
+ '--property Charlie=c '
7073
+ name,
7174
)
7275
self.assertOutput('', raw_output)
@@ -77,11 +80,14 @@ def test_volume_qos_set_show_unset(self):
7780
parse_output=True,
7881
)
7982
self.assertEqual(name, cmd_output['name'])
80-
self.assertEqual({'Alpha': 'c', 'Beta': 'b'}, cmd_output['properties'])
83+
self.assertEqual(
84+
{'Beta': 'b', 'Charlie': 'c'},
85+
cmd_output['properties'],
86+
)
8187

8288
# Test volume qos unset
8389
raw_output = self.openstack(
84-
'volume qos unset ' + '--property Alpha ' + name,
90+
'volume qos unset ' + '--property Charlie ' + name,
8591
)
8692
self.assertOutput('', raw_output)
8793

openstackclient/tests/unit/volume/v1/test_qos_specs.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,22 +366,30 @@ def setUp(self):
366366

367367
def test_qos_set_with_properties_with_id(self):
368368
arglist = [
369+
'--no-property',
369370
'--property',
370-
'foo=bar',
371+
'a=b',
371372
'--property',
372-
'iops=9001',
373+
'c=d',
373374
self.qos_spec.id,
374375
]
376+
new_property = {"a": "b", "c": "d"}
375377
verifylist = [
376-
('property', self.qos_spec.specs),
378+
('no_property', True),
379+
('property', new_property),
377380
('qos_spec', self.qos_spec.id),
378381
]
379382
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
380383

381384
result = self.cmd.take_action(parsed_args)
382385

386+
self.qos_mock.unset_keys.assert_called_with(
387+
self.qos_spec.id,
388+
list(self.qos_spec.specs.keys()),
389+
)
383390
self.qos_mock.set_keys.assert_called_with(
384-
self.qos_spec.id, self.qos_spec.specs
391+
self.qos_spec.id,
392+
{"a": "b", "c": "d"},
385393
)
386394
self.assertIsNone(result)
387395

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,22 +362,29 @@ def setUp(self):
362362

363363
def test_qos_set_with_properties_with_id(self):
364364
arglist = [
365+
'--no-property',
365366
'--property',
366-
'foo=bar',
367+
'a=b',
367368
'--property',
368-
'iops=9001',
369+
'c=d',
369370
self.qos_spec.id,
370371
]
372+
new_property = {"a": "b", "c": "d"}
371373
verifylist = [
372-
('property', self.qos_spec.specs),
374+
('no_property', True),
375+
('property', new_property),
373376
('qos_spec', self.qos_spec.id),
374377
]
375378
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
376379

377380
result = self.cmd.take_action(parsed_args)
378381

382+
self.qos_mock.unset_keys.assert_called_with(
383+
self.qos_spec.id,
384+
list(self.qos_spec.specs.keys()),
385+
)
379386
self.qos_mock.set_keys.assert_called_with(
380-
self.qos_spec.id, self.qos_spec.specs
387+
self.qos_spec.id, {"a": "b", "c": "d"}
381388
)
382389
self.assertIsNone(result)
383390

openstackclient/volume/v1/qos_specs.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,16 @@ def get_parser(self, prog_name):
255255
metavar='<qos-spec>',
256256
help=_('QoS specification to modify (name or ID)'),
257257
)
258+
parser.add_argument(
259+
'--no-property',
260+
dest='no_property',
261+
action='store_true',
262+
help=_(
263+
'Remove all properties from <qos-spec> '
264+
'(specify both --no-property and --property to remove the '
265+
'current properties before setting new properties)'
266+
),
267+
)
258268
parser.add_argument(
259269
'--property',
260270
metavar='<key=value>',
@@ -272,8 +282,29 @@ def take_action(self, parsed_args):
272282
volume_client.qos_specs, parsed_args.qos_spec
273283
)
274284

285+
result = 0
286+
if parsed_args.no_property:
287+
try:
288+
key_list = list(qos_spec._info['specs'].keys())
289+
volume_client.qos_specs.unset_keys(qos_spec.id, key_list)
290+
except Exception as e:
291+
LOG.error(_("Failed to clean qos properties: %s"), e)
292+
result += 1
293+
275294
if parsed_args.property:
276-
volume_client.qos_specs.set_keys(qos_spec.id, parsed_args.property)
295+
try:
296+
volume_client.qos_specs.set_keys(
297+
qos_spec.id,
298+
parsed_args.property,
299+
)
300+
except Exception as e:
301+
LOG.error(_("Failed to set qos property: %s"), e)
302+
result += 1
303+
304+
if result > 0:
305+
raise exceptions.CommandError(
306+
_("One or more of the set operations failed")
307+
)
277308

278309

279310
class ShowQos(command.ShowOne):

openstackclient/volume/v2/qos_specs.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,16 @@ def get_parser(self, prog_name):
257257
metavar='<qos-spec>',
258258
help=_('QoS specification to modify (name or ID)'),
259259
)
260+
parser.add_argument(
261+
'--no-property',
262+
dest='no_property',
263+
action='store_true',
264+
help=_(
265+
'Remove all properties from <qos-spec> '
266+
'(specify both --no-property and --property to remove the '
267+
'current properties before setting new properties)'
268+
),
269+
)
260270
parser.add_argument(
261271
'--property',
262272
metavar='<key=value>',
@@ -274,8 +284,29 @@ def take_action(self, parsed_args):
274284
volume_client.qos_specs, parsed_args.qos_spec
275285
)
276286

287+
result = 0
288+
if parsed_args.no_property:
289+
try:
290+
key_list = list(qos_spec._info['specs'].keys())
291+
volume_client.qos_specs.unset_keys(qos_spec.id, key_list)
292+
except Exception as e:
293+
LOG.error(_("Failed to clean qos properties: %s"), e)
294+
result += 1
295+
277296
if parsed_args.property:
278-
volume_client.qos_specs.set_keys(qos_spec.id, parsed_args.property)
297+
try:
298+
volume_client.qos_specs.set_keys(
299+
qos_spec.id,
300+
parsed_args.property,
301+
)
302+
except Exception as e:
303+
LOG.error(_("Failed to set qos property: %s"), e)
304+
result += 1
305+
306+
if result > 0:
307+
raise exceptions.CommandError(
308+
_("One or more of the set operations failed")
309+
)
279310

280311

281312
class ShowQos(command.ShowOne):
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
features:
3+
- |
4+
Add ``--no-property`` option in ``volume qos set``.

0 commit comments

Comments
 (0)