From af2e56d86caad9b72c55dbc4248c63d9db7bb8e0 Mon Sep 17 00:00:00 2001 From: Miguel Angel Ajo Date: Mon, 10 Aug 2015 15:32:57 +0200 Subject: [PATCH] Functional test for QoS policy bandwidth rule update Creates a port in a policy, and subsequently modifies the bandwidth limit rule in the policy, then verifies that the new limits are assigned to the port. Change-Id: I23fe45ef08618ad91567feb1707028e0a0bfe0d6 Partially-Implements: ml2-qos --- neutron/tests/base.py | 2 ++ neutron/tests/common/agents/l2_extensions.py | 26 +++++++++++++++ .../test_ovs_agent_qos_extension.py | 32 +++++++++++++++---- 3 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 neutron/tests/common/agents/l2_extensions.py diff --git a/neutron/tests/base.py b/neutron/tests/base.py index 476f6464ab5..d89be686bf5 100644 --- a/neutron/tests/base.py +++ b/neutron/tests/base.py @@ -35,6 +35,7 @@ import six import testtools from neutron.agent.linux import external_process +from neutron.api.rpc.callbacks.consumer import registry as rpc_consumer_reg from neutron.callbacks import manager as registry_manager from neutron.callbacks import registry from neutron.common import config @@ -290,6 +291,7 @@ class BaseTestCase(DietTestCase): policy.init() self.addCleanup(policy.reset) + self.addCleanup(rpc_consumer_reg.clear) def get_new_temp_dir(self): """Create a new temporary directory. diff --git a/neutron/tests/common/agents/l2_extensions.py b/neutron/tests/common/agents/l2_extensions.py new file mode 100644 index 00000000000..39ae0bdd741 --- /dev/null +++ b/neutron/tests/common/agents/l2_extensions.py @@ -0,0 +1,26 @@ +# Copyright (c) 2015 Red Hat, Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from neutron.agent.linux import utils as agent_utils + + +def wait_until_bandwidth_limit_rule_applied(bridge, port_vif, rule): + def _bandwidth_limit_rule_applied(): + max_rate, burst = ( + bridge.get_qos_bw_limit_for_port(port_vif)) + return (max_rate == rule.max_kbps and + burst == rule.max_burst_kbps) + + agent_utils.wait_until_true(_bandwidth_limit_rule_applied) diff --git a/neutron/tests/functional/agent/l2/extensions/test_ovs_agent_qos_extension.py b/neutron/tests/functional/agent/l2/extensions/test_ovs_agent_qos_extension.py index af6f450c24b..32c13be61e4 100644 --- a/neutron/tests/functional/agent/l2/extensions/test_ovs_agent_qos_extension.py +++ b/neutron/tests/functional/agent/l2/extensions/test_ovs_agent_qos_extension.py @@ -13,12 +13,17 @@ # License for the specific language governing permissions and limitations # under the License. -import mock +import copy +import mock from oslo_utils import uuidutils +from neutron.api.rpc.callbacks.consumer import registry as consumer_reg +from neutron.api.rpc.callbacks import events +from neutron.api.rpc.callbacks import resources from neutron.objects.qos import policy from neutron.objects.qos import rule +from neutron.tests.common.agents import l2_extensions from neutron.tests.functional.agent.l2 import base @@ -41,6 +46,8 @@ class OVSAgentQoSExtensionTestFramework(base.OVSAgentTestFramework): super(OVSAgentQoSExtensionTestFramework, self).setUp() self.config.set_override('extensions', ['qos'], 'agent') self._set_pull_mock() + self.set_test_qos_rules(TEST_POLICY_ID1, [TEST_BW_LIMIT_RULE_1]) + self.set_test_qos_rules(TEST_POLICY_ID2, [TEST_BW_LIMIT_RULE_2]) def _set_pull_mock(self): @@ -93,14 +100,16 @@ class OVSAgentQoSExtensionTestFramework(base.OVSAgentTestFramework): self.assertIsNone(max_rate) self.assertIsNone(burst) + def wait_until_bandwidth_limit_rule_applied(self, port, rule): + l2_extensions.wait_until_bandwidth_limit_rule_applied( + self.agent.int_br, port['vif_name'], rule) + class TestOVSAgentQosExtension(OVSAgentQoSExtensionTestFramework): def test_port_creation_with_bandwidth_limit(self): """Make sure bandwidth limit rules are set in low level to ports.""" - self.set_test_qos_rules(TEST_POLICY_ID1, [TEST_BW_LIMIT_RULE_1]) - self.setup_agent_and_ports( port_dicts=self.create_test_ports(amount=1, policy_id=TEST_POLICY_ID1)) @@ -113,9 +122,6 @@ class TestOVSAgentQosExtension(OVSAgentQoSExtensionTestFramework): def test_port_creation_with_different_bandwidth_limits(self): """Make sure different types of policies end on the right ports.""" - self.set_test_qos_rules(TEST_POLICY_ID1, [TEST_BW_LIMIT_RULE_1]) - self.set_test_qos_rules(TEST_POLICY_ID2, [TEST_BW_LIMIT_RULE_2]) - port_dicts = self.create_test_ports(amount=3) port_dicts[0]['qos_policy_id'] = TEST_POLICY_ID1 @@ -131,3 +137,17 @@ class TestOVSAgentQosExtension(OVSAgentQoSExtensionTestFramework): TEST_BW_LIMIT_RULE_2) self._assert_bandwidth_limit_rule_not_set(self.ports[2]) + + def test_simple_port_policy_update(self): + self.setup_agent_and_ports( + port_dicts=self.create_test_ports(amount=1, + policy_id=TEST_POLICY_ID1)) + self.wait_until_ports_state(self.ports, up=True) + policy_copy = copy.deepcopy(self.qos_policies[TEST_POLICY_ID1]) + policy_copy.rules[0].max_kbps = 500 + policy_copy.rules[0].max_burst_kbps = 5 + consumer_reg.push(resources.QOS_POLICY, policy_copy, events.UPDATED) + self.wait_until_bandwidth_limit_rule_applied(self.ports[0], + policy_copy.rules[0]) + self._assert_bandwidth_limit_rule_is_set(self.ports[0], + policy_copy.rules[0])