Don't populate resources for not-yet-migrated inst

Per the referenced bug, it is possible for update_available_resource to
race with a migration such that the migration record exists, but the
instance's migration context doesn't. In such cases we shouldn't try to
track the instance's assigned resources on this host (because there
aren't any yet).

Change-Id: I69f99adfa8c91b50086052ca1b15c55e86ed614d
Closes-Bug: #1849165
This commit is contained in:
Eric Fried 2019-10-21 11:50:25 -05:00
parent 761be5d0cb
commit 80385a22ee
2 changed files with 8 additions and 4 deletions

View File

@ -477,6 +477,10 @@ class ResourceTracker(object):
# Get resources assigned to migrations
for mig in self.tracked_migrations.values():
mig_ctx = mig.instance.migration_context
# We might have a migration whose instance hasn't arrived here yet.
# Ignore it.
if not mig_ctx:
continue
if mig.source_compute == self.host and 'old_resources' in mig_ctx:
resources.extend(mig_ctx.old_resources or [])
if mig.dest_compute == self.host and 'new_resources' in mig_ctx:

View File

@ -58,9 +58,9 @@ class UpdateResourceMigrationRaceTest(
'OS-EXT-STS:task_state': None,
'status': 'ACTIVE'})
# FIXME(efried): This is bug 1849165 where
# _populate_assigned_resources raises a TypeError because it tries
# to access the instance's migration_context before that exists.
self.assertIn(
# NOTE(efried): This was bug 1849165 where
# _populate_assigned_resources raised a TypeError because it tried
# to access the instance's migration_context before that existed.
self.assertNotIn(
"TypeError: argument of type 'NoneType' is not iterable",
self.stdlog.logger.output)