Skip to content

Commit c17819a

Browse files
author
Rodolfo Alonso Hernandez
committed
Add new parameter "is_default" to Network QoS policy.
Add a set of exclusive parameters to the Network QoS policy: --default: makes this policy the default policy for the project to which the qos policy belongs. --no-default: unset the property. Closes-Bug: #1639220 Depends-On: If5ff2b00fa828f93aa089e275ddbd1ff542b79d4 Depends-On: Ibe7b7881cb190bfd5582f35b6de51a8bc21135de Change-Id: I0269b837dc29bbd8ee2089d847cadb72d800fa30
1 parent 79b992b commit c17819a

6 files changed

Lines changed: 112 additions & 13 deletions

File tree

doc/source/cli/command-objects/network-qos-policy.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Create new Network QoS policy
2020
[--share | --no-share]
2121
[--project <project>]
2222
[--project-domain <project-domain>]
23+
[--default | --no-default]
2324
<name>
2425
2526
.. option:: --description <description>
@@ -43,6 +44,14 @@ Create new Network QoS policy
4344
Domain the project belongs to (name or ID).
4445
This can be used in case collisions between project names exist.
4546

47+
.. option:: --default
48+
49+
Set this as a default network QoS policy
50+
51+
.. option:: --no-default
52+
53+
Set this as a non-default network QoS policy
54+
4655
.. _network_qos_policy_create-name:
4756
.. describe:: <name>
4857

@@ -105,6 +114,7 @@ Set Network QoS policy properties
105114
[--name <name>]
106115
[--description <description>]
107116
[--share | --no-share]
117+
[--default | --no-default]
108118
<qos-policy>
109119
110120
.. option:: --name <name>
@@ -123,6 +133,14 @@ Set Network QoS policy properties
123133
124134
Make the QoS policy not accessible by other projects
125135
136+
.. option:: --default
137+
138+
Set this as a default network QoS policy
139+
140+
.. option:: --no-default
141+
142+
Set this as a non-default network QoS policy
143+
126144
.. _network_qos_policy_set-qos-policy:
127145
.. describe:: <qos-policy>
128146

openstackclient/network/v2/network_qos_policy.py

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,15 @@ def _get_attrs(client_manager, parsed_args):
4545
attrs['shared'] = True
4646
if parsed_args.no_share:
4747
attrs['shared'] = False
48-
if parsed_args.project is not None:
48+
# NOTE(ralonsoh): 'default' and 'no_default' parameters are defined only in
49+
# create and set commands context only.
50+
if 'default' in parsed_args and parsed_args.default:
51+
attrs['is_default'] = True
52+
if 'no_default' in parsed_args and parsed_args.no_default:
53+
attrs['is_default'] = False
54+
# NOTE(ralonsoh): 'project' parameter is defined only in create and list
55+
# commands context only.
56+
if 'project' in parsed_args and parsed_args.project is not None:
4957
identity_client = client_manager.identity
5058
project_id = identity_common.find_project(
5159
identity_client,
@@ -93,6 +101,17 @@ def get_parser(self, prog_name):
93101
help=_("Owner's project (name or ID)")
94102
)
95103
identity_common.add_project_domain_option_to_parser(parser)
104+
default_group = parser.add_mutually_exclusive_group()
105+
default_group.add_argument(
106+
'--default',
107+
action='store_true',
108+
help=_("Set this as a default network QoS policy"),
109+
)
110+
default_group.add_argument(
111+
'--no-default',
112+
action='store_true',
113+
help=_("Set this as a non-default network QoS policy"),
114+
)
96115
return parser
97116

