]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
ml2: added qos_profile_id to get_device_details payload
authorIhar Hrachyshka <ihrachys@redhat.com>
Fri, 24 Jul 2015 15:31:50 +0000 (17:31 +0200)
committerIhar Hrachyshka <ihrachys@redhat.com>
Sat, 25 Jul 2015 07:29:19 +0000 (09:29 +0200)
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

neutron/plugins/ml2/rpc.py
neutron/tests/unit/plugins/ml2/test_rpc.py

index 4187da6864e20174eeb480e8fc7a593e21b2a7fd..9891905d117016136c36a85c34d0308ecf8182b1 100644 (file)
@@ -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
index f0e1a360322b86baded0faaec854b9a78b5bb5de..0b1c0c97b2f20c58481cff11fe1181956d38eee7 100644 (file)
@@ -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'}