]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Allow update_port_status to take network param
authorKevin Benton <blak111@gmail.com>
Thu, 4 Jun 2015 01:25:14 +0000 (18:25 -0700)
committerKevin Benton <blak111@gmail.com>
Tue, 9 Jun 2015 11:11:58 +0000 (04:11 -0700)
Allow the update_port_status function to take a network as
an optional parameter to skip calling get_network again if
the caller has already done so.

Closes-Bug: #1463656
Change-Id: I994f3abdb1b0ad3b2766f409b206ad4a8b2309b6

neutron/plugins/ml2/plugin.py
neutron/plugins/ml2/rpc.py
neutron/tests/unit/plugins/ml2/test_plugin.py

index df831fdc81f52ba33db29186eab00cacfc2a72c9..ba8054b9989b0627fbe7c48d8585603caca0ce17 100644 (file)
@@ -1375,10 +1375,13 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
 
         return self._bind_port_if_needed(port_context)
 
-    def update_port_status(self, context, port_id, status, host=None):
+    def update_port_status(self, context, port_id, status, host=None,
+                           network=None):
         """
         Returns port_id (non-truncated uuid) if the port exists.
         Otherwise returns None.
+        network can be passed in to avoid another get_network call if
+        one was already performed by the caller.
         """
         updated = False
         session = context.session
@@ -1398,8 +1401,8 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
                 original_port = self._make_port_dict(port)
                 port.status = status
                 updated_port = self._make_port_dict(port)
-                network = self.get_network(context,
-                                           original_port['network_id'])
+                network = network or self.get_network(
+                    context, original_port['network_id'])
                 levels = db.get_binding_levels(session, port.id,
                                                port.port_binding.host)
                 mech_context = driver_context.PortContext(
@@ -1426,8 +1429,8 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
                                 port_id)
                     return
                 original_port = self._make_port_dict(port)
-                network = self.get_network(context,
-                                           original_port['network_id'])
+                network = network or self.get_network(
+                    context, original_port['network_id'])
                 port.status = db.generate_dvr_port_status(session, port['id'])
                 updated_port = self._make_port_dict(port)
                 levels = db.get_binding_levels(session, port_id, host)
index b9d478cd51a20791cc352b343cec4a86644a41ff..eeccde6a0e983dee5e4ff203ecb400e4931d58da 100644 (file)
@@ -103,7 +103,8 @@ class RpcCallbacks(type_tunnel.TunnelRpcCallbackMixin):
                 plugin.update_port_status(rpc_context,
                                           port_id,
                                           new_status,
-                                          host)
+                                          host,
+                                          port_context.network.current)
 
         entry = {'device': device,
                  'network_id': port['network_id'],
index 50dfd31964161ce4fcc4ec86ed1dac65f42bdc33..aa7de37213a857845ffe0ca2ab9ef457c3ace3cf 100644 (file)
@@ -412,6 +412,16 @@ class TestMl2PortsV2(test_plugin.TestPortsV2, Ml2PluginV2TestCase):
             plugin.update_port(ctx, port['port']['id'], port)
             self.assertTrue(sg_member_update.called)
 
+    def test_update_port_status_with_network(self):
+        ctx = context.get_admin_context()
+        plugin = manager.NeutronManager.get_plugin()
+        with self.port() as port:
+            net = plugin.get_network(ctx, port['port']['network_id'])
+            with mock.patch.object(plugin, 'get_network') as get_net:
+                plugin.update_port_status(ctx, port['port']['id'], 'UP',
+                                          network=net)
+                self.assertFalse(get_net.called)
+
     def test_update_port_mac(self):
         self.check_update_port_mac(
             host_arg={portbindings.HOST_ID: HOST},