98117
def take_action(self, parsed_args):
@@ -170,12 +189,14 @@ def take_action(self, parsed_args):
170189
'id',
171190
'name',
172191
'is_shared',
192+
'is_default',
173193
'project_id',
174194
)
175195
column_headers = (
176196
'ID',
177197
'Name',
178198
'Shared',
199+
'Default',
179200
'Project',
180201
)
181202
attrs = _get_attrs(self.app.client_manager, parsed_args)
@@ -219,22 +240,25 @@ def get_parser(self, prog_name):
219240
action='store_true',
220241
help=_('Make the QoS policy not accessible by other projects'),
221242
)
243+
default_group = parser.add_mutually_exclusive_group()
244+
default_group.add_argument(
245+
'--default',
246+
action='store_true',
247+
help=_("Set this as a default network QoS policy"),
248+
)
249+
default_group.add_argument(
250+
'--no-default',
251+
action='store_true',
252+
help=_("Set this as a non-default network QoS policy"),
253+
)
222254
return parser
223255

224256
def take_action(self, parsed_args):
225257
client = self.app.client_manager.network
226258
obj = client.find_qos_policy(
227259
parsed_args.policy,
228260
ignore_missing=False)
229-
attrs = {}
230-
if parsed_args.name is not None:
231-
attrs['name'] = parsed_args.name
232-
if parsed_args.share:
233-
attrs['shared'] = True
234-
if parsed_args.no_share:
235-
attrs['shared'] = False
236-
if parsed_args.description is not None:
237-
attrs['description'] = parsed_args.description
261+
attrs = _get_attrs(self.app.client_manager, parsed_args)
238262
client.update_qos_policy(obj, **attrs)
239263

240264

openstackclient/tests/functional/network/v2/test_network_qos_policy.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,16 @@ def test_qos_policy_set(self):
6868
raw_output = self.openstack('network qos policy show ' + self.NAME +
6969
opts)
7070
self.assertEqual("True\n", raw_output)
71+
72+
def test_qos_policy_default(self):
73+
self.openstack('network qos policy set --default ' + self.NAME)
74+
opts = self.get_opts(['is_default'])
75+
raw_output = self.openstack('network qos policy show ' + self.NAME +
76+
opts)
77+
self.assertEqual("True\n", raw_output)
78+
79+
self.openstack('network qos policy set --no-default ' + self.NAME)
80+
opts = self.get_opts(['is_default'])
81+
raw_output = self.openstack('network qos policy show ' + self.NAME +
82+
opts)
83+
self.assertEqual("False\n", raw_output)

openstackclient/tests/unit/network/v2/fakes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,7 @@ def create_one_qos_policy(attrs=None):
841841
qos_policy_attrs = {
842842
'name': 'qos-policy-name-' + uuid.uuid4().hex,
843843
'id': qos_id,
844+
'is_default': False,
844845
'tenant_id': 'project-id-' + uuid.uuid4().hex,
845846
'shared': False,
846847
'description': 'qos-policy-description-' + uuid.uuid4().hex,

openstackclient/tests/unit/network/v2/test_network_qos_policy.py

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class TestCreateNetworkQosPolicy(TestQosPolicy):
4848
columns = (
4949
'description',
5050
'id',
51+
'is_default',
5152
'name',
5253
'project_id',
5354
'rules',
@@ -57,6 +58,7 @@ class TestCreateNetworkQosPolicy(TestQosPolicy):
5758
data = (
5859
new_qos_policy.description,
5960
new_qos_policy.id,
61+
new_qos_policy.is_default,
6062
new_qos_policy.name,
6163
new_qos_policy.project_id,
6264
new_qos_policy.rules,
@@ -106,12 +108,14 @@ def test_create_all_options(self):
106108
'--project', self.project.name,
107109
self.new_qos_policy.name,
108110
'--description', 'QoS policy description',
111+
'--default',
109112
]
110113
verifylist = [
111114
('share', True),
112115
('project', self.project.name),
113116
('name', self.new_qos_policy.name),
114117
('description', 'QoS policy description'),
118+
('default', True),
115119
]
116120

117121
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@@ -122,6 +126,28 @@ def test_create_all_options(self):
122126
'tenant_id': self.project.id,
123127
'name': self.new_qos_policy.name,
124128
'description': 'QoS policy description',
129+
'is_default': True,
130+
})
131+
self.assertEqual(self.columns, columns)
132+
self.assertEqual(self.data, data)
133+
134+
def test_create_no_default(self):
135+
arglist = [
136+
self.new_qos_policy.name,
137+
'--no-default'
138+
]
139+
verifylist = [
140+
('project', None),
141+
('name', self.new_qos_policy.name),
142+
('default', False),
143+
]
144+
145+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
146+
columns, data = (self.cmd.take_action(parsed_args))
147+
148+
self.network.create_qos_policy.assert_called_once_with(**{
149+
'name': self.new_qos_policy.name,
150+
'is_default': False,
125151
})
126152
self.assertEqual(self.columns, columns)
127153
self.assertEqual(self.data, data)
@@ -220,6 +246,7 @@ class TestListNetworkQosPolicy(TestQosPolicy):
220246
'ID',
221247
'Name',
222248
'Shared',
249+
'Default',
223250
'Project',
224251
)
225252
data = []
@@ -228,6 +255,7 @@ class TestListNetworkQosPolicy(TestQosPolicy):
228255
qos_policy.id,
229256
qos_policy.name,
230257
qos_policy.shared,
258+
qos_policy.is_default,
231259
qos_policy.project_id,
232260
))
233261

