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 c5a8a1d0..fdfec45a 100644 --- a/vmware_nsxlib/tests/unit/v3/test_qos_switching_profile.py +++ b/vmware_nsxlib/tests/unit/v3/test_qos_switching_profile.py @@ -48,8 +48,10 @@ class NsxLibQosTestCase(nsxlib_testcase.NsxClientTestCase): average_bandwidth=None, description=test_constants.FAKE_NAME, qos_marking=None, - dscp=0, direction=nsx_constants.EGRESS): - body = copy.deepcopy(test_constants.FAKE_QOS_PROFILE) + dscp=0, direction=nsx_constants.EGRESS, + body=None): + if body is None: + body = copy.deepcopy(test_constants.FAKE_QOS_PROFILE) body["display_name"] = test_constants.FAKE_NAME body["description"] = description @@ -221,3 +223,58 @@ class NsxLibQosTestCase(nsxlib_testcase.NsxClientTestCase): delete.assert_called_with( 'switching-profiles/%s' % test_constants.FAKE_QOS_PROFILE['id']) + + def test_qos_switching_profile_set_shaping(self): + """Test updating a qos-switching profile + + returns the correct response + """ + egress_peak_bandwidth = 200 + egress_average_bandwidth = 300 + egress_burst_size = 500 + ingress_peak_bandwidth = 100 + ingress_average_bandwidth = 400 + ingress_burst_size = 600 + qos_marking = "untrusted" + dscp = 10 + + original_profile = self._body_with_shaping() + with mock.patch.object(self.nsxlib.client, 'get', + return_value=original_profile): + with mock.patch.object(self.nsxlib.client, 'update') as update: + # update the bw shaping of the profile + self.nsxlib.qos_switching_profile.set_profile_shaping( + test_constants.FAKE_QOS_PROFILE['id'], + ingress_bw_enabled=True, + ingress_burst_size=ingress_burst_size, + ingress_peak_bandwidth=ingress_peak_bandwidth, + ingress_average_bandwidth=ingress_average_bandwidth, + egress_bw_enabled=True, + egress_burst_size=egress_burst_size, + egress_peak_bandwidth=egress_peak_bandwidth, + egress_average_bandwidth=egress_average_bandwidth, + qos_marking=qos_marking, + dscp=dscp) + + actual_body = copy.deepcopy(update.call_args[0][1]) + actual_path = update.call_args[0][0] + expected_path = ('switching-profiles/%s' % + test_constants.FAKE_QOS_PROFILE['id']) + expected_body = self._body_with_shaping( + shaping_enabled=True, + burst_size=egress_burst_size, + peak_bandwidth=egress_peak_bandwidth, + average_bandwidth=egress_average_bandwidth, + qos_marking="untrusted", dscp=10, + direction=nsx_constants.EGRESS) + # Add the other direction to the body + expected_body = self._body_with_shaping( + shaping_enabled=True, + burst_size=ingress_burst_size, + peak_bandwidth=ingress_peak_bandwidth, + average_bandwidth=ingress_average_bandwidth, + direction=nsx_constants.INGRESS, + body=expected_body) + + self.assertEqual(expected_path, actual_path) + self.assertEqual(expected_body, actual_body) diff --git a/vmware_nsxlib/v3/core_resources.py b/vmware_nsxlib/v3/core_resources.py index 6594685a..18625644 100644 --- a/vmware_nsxlib/v3/core_resources.py +++ b/vmware_nsxlib/v3/core_resources.py @@ -16,6 +16,7 @@ import collections from oslo_log import log +from oslo_log import versionutils from vmware_nsxlib._i18n import _ from vmware_nsxlib.v3 import exceptions @@ -349,11 +350,12 @@ class NsxLibQosSwitchingProfile(NsxLibSwitchingProfile): return self.client.create(self.get_path(), body) def update(self, profile_id, tags, name=None, description=None): - # TODO(asarfaty): tags are never used here # get the current configuration body = self.get(profile_id) # update the relevant fields body = self._update_args(body, name, description) + if tags is not None: + body['tags'] = tags return self._update_resource_with_retry( self.get_path(profile_id), body) @@ -364,6 +366,10 @@ class NsxLibQosSwitchingProfile(NsxLibSwitchingProfile): average_bandwidth=None, qos_marking=None, dscp=None, direction=nsx_constants.INGRESS): + versionutils.report_deprecated_feature( + LOG, + 'NsxLibQosSwitchingProfile.update_shaping is deprecated. ' + 'Please use set_profile_shaping instead.') # get the current configuration body = self.get(profile_id) # update the relevant fields @@ -379,6 +385,49 @@ class NsxLibQosSwitchingProfile(NsxLibSwitchingProfile): return self._update_resource_with_retry( self.get_path(profile_id), body) + def set_profile_shaping(self, profile_id, + ingress_bw_enabled=False, + ingress_burst_size=None, + ingress_peak_bandwidth=None, + ingress_average_bandwidth=None, + egress_bw_enabled=False, + egress_burst_size=None, + egress_peak_bandwidth=None, + egress_average_bandwidth=None, + qos_marking='trusted', dscp=None): + """Set all shaping parameters in the QoS switch profile""" + # get the current configuration + body = self.get(profile_id) + + # update the ingress shaping + if ingress_bw_enabled: + body = self._enable_shaping_in_args( + body, burst_size=ingress_burst_size, + peak_bandwidth=ingress_peak_bandwidth, + average_bandwidth=ingress_average_bandwidth, + direction=nsx_constants.INGRESS) + else: + body = self._disable_shaping_in_args( + body, direction=nsx_constants.INGRESS) + + # update the egress shaping + if egress_bw_enabled: + body = self._enable_shaping_in_args( + body, burst_size=egress_burst_size, + peak_bandwidth=egress_peak_bandwidth, + average_bandwidth=egress_average_bandwidth, + direction=nsx_constants.EGRESS) + else: + body = self._disable_shaping_in_args( + body, direction=nsx_constants.EGRESS) + + # update dscp marking + body = self._update_dscp_in_args(body, qos_marking, dscp) + + # update the profile in the backend + return self._update_resource_with_retry( + self.get_path(profile_id), body) + class NsxLibLogicalRouter(utils.NsxLibApiBase):