From 80385a22ee480a4c9775148d4729ab5d9c52e76d Mon Sep 17 00:00:00 2001 From: Eric Fried Date: Mon, 21 Oct 2019 11:50:25 -0500 Subject: [PATCH] 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 --- nova/compute/resource_tracker.py | 4 ++++ nova/tests/functional/regressions/test_bug_1849165.py | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/nova/compute/resource_tracker.py b/nova/compute/resource_tracker.py index 034f4f00854e..b2ba0145cf4d 100644 --- a/nova/compute/resource_tracker.py +++ b/nova/compute/resource_tracker.py @@ -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: diff --git a/nova/tests/functional/regressions/test_bug_1849165.py b/nova/tests/functional/regressions/test_bug_1849165.py index 0980e61e92e9..5939a8c40405 100644 --- a/nova/tests/functional/regressions/test_bug_1849165.py +++ b/nova/tests/functional/regressions/test_bug_1849165.py @@ -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)