From d9c6610cb60f2da152f567aaa1b0cdb9edef2957 Mon Sep 17 00:00:00 2001 From: Sahid Orentino Ferdjaoui Date: Thu, 21 Sep 2017 15:42:54 +0200 Subject: [PATCH] ml2: fix update_device_up to send lm events with linux bridge In case of a live migration and with linux bridge the events are not sent to Nova, because the port UUID returned by _device_to_port_id may be a truncated UUID and the current plugin._get_port() can't find it. Conflicts: neutron/tests/unit/plugins/ml2/test_rpc.py NOTE(lyarwood): Test conflict introducing an additional mock for ml2_db, required prior to Pike and Ia15c63f94d2c67791da3b65546e59f6929c8c685. Related-Bug: #1414559 Change-Id: Icb039ae2d465e3822ab07ae4f9bc405c1362afba Signed-off-by: Sahid Orentino Ferdjaoui (cherry picked from commit 38b3d4e16ac76d97f64f264c68ef9b88d66e0324) (cherry picked from commit 50988f3f3665adb4dd481aff5515a81878c8e067) --- neutron/plugins/ml2/rpc.py | 8 ++++---- neutron/tests/unit/plugins/ml2/test_rpc.py | 15 +++++++++------ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/neutron/plugins/ml2/rpc.py b/neutron/plugins/ml2/rpc.py index 4a0f1d06bb2..9608da436b0 100644 --- a/neutron/plugins/ml2/rpc.py +++ b/neutron/plugins/ml2/rpc.py @@ -14,7 +14,6 @@ # under the License. from neutron_lib import constants as n_const -from neutron_lib import exceptions from neutron_lib.plugins import directory from oslo_log import log import oslo_messaging @@ -238,9 +237,10 @@ class RpcCallbacks(type_tunnel.TunnelRpcCallbackMixin): # this might mean that a VM is in the process of live migration # and vif was plugged on the destination compute node; # need to notify nova explicitly - try: - port = plugin._get_port(rpc_context, port_id) - except exceptions.PortNotFound: + port = ml2_db.get_port(rpc_context, port_id) + # _device_to_port_id may have returned a truncated UUID if the + # agent did not provide a full one (e.g. Linux Bridge case). + if not port: LOG.debug("Port %s not found, will not notify nova.", port_id) return else: diff --git a/neutron/tests/unit/plugins/ml2/test_rpc.py b/neutron/tests/unit/plugins/ml2/test_rpc.py index 1e09012857b..a264096ec5e 100644 --- a/neutron/tests/unit/plugins/ml2/test_rpc.py +++ b/neutron/tests/unit/plugins/ml2/test_rpc.py @@ -30,6 +30,7 @@ from neutron.agent import rpc as agent_rpc from neutron.callbacks import resources from neutron.common import topics from neutron.db import provisioning_blocks +from neutron.plugins.ml2 import db as ml2_db from neutron.plugins.ml2.drivers import type_tunnel from neutron.plugins.ml2 import managers from neutron.plugins.ml2 import rpc as plugin_rpc @@ -62,7 +63,8 @@ class RpcCallbacksTestCase(base.BaseTestCase): mock.patch.object(self.callbacks, 'notify_ha_port_status'): with mock.patch('neutron.db.provisioning_blocks.' 'provisioning_complete') as pc: - self.callbacks.update_device_up(mock.Mock(), **kwargs) + with mock.patch.object(ml2_db, 'get_port'): + self.callbacks.update_device_up(mock.Mock(), **kwargs) return pc def test_update_device_up_notify(self): @@ -221,11 +223,12 @@ class RpcCallbacksTestCase(base.BaseTestCase): return res def test_update_device_up_with_device_not_bound_to_host(self): - self.assertIsNone(self._test_update_device_not_bound_to_host( - self.callbacks.update_device_up)) - port = self.plugin._get_port.return_value - (self.plugin.nova_notifier.notify_port_active_direct. - assert_called_once_with(port)) + with mock.patch.object(ml2_db, 'get_port') as ml2_db_get_port: + self.assertIsNone(self._test_update_device_not_bound_to_host( + self.callbacks.update_device_up)) + port = ml2_db_get_port.return_value + (self.plugin.nova_notifier.notify_port_active_direct. + assert_called_once_with(port)) def test_update_device_down_with_device_not_bound_to_host(self): self.assertEqual(