Skip to content

Commit 9b6d02d

Browse files
committed
Make max_burst_kbps option as optional for bw limit QoS rule
Attribute max_burst_kbps of QoS bandwidth limit rule in Neutron's is optional in API so it should be also optional on client's side. Change-Id: Ie085b73fa885ff12f9ac080666cf3ca6a09b632a Related-Bug:#1770622 Task: 19658 Story: 2002017
1 parent f7e4d31 commit 9b6d02d

3 files changed

Lines changed: 53 additions & 11 deletions

File tree

openstackclient/network/v2/network_qos_rule.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929
MANDATORY_PARAMETERS = {
3030
RULE_TYPE_MINIMUM_BANDWIDTH: {'min_kbps', 'direction'},
3131
RULE_TYPE_DSCP_MARKING: {'dscp_mark'},
32-
RULE_TYPE_BANDWIDTH_LIMIT: {'max_kbps', 'max_burst_kbps'}}
32+
RULE_TYPE_BANDWIDTH_LIMIT: {'max_kbps'}}
3333
OPTIONAL_PARAMETERS = {
3434
RULE_TYPE_MINIMUM_BANDWIDTH: set(),
3535
RULE_TYPE_DSCP_MARKING: set(),
36-
RULE_TYPE_BANDWIDTH_LIMIT: {'direction'}}
36+
RULE_TYPE_BANDWIDTH_LIMIT: {'direction', 'max_burst_kbps'}}
3737
DIRECTION_EGRESS = 'egress'
3838
DIRECTION_INGRESS = 'ingress'
3939
DSCP_VALID_MARKS = [0, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32,
@@ -62,11 +62,11 @@ def _check_type_parameters(attrs, type, is_create):
6262
notreq_params -= type_params
6363
if is_create and None in map(attrs.get, req_params):
6464
msg = (_('"Create" rule command for type "%(rule_type)s" requires '
65-
'arguments %(args)s') %
65+
'arguments: %(args)s') %
6666
{'rule_type': type, 'args': ", ".join(sorted(req_params))})
6767
raise exceptions.CommandError(msg)
6868
if set(attrs.keys()) & notreq_params:
69-
msg = (_('Rule type "%(rule_type)s" only requires arguments %(args)s')
69+
msg = (_('Rule type "%(rule_type)s" only requires arguments: %(args)s')
7070
% {'rule_type': type, 'args': ", ".join(sorted(type_params))})
7171
raise exceptions.CommandError(msg)
7272

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ def setUp(self):
167167
'network qos rule create -f json '
168168
'--type bandwidth-limit '
169169
'--max-kbps 10000 '
170-
'--max-burst-kbits 1400 '
171170
'--egress %s' %
172171
self.QOS_POLICY_NAME
173172
))

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

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def test_create_wrong_options(self):
127127
self.cmd.take_action(parsed_args)
128128
except exceptions.CommandError as e:
129129
msg = ('"Create" rule command for type "minimum-bandwidth" '
130-
'requires arguments direction, min_kbps')
130+
'requires arguments: direction, min_kbps')
131131
self.assertEqual(msg, str(e))
132132

133133

@@ -213,7 +213,7 @@ def test_create_wrong_options(self):
213213
self.cmd.take_action(parsed_args)
214214
except exceptions.CommandError as e:
215215
msg = ('"Create" rule command for type "dscp-marking" '
216-
'requires arguments dscp_mark')
216+
'requires arguments: dscp_mark')
217217
self.assertEqual(msg, str(e))
218218

219219

@@ -263,6 +263,49 @@ def test_create_no_options(self):
263263
self.cmd, arglist, verifylist)
264264

265265
def test_create_default_options(self):
266+
arglist = [
267+
'--type', RULE_TYPE_BANDWIDTH_LIMIT,
268+
'--max-kbps', str(self.new_rule.max_kbps),
269+
'--egress',
270+
self.new_rule.qos_policy_id,
271+
]
272+
273+
verifylist = [
274+
('type', RULE_TYPE_BANDWIDTH_LIMIT),
275+
('max_kbps', self.new_rule.max_kbps),
276+
('egress', True),
277+
('qos_policy', self.new_rule.qos_policy_id),
278+
]
279+
280+
rule = network_fakes.FakeNetworkQosRule.create_one_qos_rule(
281+
{'qos_policy_id': self.qos_policy.id,
282+
'type': RULE_TYPE_BANDWIDTH_LIMIT})
283+
rule.max_burst_kbits = 0
284+
expected_data = (
285+
rule.direction,
286+
rule.id,
287+
rule.max_burst_kbits,
288+
rule.max_kbps,
289+
rule.project_id,
290+
rule.qos_policy_id,
291+
rule.type,
292+
)
293+
294+
with mock.patch.object(
295+
self.network, "create_qos_bandwidth_limit_rule",
296+
return_value=rule) as create_qos_bandwidth_limit_rule:
297+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
298+
columns, data = (self.cmd.take_action(parsed_args))
299+
300+
create_qos_bandwidth_limit_rule.assert_called_once_with(
301+
self.qos_policy.id,
302+
**{'max_kbps': self.new_rule.max_kbps,
303+
'direction': self.new_rule.direction}
304+
)
305+
self.assertEqual(self.columns, columns)
306+
self.assertEqual(expected_data, data)
307+
308+
def test_create_all_options(self):
266309
arglist = [
267310
'--type', RULE_TYPE_BANDWIDTH_LIMIT,
268311
'--max-kbps', str(self.new_rule.max_kbps),
@@ -309,7 +352,7 @@ def test_create_wrong_options(self):
309352
self.cmd.take_action(parsed_args)
310353
except exceptions.CommandError as e:
311354
msg = ('"Create" rule command for type "bandwidth-limit" '
312-
'requires arguments max_burst_kbps, max_kbps')
355+
'requires arguments: max_kbps')
313356
self.assertEqual(msg, str(e))
314357

315358

@@ -579,7 +622,7 @@ def test_set_wrong_options(self):
579622
self.cmd.take_action(parsed_args)
580623
except exceptions.CommandError as e:
581624
msg = ('Failed to set Network QoS rule ID "%(rule)s": Rule type '
582-
'"minimum-bandwidth" only requires arguments direction, '
625+
'"minimum-bandwidth" only requires arguments: direction, '
583626
'min_kbps' % {'rule': self.new_rule.id})
584627
self.assertEqual(msg, str(e))
585628

@@ -673,7 +716,7 @@ def test_set_wrong_options(self):
673716
self.cmd.take_action(parsed_args)
674717
except exceptions.CommandError as e:
675718
msg = ('Failed to set Network QoS rule ID "%(rule)s": Rule type '
676-
'"dscp-marking" only requires arguments dscp_mark' %
719+
'"dscp-marking" only requires arguments: dscp_mark' %
677720
{'rule': self.new_rule.id})
678721
self.assertEqual(msg, str(e))
679722

@@ -837,7 +880,7 @@ def test_set_wrong_options(self):
837880
self.cmd.take_action(parsed_args)
838881
except exceptions.CommandError as e:
839882
msg = ('Failed to set Network QoS rule ID "%(rule)s": Rule type '
840-
'"bandwidth-limit" only requires arguments direction, '
883+
'"bandwidth-limit" only requires arguments: direction, '
841884
'max_burst_kbps, max_kbps' % {'rule': self.new_rule.id})
842885
self.assertEqual(msg, str(e))
843886

0 commit comments

Comments
 (0)