From 1e760fe4f56ce89fd96a58784ee5c5f54ab3aa5b Mon Sep 17 00:00:00 2001 From: Adit Sarfaty Date: Mon, 16 Jan 2017 10:53:48 +0200 Subject: [PATCH] Allow setting QoS shaper values to 0 Change-Id: I751fcb61adf0a18a82c961a6fede4656b2643660 --- .../unit/v3/test_qos_switching_profile.py | 26 ++++++++++++++----- vmware_nsxlib/v3/__init__.py | 6 ++--- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/vmware_nsxlib/tests/unit/v3/test_qos_switching_profile.py b/vmware_nsxlib/tests/unit/v3/test_qos_switching_profile.py index 9d805244..c5a8a1d0 100644 --- a/vmware_nsxlib/tests/unit/v3/test_qos_switching_profile.py +++ b/vmware_nsxlib/tests/unit/v3/test_qos_switching_profile.py @@ -108,14 +108,14 @@ class NsxLibQosTestCase(nsxlib_testcase.NsxClientTestCase): self._body(description=new_description)) def _enable_qos_switching_profile_shaping( - self, direction=nsx_constants.EGRESS): + self, direction=nsx_constants.EGRESS, new_burst_size=100): """Test updating a qos-switching profile returns the correct response """ - - original_profile = self._body_with_shaping(direction=direction) - burst_size = 100 + original_burst = 10 + original_profile = self._body_with_shaping(direction=direction, + burst_size=original_burst) peak_bandwidth = 200 average_bandwidth = 300 qos_marking = "untrusted" @@ -128,7 +128,7 @@ class NsxLibQosTestCase(nsxlib_testcase.NsxClientTestCase): self.nsxlib.qos_switching_profile.update_shaping( test_constants.FAKE_QOS_PROFILE['id'], shaping_enabled=True, - burst_size=burst_size, + burst_size=new_burst_size, peak_bandwidth=peak_bandwidth, average_bandwidth=average_bandwidth, qos_marking=qos_marking, @@ -138,9 +138,11 @@ class NsxLibQosTestCase(nsxlib_testcase.NsxClientTestCase): actual_path = update.call_args[0][0] expected_path = ('switching-profiles/%s' % test_constants.FAKE_QOS_PROFILE['id']) + expected_burst = (new_burst_size if new_burst_size is not None + else original_burst) expected_body = self._body_with_shaping( shaping_enabled=True, - burst_size=burst_size, + burst_size=expected_burst, peak_bandwidth=peak_bandwidth, average_bandwidth=average_bandwidth, qos_marking="untrusted", dscp=10, @@ -156,6 +158,18 @@ class NsxLibQosTestCase(nsxlib_testcase.NsxClientTestCase): self._enable_qos_switching_profile_shaping( direction=nsx_constants.INGRESS) + def test_update_qos_switching_profile_with_burst_size(self): + self._enable_qos_switching_profile_shaping( + direction=nsx_constants.EGRESS, new_burst_size=101) + + def test_update_qos_switching_profile_without_burst_size(self): + self._enable_qos_switching_profile_shaping( + direction=nsx_constants.EGRESS, new_burst_size=None) + + def test_update_qos_switching_profile_zero_burst_size(self): + self._enable_qos_switching_profile_shaping( + direction=nsx_constants.EGRESS, new_burst_size=0) + def _disable_qos_switching_profile_shaping( self, direction=nsx_constants.EGRESS): """Test updating a qos-switching profile. diff --git a/vmware_nsxlib/v3/__init__.py b/vmware_nsxlib/v3/__init__.py index 5c68e69d..b50fa623 100644 --- a/vmware_nsxlib/v3/__init__.py +++ b/vmware_nsxlib/v3/__init__.py @@ -247,11 +247,11 @@ class NsxLibQosSwitchingProfile(utils.NsxLibApiBase): for shaper in body["shaper_configuration"]: if shaper["resource_type"] == resource_type: shaper["enabled"] = True - if burst_size: + if burst_size is not None: shaper["burst_size_bytes"] = burst_size - if peak_bandwidth: + if peak_bandwidth is not None: shaper["peak_bandwidth_mbps"] = peak_bandwidth - if average_bandwidth: + if average_bandwidth is not None: shaper["average_bandwidth_mbps"] = average_bandwidth break