diff --git a/vmware_nsx/services/qos/nsx_v/utils.py b/vmware_nsx/services/qos/nsx_v/utils.py index 4981940424..7ef6219ba6 100644 --- a/vmware_nsx/services/qos/nsx_v/utils.py +++ b/vmware_nsx/services/qos/nsx_v/utils.py @@ -18,8 +18,8 @@ from neutron.api.rpc.callbacks import events as callbacks_events from neutron import context as n_context from neutron import manager from neutron.objects.qos import policy as qos_policy -from neutron.objects.qos import rule as rule_object from neutron.plugins.common import constants +from neutron.services.qos import qos_consts from oslo_log import log as logging @@ -63,11 +63,14 @@ class NsxVQosRule(object): # read the neutron policy restrictions if qos_policy_id is not None: plugin = self._get_qos_plugin() - rules_obj = plugin.get_policies( - context, qos_policy_id) - if rules_obj is not None and len(rules_obj) > 0: - for rule_obj in rules_obj: - if isinstance(rule_obj, rule_object.QosBandwidthLimitRule): + policy_obj = plugin.get_policy(context, qos_policy_id) + if 'rules' in policy_obj and len(policy_obj['rules']) > 0: + for rule_obj in policy_obj['rules']: + # TODO(asarfaty): for now we support one rule of each type + # This code should be fixed in order to support rules of + # different directions + if (rule_obj['type'] == + qos_consts.RULE_TYPE_BANDWIDTH_LIMIT): self.bandwidthEnabled = True # averageBandwidth: kbps (neutron) -> bps (nsxv) self.averageBandwidth = rule_obj['max_kbps'] * 1024 @@ -77,7 +80,7 @@ class NsxVQosRule(object): self.peakBandwidth = self.averageBandwidth # burstSize: kbps (neutron) -> Bytes (nsxv) self.burstSize = rule_obj['max_burst_kbps'] * 128 - elif isinstance(rule_obj, rule_object.QosDscpMarkingRule): + if rule_obj['type'] == qos_consts.RULE_TYPE_DSCP_MARK: self.dscpMarkEnabled = True self.dscpMarkValue = rule_obj['dscp_mark'] diff --git a/vmware_nsx/tests/unit/services/qos/test_nsxv_notification.py b/vmware_nsx/tests/unit/services/qos/test_nsxv_notification.py index 78869dcb4c..6fb79b6ecd 100644 --- a/vmware_nsx/tests/unit/services/qos/test_nsxv_notification.py +++ b/vmware_nsx/tests/unit/services/qos/test_nsxv_notification.py @@ -21,6 +21,7 @@ from neutron import context from neutron import manager from neutron.objects.qos import policy as policy_object from neutron.objects.qos import rule as rule_object +from neutron.services.qos import qos_consts from neutron.services.qos import qos_plugin from neutron.tests.unit.services.qos import base @@ -69,12 +70,16 @@ class TestQosNsxVNotification(test_plugin.NsxVPluginV2TestCase, 'shared': True}} self.rule_data = { - 'bandwidth_limit_rule': {'id': uuidutils.generate_uuid(), - 'max_kbps': 100, - 'max_burst_kbps': 150}} + 'bandwidth_limit_rule': { + 'id': uuidutils.generate_uuid(), + 'max_kbps': 100, + 'max_burst_kbps': 150, + 'type': qos_consts.RULE_TYPE_BANDWIDTH_LIMIT}} self.dscp_rule_data = { - 'dscp_marking_rule': {'id': uuidutils.generate_uuid(), - 'dscp_mark': 22}} + 'dscp_marking_rule': { + 'id': uuidutils.generate_uuid(), + 'dscp_mark': 22, + 'type': qos_consts.RULE_TYPE_DSCP_MARK}} self.policy = policy_object.QosPolicy( self.ctxt, **self.policy_data['policy']) @@ -129,8 +134,8 @@ class TestQosNsxVNotification(test_plugin.NsxVPluginV2TestCase, setattr(_policy, "rules", [self.rule, self.dscp_rule]) with mock.patch('neutron.services.qos.qos_plugin.QoSPlugin.' - 'get_policies', - return_value=self._rules) as get_rules_mock: + 'get_policy', + return_value=_policy) as get_rules_mock: # create the network to use this policy net = self._create_net() @@ -156,8 +161,8 @@ class TestQosNsxVNotification(test_plugin.NsxVPluginV2TestCase, setattr(_policy, "rules", [self.rule]) with mock.patch('neutron.services.qos.qos_plugin.QoSPlugin.' - 'get_policies', - return_value=self._rules) as get_rules_mock: + 'get_policy', + return_value=_policy) as get_rules_mock: with mock.patch('neutron.objects.qos.policy.' 'QosPolicy.get_object', return_value=_policy): @@ -213,8 +218,8 @@ class TestQosNsxVNotification(test_plugin.NsxVPluginV2TestCase, setattr(_policy, "rules", [self.dscp_rule]) plugin = self.qos_plugin with mock.patch('neutron.services.qos.qos_plugin.QoSPlugin.' - 'get_policies', - return_value=self._dscp_rules) as rules_mock: + 'get_policy', + return_value=_policy) as rules_mock: with mock.patch('neutron.objects.qos.policy.' 'QosPolicy.get_object', return_value=_policy):