Extend QosSwitchingProfile actions
1. Support updating of shaping in both direction in the same call 2. Deprecate the old api for update shaping 3. Allow updating the profile tags Change-Id: I34ae54b7c4b5810694e4ea05265421c8e4c903d8
This commit is contained in:
parent
b11a5c0b15
commit
061b03dbbd
@ -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)
|
||||
|
@ -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):
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user