From: Ihar Hrachyshka Date: Fri, 24 Jul 2015 15:31:50 +0000 (+0200) Subject: ml2: added qos_profile_id to get_device_details payload X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=301ffb02ecccdddfee361ee6738b7ff84d7cc0d8;p=openstack-build%2Fneutron-build.git ml2: added qos_profile_id to get_device_details payload This is needed to make l2 agent qos extension determine which rules to apply to the port, if any. Partially-Implements: blueprint quantum-qos-api Change-Id: Idefa819f9a21cf53762b1fb923dafb63f2b256e0 --- diff --git a/neutron/plugins/ml2/rpc.py b/neutron/plugins/ml2/rpc.py index 4187da686..9891905d1 100644 --- a/neutron/plugins/ml2/rpc.py +++ b/neutron/plugins/ml2/rpc.py @@ -28,6 +28,7 @@ from neutron.common import rpc as n_rpc from neutron.common import topics from neutron.extensions import portbindings from neutron.extensions import portsecurity as psec +from neutron.extensions import qos from neutron.i18n import _LW from neutron import manager from neutron.plugins.ml2 import driver_api as api @@ -106,6 +107,8 @@ class RpcCallbacks(type_tunnel.TunnelRpcCallbackMixin): host, port_context.network.current) + qos_profile_id = (port.get(qos.QOS_POLICY_ID) or + port_context.network._network.get(qos.QOS_POLICY_ID)) entry = {'device': device, 'network_id': port['network_id'], 'port_id': port['id'], @@ -118,6 +121,7 @@ class RpcCallbacks(type_tunnel.TunnelRpcCallbackMixin): 'device_owner': port['device_owner'], 'allowed_address_pairs': port['allowed_address_pairs'], 'port_security_enabled': port.get(psec.PORTSECURITY, True), + 'qos_policy_id': qos_profile_id, 'profile': port[portbindings.PROFILE]} LOG.debug("Returning: %s", entry) return entry diff --git a/neutron/tests/unit/plugins/ml2/test_rpc.py b/neutron/tests/unit/plugins/ml2/test_rpc.py index f0e1a3603..0b1c0c97b 100644 --- a/neutron/tests/unit/plugins/ml2/test_rpc.py +++ b/neutron/tests/unit/plugins/ml2/test_rpc.py @@ -28,6 +28,7 @@ from neutron.agent import rpc as agent_rpc from neutron.common import constants from neutron.common import exceptions from neutron.common import topics +from neutron.extensions import qos from neutron.plugins.ml2.drivers import type_tunnel from neutron.plugins.ml2 import managers from neutron.plugins.ml2 import rpc as plugin_rpc @@ -134,6 +135,31 @@ class RpcCallbacksTestCase(base.BaseTestCase): self.callbacks.get_device_details(mock.Mock()) self.assertTrue(self.plugin.update_port_status.called) + def test_get_device_details_qos_policy_id_none(self): + port = collections.defaultdict(lambda: 'fake_port') + self.plugin.get_bound_port_context().current = port + self.plugin.get_bound_port_context().network._network = ( + {"id": "fake_network"}) + res = self.callbacks.get_device_details(mock.Mock(), host='fake') + self.assertIsNone(res['qos_policy_id']) + + def test_get_device_details_qos_policy_id_inherited_from_network(self): + port = collections.defaultdict(lambda: 'fake_port') + self.plugin.get_bound_port_context().current = port + self.plugin.get_bound_port_context().network._network = ( + {"id": "fake_network", qos.QOS_POLICY_ID: 'test-policy-id'}) + res = self.callbacks.get_device_details(mock.Mock(), host='fake') + self.assertEqual('test-policy-id', res['qos_policy_id']) + + def test_get_device_details_qos_policy_id_taken_from_port(self): + port = collections.defaultdict( + lambda: 'fake_port', {qos.QOS_POLICY_ID: 'test-port-policy-id'}) + self.plugin.get_bound_port_context().current = port + self.plugin.get_bound_port_context().network._network = ( + {"id": "fake_network", qos.QOS_POLICY_ID: 'test-net-policy-id'}) + res = self.callbacks.get_device_details(mock.Mock(), host='fake') + self.assertEqual('test-port-policy-id', res['qos_policy_id']) + def test_get_devices_details_list(self): devices = [1, 2, 3, 4, 5] kwargs = {'host': 'fake_host', 'agent_id': 'fake_agent_id'}