Allow update_port_status to take network param
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
This commit is contained in:
parent
ca01ebc120
commit
ea35b299f0
|
@ -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)
|
||||
|
|
|
@ -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'],
|
||||
|
|
|
@ -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},
|
||||
|
|
Loading…
Reference in New Issue