From 24fb21623eac04cf8abf8c04e0febb4c52e57540 Mon Sep 17 00:00:00 2001 From: Kevin Benton Date: Thu, 16 Feb 2017 14:53:31 -0800 Subject: [PATCH] Macvtap: Check for no original port in is_live_migration Change 6865f4d9f22d5daa2f07ff9651c2280aed489c8c mistakenly assumed that None would not be present for the 'original' property on a PortContext. However, this is the default value for the original field in PortContext, which is what is used in the construction as part of the _create_port_db process in ML2. This resulted in binding failures for the macvtap mech drivers due to an attribute error in cases like brand new ports. This patch simply checks for None before trying to determine if it's a live migration (which it isn't in the case of port creation). Part of the issue is likely that the FakePortContext in the unit tests was defaulting to an empty dict which is the not the same behavior as the real PortContext. Change-Id: I6659235a70aa4528fd21911c04e651194591e449 Closes-Bug: #1658802 (cherry picked from commit 3dddfa56db69b504408c6894a814a89ea63b05f0) --- .../plugins/ml2/drivers/macvtap/mech_driver/mech_macvtap.py | 3 +++ neutron/tests/unit/plugins/ml2/_test_mech_agent.py | 2 +- .../ml2/drivers/macvtap/mech_driver/test_mech_macvtap.py | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/neutron/plugins/ml2/drivers/macvtap/mech_driver/mech_macvtap.py b/neutron/plugins/ml2/drivers/macvtap/mech_driver/mech_macvtap.py index 0d54090e5fb..f578e8bf9e1 100644 --- a/neutron/plugins/ml2/drivers/macvtap/mech_driver/mech_macvtap.py +++ b/neutron/plugins/ml2/drivers/macvtap/mech_driver/mech_macvtap.py @@ -64,6 +64,9 @@ class MacvtapMechanismDriver(mech_agent.SimpleAgentMechanismDriverBase): # The only safe way to detect a migration is to look into the binding # profiles 'migrating_to' attribute, which is set by Nova since patch # https://review.openstack.org/#/c/275073/. + if not context.original: + # new port + return False port_profile = context.original.get(portbindings.PROFILE) if port_profile and port_profile.get('migrating_to', None): LOG.debug("Live migration with profile %s detected.", port_profile) diff --git a/neutron/tests/unit/plugins/ml2/_test_mech_agent.py b/neutron/tests/unit/plugins/ml2/_test_mech_agent.py index 3e4efdc49bd..addfb67f950 100644 --- a/neutron/tests/unit/plugins/ml2/_test_mech_agent.py +++ b/neutron/tests/unit/plugins/ml2/_test_mech_agent.py @@ -59,7 +59,7 @@ class FakePortContext(api.PortContext): @property def original(self): - return self._original or {} + return self._original @property def status(self): diff --git a/neutron/tests/unit/plugins/ml2/drivers/macvtap/mech_driver/test_mech_macvtap.py b/neutron/tests/unit/plugins/ml2/drivers/macvtap/mech_driver/test_mech_macvtap.py index 5d145a1b9d1..0c5c30cddfc 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/macvtap/mech_driver/test_mech_macvtap.py +++ b/neutron/tests/unit/plugins/ml2/drivers/macvtap/mech_driver/test_mech_macvtap.py @@ -71,6 +71,9 @@ class MacvtapMechanismMigrationTestCase(object): def test__is_live_migration_false(self): self._test__is_live_migration(False, {}) + def test__is_live_migration_false_None_original(self): + self._test__is_live_migration(False, None) + def _test__is_live_migration(self, expected, original): context = base.FakePortContext(self.AGENT_TYPE, self.AGENTS,