diff --git a/neutron/objects/qos/rule.py b/neutron/objects/qos/rule.py index e163f0e3e8c..d2434322ec0 100644 --- a/neutron/objects/qos/rule.py +++ b/neutron/objects/qos/rule.py @@ -80,12 +80,17 @@ class QosRule(base.NeutronDbObject): this method, or we could make it abstract to allow different rule behaviour. """ - is_network_rule = self.qos_policy_id != port[qos_consts.QOS_POLICY_ID] + is_port_policy = self.qos_policy_id == port[qos_consts.QOS_POLICY_ID] + is_network_policy_only = port[qos_consts.QOS_POLICY_ID] is None is_network_device_port = any(port['device_owner'].startswith(prefix) for prefix in constants.DEVICE_OWNER_PREFIXES) - - return not (is_network_rule and is_network_device_port) + # NOTE(ralonsoh): return True if: + # - Is a port QoS policy (not a network QoS policy) + # - Is not a network device (e.g. router) and is a network QoS + # policy and there is no port QoS policy + return (is_port_policy or + (not is_network_device_port and is_network_policy_only)) @obj_base.VersionedObjectRegistry.register diff --git a/neutron/tests/unit/objects/qos/test_rule.py b/neutron/tests/unit/objects/qos/test_rule.py index fccddff4929..eeaba771164 100644 --- a/neutron/tests/unit/objects/qos/test_rule.py +++ b/neutron/tests/unit/objects/qos/test_rule.py @@ -42,6 +42,13 @@ class QosRuleObjectTestCase(neutron_test_base.BaseTestCase): device_owner=constants.DEVICE_OWNER_ROUTER_INTF, expected_result=False) + def test_should_apply_to_port_with_network_port_and_only_net_policy(self): + self._test_should_apply_to_port( + rule_policy_id=POLICY_ID_B, + port_policy_id=None, + device_owner=constants.DEVICE_OWNER_ROUTER_INTF, + expected_result=False) + def test_should_apply_to_port_with_network_port_and_port_policy(self): self._test_should_apply_to_port( rule_policy_id=POLICY_ID_A, @@ -50,10 +57,19 @@ class QosRuleObjectTestCase(neutron_test_base.BaseTestCase): expected_result=True) def test_should_apply_to_port_with_compute_port_and_net_policy(self): + # NOTE(ralonsoh): in this case the port has a port QoS policy; the + # network QoS policy can't be applied. self._test_should_apply_to_port( rule_policy_id=POLICY_ID_B, port_policy_id=POLICY_ID_A, device_owner=DEVICE_OWNER_COMPUTE, + expected_result=False) + + def test_should_apply_to_port_with_compute_port_and_only_net_policy(self): + self._test_should_apply_to_port( + rule_policy_id=POLICY_ID_B, + port_policy_id=None, + device_owner=DEVICE_OWNER_COMPUTE, expected_result=True) def test_should_apply_to_port_with_compute_port_and_port_policy(self): diff --git a/neutron/tests/unit/plugins/ml2/drivers/mech_sriov/agent/extension_drivers/test_qos_driver.py b/neutron/tests/unit/plugins/ml2/drivers/mech_sriov/agent/extension_drivers/test_qos_driver.py index a86f8b3ee65..1a3d8ed0f90 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/mech_sriov/agent/extension_drivers/test_qos_driver.py +++ b/neutron/tests/unit/plugins/ml2/drivers/mech_sriov/agent/extension_drivers/test_qos_driver.py @@ -54,6 +54,7 @@ class QosSRIOVAgentDriverTestCase(base.BaseTestCase): self.qos_policy_min_tx_rate = self._create_qos_policy_obj( [self.rule_min_tx_rate]) self.port = self._create_fake_port(self.qos_policy.id) + self.port_min = self._create_fake_port(self.qos_policy_min_tx_rate.id) def _create_bw_limit_rule_obj(self): rule_obj = rule.QosBandwidthLimitRule() @@ -124,21 +125,21 @@ class QosSRIOVAgentDriverTestCase(base.BaseTestCase): self.assertFalse(self.max_rate_mock.called) def test_create_minimum_bandwidth(self): - self.qos_driver.create(self.port, self.qos_policy_min_tx_rate) + self.qos_driver.create(self.port_min, self.qos_policy_min_tx_rate) self.min_tx_rate_mock.assert_called_once_with( self.ASSIGNED_MAC, self.PCI_SLOT, self.rule_min_tx_rate.min_kbps) def test_update_minimum_bandwidth(self): - self.qos_driver.update(self.port, self.qos_policy_min_tx_rate) + self.qos_driver.update(self.port_min, self.qos_policy_min_tx_rate) self.min_tx_rate_mock.assert_called_once_with( self.ASSIGNED_MAC, self.PCI_SLOT, self.rule_min_tx_rate.min_kbps) def test_delete_minimum_bandwidth_on_assigned_vf(self): - self.qos_driver.delete(self.port, self.qos_policy_min_tx_rate) + self.qos_driver.delete(self.port_min, self.qos_policy_min_tx_rate) self.min_tx_rate_mock.assert_called_once_with( self.ASSIGNED_MAC, self.PCI_SLOT, 0) def test_delete_minimum_bandwidth_on_released_vf(self): - del self.port['device_owner'] - self.qos_driver.delete(self.port, self.qos_policy_min_tx_rate) + del self.port_min['device_owner'] + self.qos_driver.delete(self.port_min, self.qos_policy_min_tx_rate) self.clear_min_tx_rate_mock.assert_called_once_with(self.PCI_SLOT)