From 8e31122d36ce5c9d367696921ed92c50cb062b5f Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Fri, 11 Jul 2014 09:15:58 +0900 Subject: [PATCH] Fix DVR regression for ofagent Background: ML2 plugin sometimes uses truncated port uuids. For example, in the case of ofagent and linuxbridge, if port id is 804ceaa1-0e3e-11e4-b537-08606e7f74e7, an agent would send "tap804ceaa1-0e" to the plugin. ML2 plugin's _device_to_port_id() would restore it to "804ceaa1-0e". While it's still truncated, ML2 plugin's get_port() handles that by using "startswith". The recently merged DVR change (https://review.openstack.org/#/c/102332/) assumes that port_id is always a complete uuid (it's the case for openvswitch) and fails to handle the above mentioned case. This commit fixes the regression. Change-Id: I9c0845be606969068ab5d13c0165e76760378500 Closes-Bug: #1343750 --- neutron/plugins/ml2/plugin.py | 8 ++++++-- neutron/plugins/ml2/rpc.py | 12 ++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/neutron/plugins/ml2/plugin.py b/neutron/plugins/ml2/plugin.py index 294deb668..34e5add14 100644 --- a/neutron/plugins/ml2/plugin.py +++ b/neutron/plugins/ml2/plugin.py @@ -939,6 +939,10 @@ 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): + """ + Returns port_id (non-truncated uuid) if the port exists. + Otherwise returns None. + """ updated = False session = context.session # REVISIT: Serialize this operation with a semaphore to @@ -951,7 +955,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2, if not port: LOG.warning(_("Port %(port)s updated up by agent not found"), {'port': port_id}) - return False + return None if port.status != status: original_port = self._make_port_dict(port) port.status = status @@ -967,7 +971,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2, if updated: self.mechanism_manager.update_port_postcommit(mech_context) - return True + return port['id'] def port_bound_to_host(self, context, port_id, host): port_host = db.get_port_binding_host(port_id) diff --git a/neutron/plugins/ml2/rpc.py b/neutron/plugins/ml2/rpc.py index 553ba1f1f..0ee8c0099 100644 --- a/neutron/plugins/ml2/rpc.py +++ b/neutron/plugins/ml2/rpc.py @@ -159,9 +159,9 @@ class RpcCallbacks(n_rpc.RpcCallback, return {'device': device, 'exists': port_exists} - port_exists = plugin.update_port_status(rpc_context, port_id, - q_const.PORT_STATUS_DOWN, - host) + port_exists = bool(plugin.update_port_status(rpc_context, port_id, + q_const.PORT_STATUS_DOWN, + host)) return {'device': device, 'exists': port_exists} @@ -182,9 +182,9 @@ class RpcCallbacks(n_rpc.RpcCallback, {'device': device, 'host': host}) return - plugin.update_port_status(rpc_context, port_id, - q_const.PORT_STATUS_ACTIVE, - host) + port_id = plugin.update_port_status(rpc_context, port_id, + q_const.PORT_STATUS_ACTIVE, + host) l3plugin = manager.NeutronManager.get_service_plugins().get( service_constants.L3_ROUTER_NAT) if l3plugin: -- 2.45.2