Browse Source

Fix AttributeError in RT._update_usage_from_migration

Change Ieb539c9a0cfbac743c579a1633234537a8e3e3ee in Stein
added some logging in _update_usage_from_migration to log
the flavor for an inbound and outbound migration.

If an instance is resized and then the resize is immediately
confirmed, it's possible to race with ComputeManager._confirm_resize
setting the instance.old_flavor to None before the migration
status is changed to "confirmed" while the update_available_resource
periodic is running which will result in _update_usage_from_migration
hitting an AttributeError when trying to log instance.old_flavor.flavorid
since instance.old_flavor is None.

There are a few key points there:

- We get into _update_usage_from_migration because the
  _update_available_resource method gets in-progress migrations
  related to the host (in this case the source compute) and the
  migration is consider in-progress until its status is "confirmed".

- The instance is not in the tracked_instances dict when
  _update_usage_from_migration runs because RT only tracks instances
  where the instance.host matches the RT.host and in this case the
  instance has been resized to another compute and the instance.host
  is pointing at the dest compute.

The fix here is to simply check if we got the instance.old_flavor and
not log the message if we do not have it, which gets us back to the old
behavior.

This bug was found by noticing it in CI job logs - there is a link to
hits in logstash in the bug report.

As for the "incoming and not tracked" case in _update_usage_from_migration
I have not modified that since I am not sure we have the same race nor
have I seen it in CI logs.

Change-Id: I43e34b3ff1424d42632a3e8f842c93508905aa1a
Closes-Bug: #1834349
(cherry picked from commit 818419c9d3)
tags/19.0.2
Matt Riedemann 3 months ago
parent
commit
dd09686232
2 changed files with 31 additions and 2 deletions
  1. 8
    2
      nova/compute/resource_tracker.py
  2. 23
    0
      nova/tests/unit/compute/test_resource_tracker.py

+ 8
- 2
nova/compute/resource_tracker.py View File

@@ -1126,8 +1126,14 @@ class ResourceTracker(object):
1126 1126
                     migration)
1127 1127
             numa_topology = self._get_migration_context_resource(
1128 1128
                 'numa_topology', instance, prefix='old_')
1129
-            LOG.debug('Starting to track outgoing migration %s with flavor %s',
1130
-                      migration.uuid, itype.flavorid, instance=instance)
1129
+            # We could be racing with confirm_resize setting the
1130
+            # instance.old_flavor field to None before the migration status
1131
+            # is "confirmed" so if we did not find the flavor in the outgoing
1132
+            # resized instance we won't track it.
1133
+            if itype:
1134
+                LOG.debug('Starting to track outgoing migration %s with '
1135
+                          'flavor %s', migration.uuid, itype.flavorid,
1136
+                          instance=instance)
1131 1137
 
1132 1138
         if itype:
1133 1139
             cn = self.compute_nodes[nodename]

+ 23
- 0
nova/tests/unit/compute/test_resource_tracker.py View File

@@ -2747,6 +2747,29 @@ class TestUpdateUsageFromMigration(test.NoDBTestCase):
2747 2747
                                         _NODENAME)
2748 2748
         self.assertFalse(get_mock.called)
2749 2749
 
2750
+    def test_missing_old_flavor_outbound_resize(self):
2751
+        """Tests the case that an instance is not being tracked on the source
2752
+        host because it has been resized to a dest host. The confirm_resize
2753
+        operation in ComputeManager sets instance.old_flavor to None before
2754
+        the migration.status is changed to "confirmed" so the source compute
2755
+        RT considers it an in-progress migration and tries to update tracked
2756
+        usage from the instance.old_flavor (which is None when
2757
+        _update_usage_from_migration runs). This test just makes sure that the
2758
+        RT method gracefully handles the instance.old_flavor being gone.
2759
+        """
2760
+        migration = _MIGRATION_FIXTURES['source-only']
2761
+        rt = resource_tracker.ResourceTracker(
2762
+            migration.source_compute, mock.sentinel.virt_driver)
2763
+        ctxt = context.get_admin_context()
2764
+        instance = objects.Instance(
2765
+            uuid=migration.instance_uuid, old_flavor=None,
2766
+            migration_context=objects.MigrationContext())
2767
+        rt._update_usage_from_migration(
2768
+            ctxt, instance, migration, migration.source_node)
2769
+        self.assertNotIn('Starting to track outgoing migration',
2770
+                         self.stdlog.logger.output)
2771
+        self.assertNotIn(migration.instance_uuid, rt.tracked_migrations)
2772
+
2750 2773
 
2751 2774
 class TestUpdateUsageFromMigrations(BaseTestCase):
2752 2775
     @mock.patch('nova.compute.resource_tracker.ResourceTracker.'

Loading…
Cancel
Save