Macvtap: Check for no original port in is_live_migration

Change 6865f4d9f2 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 3dddfa56db)
This commit is contained in:
Kevin Benton 2017-02-16 14:53:31 -08:00 committed by Jakub Libosvar
parent 59c6530990
commit fe3a2139a8
3 changed files with 7 additions and 1 deletions

View File

@ -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)

View File

@ -59,7 +59,7 @@ class FakePortContext(api.PortContext):
@property
def original(self):
return self._original or {}
return self._original
@property
def status(self):

View File

@ -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,