Skip to content

Commit 4b2355b

Browse files
author
Rodolfo Alonso Hernandez
committed
Fix Network QoS rule CLI attrs parsing
Allows to set zero values in the CLI parameters for Network QoS rule. Change-Id: Ie0e045ff4888615d68804fd739d5b995ca11e9a1 Closes-Bug: #1655947
1 parent c8c29e8 commit 4b2355b

2 files changed

Lines changed: 56 additions & 4 deletions

File tree

openstackclient/network/v2/network_qos_rule.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,16 @@ def _get_attrs(network_client, parsed_args, is_create=False):
8585
msg = _('"Create" rule command requires argument "type"')
8686
raise exceptions.CommandError(msg)
8787
rule_type = parsed_args.type
88-
if parsed_args.max_kbps:
88+
if parsed_args.max_kbps is not None:
8989
attrs['max_kbps'] = parsed_args.max_kbps
90-
if parsed_args.max_burst_kbits:
90+
if parsed_args.max_burst_kbits is not None:
9191
# NOTE(ralonsoh): this parameter must be changed in SDK and then in
9292
# Neutron API, from 'max_burst_kbps' to
9393
# 'max_burst_kbits'
9494
attrs['max_burst_kbps'] = parsed_args.max_burst_kbits
95-
if parsed_args.dscp_mark:
95+
if parsed_args.dscp_mark is not None:
9696
attrs['dscp_mark'] = parsed_args.dscp_mark
97-
if parsed_args.min_kbps:
97+
if parsed_args.min_kbps is not None:
9898
attrs['min_kbps'] = parsed_args.min_kbps
9999
if parsed_args.ingress:
100100
attrs['direction'] = 'ingress'

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

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,16 @@ def test_set_nothing(self):
523523
self.assertIsNone(result)
524524

525525
def test_set_min_kbps(self):
526+
self._set_min_kbps()
527+
528+
def test_set_min_kbps_to_zero(self):
529+
self._set_min_kbps(min_kbps=0)
530+
531+
def _set_min_kbps(self, min_kbps=None):
532+
if min_kbps:
533+
previous_min_kbps = self.new_rule.min_kbps
534+
self.new_rule.min_kbps = min_kbps
535+
526536
arglist = [
527537
'--min-kbps', str(self.new_rule.min_kbps),
528538
self.new_rule.qos_policy_id,
@@ -544,6 +554,9 @@ def test_set_min_kbps(self):
544554
self.new_rule, self.qos_policy.id, **attrs)
545555
self.assertIsNone(result)
546556

557+
if min_kbps:
558+
self.new_rule.min_kbps = previous_min_kbps
559+
547560
def test_set_wrong_options(self):
548561
arglist = [
549562
'--max-kbps', str(10000),
@@ -604,6 +617,16 @@ def test_set_nothing(self):
604617
self.assertIsNone(result)
605618

606619
def test_set_dscp_mark(self):
620+
self._set_dscp_mark()
621+
622+
def test_set_dscp_mark_to_zero(self):
623+
self._set_dscp_mark(dscp_mark=0)
624+
625+
def _set_dscp_mark(self, dscp_mark=None):
626+
if dscp_mark:
627+
previous_dscp_mark = self.new_rule.dscp_mark
628+
self.new_rule.dscp_mark = dscp_mark
629+
607630
arglist = [
608631
'--dscp-mark', str(self.new_rule.dscp_mark),
609632
self.new_rule.qos_policy_id,
@@ -625,6 +648,9 @@ def test_set_dscp_mark(self):
625648
self.new_rule, self.qos_policy.id, **attrs)
626649
self.assertIsNone(result)
627650

651+
if dscp_mark:
652+
self.new_rule.dscp_mark = previous_dscp_mark
653+
628654
def test_set_wrong_options(self):
629655
arglist = [
630656
'--max-kbps', str(10000),
@@ -685,6 +711,16 @@ def test_set_nothing(self):
685711
self.assertIsNone(result)
686712

687713
def test_set_max_kbps(self):
714+
self._set_max_kbps()
715+
716+
def test_set_max_kbps_to_zero(self):
717+
self._set_max_kbps(max_kbps=0)
718+
719+
def _set_max_kbps(self, max_kbps=None):
720+
if max_kbps:
721+
previous_max_kbps = self.new_rule.max_kbps
722+
self.new_rule.max_kbps = max_kbps
723+
688724
arglist = [
689725
'--max-kbps', str(self.new_rule.max_kbps),
690726
self.new_rule.qos_policy_id,
@@ -706,7 +742,20 @@ def test_set_max_kbps(self):
706742
self.new_rule, self.qos_policy.id, **attrs)
707743
self.assertIsNone(result)
708744

745+
if max_kbps:
746+
self.new_rule.max_kbps = previous_max_kbps
747+
709748
def test_set_max_burst_kbits(self):
749+
self._set_max_burst_kbits()
750+
751+
def test_set_max_burst_kbits_to_zero(self):
752+
self._set_max_burst_kbits(max_burst_kbits=0)
753+
754+
def _set_max_burst_kbits(self, max_burst_kbits=None):
755+
if max_burst_kbits:
756+
previous_max_burst_kbits = self.new_rule.max_burst_kbits
757+
self.new_rule.max_burst_kbits = max_burst_kbits
758+
710759
arglist = [
711760
'--max-burst-kbits', str(self.new_rule.max_burst_kbits),
712761
self.new_rule.qos_policy_id,
@@ -728,6 +777,9 @@ def test_set_max_burst_kbits(self):
728777
self.new_rule, self.qos_policy.id, **attrs)
729778
self.assertIsNone(result)
730779

780+
if max_burst_kbits:
781+
self.new_rule.max_burst_kbits = previous_max_burst_kbits
782+
731783
def test_set_wrong_options(self):
732784
arglist = [
733785
'--min-kbps', str(10000),

0 commit comments

Comments
 (0)