@@ -333,17 +361,19 @@ def test_set_nothing(self):
333361
self._qos_policy, **attrs)
334362
self.assertIsNone(result)
335363

336-
def test_set_name_share_description(self):
364+
def test_set_name_share_description_default(self):
337365
arglist = [
338366
'--name', 'new_qos_policy',
339367
'--share',
340368
'--description', 'QoS policy description',
369+
'--default',
341370
self._qos_policy.name,
342371
]
343372
verifylist = [
344373
('name', 'new_qos_policy'),
345374
('share', True),
346375
('description', 'QoS policy description'),
376+
('default', True),
347377
('policy', self._qos_policy.name),
348378
]
349379

@@ -353,25 +383,29 @@ def test_set_name_share_description(self):
353383
'name': 'new_qos_policy',
354384
'description': 'QoS policy description',
355385
'shared': True,
386+
'is_default': True,
356387
}
357388
self.network.update_qos_policy.assert_called_with(
358389
self._qos_policy, **attrs)
359390
self.assertIsNone(result)
360391

361-
def test_set_no_share(self):
392+
def test_set_no_share_no_default(self):
362393
arglist = [
363394
'--no-share',
395+
'--no-default',
364396
self._qos_policy.name,
365397
]
366398
verifylist = [
367399
('no_share', True),
400+
('no_default', True),
368401
('policy', self._qos_policy.name),
369402
]
370403

371404
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
372405
result = self.cmd.take_action(parsed_args)
373406
attrs = {
374-
'shared': False
407+
'shared': False,
408+
'is_default': False
375409
}
376410
self.network.update_qos_policy.assert_called_with(
377411
self._qos_policy, **attrs)
@@ -386,6 +420,7 @@ class TestShowNetworkQosPolicy(TestQosPolicy):
386420
columns = (
387421
'description',
388422
'id',
423+
'is_default',
389424
'name',
390425
'project_id',
391426
'rules',
@@ -394,6 +429,7 @@ class TestShowNetworkQosPolicy(TestQosPolicy):
394429
data = (
395430
_qos_policy.description,
396431
_qos_policy.id,
432+
_qos_policy.is_default,
397433
_qos_policy.name,
398434
_qos_policy.project_id,
399435
_qos_policy.rules,
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
features:
3+
- |
4+
Add ``--default`` and ``--no-default`` options to
5+
``network qos policy create`` and ``network qos policy set``
6+
comamnds.
7+
[Bug `1639220 <https://bugs.launchpad.net/bugs/1639220>`_]

0 commit comments

Comments
 (0)