From 5a52317eac230d8680f491e495db1af15423ea80 Mon Sep 17 00:00:00 2001 From: Adit Sarfaty Date: Sun, 26 Aug 2018 12:07:54 +0300 Subject: [PATCH] NSX|V3: Fail on unsupported QoS rules The NSX plugin does not support minimum BW rules. This patch fails validation to prevent the creation of such rules. Change-Id: I293dd5b6c659855bb939912370d72cdfd228a338 --- vmware_nsx/services/qos/nsx_v3/utils.py | 12 ++++++++- .../services/qos/test_nsxv3_notification.py | 25 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/vmware_nsx/services/qos/nsx_v3/utils.py b/vmware_nsx/services/qos/nsx_v3/utils.py index 9d13bdd5ba..76f1b6d9d3 100644 --- a/vmware_nsx/services/qos/nsx_v3/utils.py +++ b/vmware_nsx/services/qos/nsx_v3/utils.py @@ -175,8 +175,11 @@ class QosNotificationsHandler(object): egress_bw_rule = rule else: ingress_bw_rule = rule - else: + elif rule.rule_type == qos_consts.RULE_TYPE_DSCP_MARKING: dscp_rule = rule + else: + LOG.warning("The NSX-V3 plugin does not support QoS rule of " + "type %s", rule.rule_type) # the NSX direction is opposite to the neutron direction (ingress_bw_enabled, ingress_burst_size, ingress_peak_bw, @@ -203,3 +206,10 @@ class QosNotificationsHandler(object): """Raise an exception if the rule values are not supported""" if rule.rule_type == qos_consts.RULE_TYPE_BANDWIDTH_LIMIT: self._validate_bw_values(rule) + elif rule.rule_type == qos_consts.RULE_TYPE_DSCP_MARKING: + pass + else: + msg = (_("The NSX-V3 plugin does not support QoS rule of type " + "%s") % rule.rule_type) + LOG.error(msg) + raise n_exc.InvalidInput(error_message=msg) diff --git a/vmware_nsx/tests/unit/services/qos/test_nsxv3_notification.py b/vmware_nsx/tests/unit/services/qos/test_nsxv3_notification.py index a8787f827f..bb4e969f14 100644 --- a/vmware_nsx/tests/unit/services/qos/test_nsxv3_notification.py +++ b/vmware_nsx/tests/unit/services/qos/test_nsxv3_notification.py @@ -305,6 +305,7 @@ class TestQosNsxV3Notification(base.BaseQosTestCase, dscp_mark = rule_dict['dscp_mark'] update_profile.assert_called_once_with( self.fake_profile_id, + ingress_bw_enabled=False, ingress_burst_size=None, ingress_peak_bandwidth=None, @@ -317,6 +318,30 @@ class TestQosNsxV3Notification(base.BaseQosTestCase, qos_marking='untrusted' ) + @mock.patch.object(QoSPolicyObject, '_reload_rules') + def test_minimum_bw_rule_create_profile(self, *mocks): + # Minimum BW rules are not supported + policy = QoSPolicyObject( + self.ctxt, **self.policy_data['policy']) + min_bw_rule_data = { + 'minimum_bandwidth_rule': {'id': uuidutils.generate_uuid(), + 'min_kbps': 10, + 'direction': 'egress'}} + min_bw_rule = obj_reg.new_instance( + 'QosMinimumBandwidthRule', self.ctxt, + **min_bw_rule_data['minimum_bandwidth_rule']) + # add a rule to the policy + setattr(policy, "rules", [min_bw_rule]) + with mock.patch('neutron.objects.qos.policy.QosPolicy.get_object', + return_value=policy),\ + mock.patch('neutron.objects.db.api.' + 'update_object', return_value=self.dscp_rule_data): + self.assertRaises( + exceptions.DriverCallError, + self.qos_plugin.update_policy_minimum_bandwidth_rule, + self.ctxt, min_bw_rule.id, + policy.id, min_bw_rule_data) + def test_rule_delete_profile(self): # test the switch profile update when a QoS rule is deleted _policy = QoSPolicyObject(