From 680518ad6d07febac69cc0d413dfd626f83dd93d Mon Sep 17 00:00:00 2001 From: Douglas Viroel Date: Wed, 30 Jul 2025 17:29:16 -0300 Subject: [PATCH] Fix zone migration instance not found issue When retrieving the list of instances and volumes to propose a solution, the zone migration strategy can raise an exception for instance or volume not found, which will make the audit goes to a failure state. This fix maintains the logic of listing all elements directly from the client (nova) but now checks if the instance is already in the model. The storage model check was already fixed in another patch[1]. [1] https://github.com/openstack/watcher/commit/cb6fb1609706495a6187b973a55e270257be64e1 Closes-Bug: #2098984 Assisted-By: Cursor (claude-3.5-sonnet) Change-Id: I4c8993f051b797104172047eaae1fe1523eaf7eb Signed-off-by: Douglas Viroel --- ...migration-instance-not-found-b9ce947dd3e7e020.yaml | 9 +++++++++ .../strategy/strategies/zone_migration.py | 2 +- .../strategy/strategies/test_zone_migration.py | 11 ++--------- 3 files changed, 12 insertions(+), 10 deletions(-) create mode 100644 releasenotes/notes/bug-2098984-zone-migration-instance-not-found-b9ce947dd3e7e020.yaml diff --git a/releasenotes/notes/bug-2098984-zone-migration-instance-not-found-b9ce947dd3e7e020.yaml b/releasenotes/notes/bug-2098984-zone-migration-instance-not-found-b9ce947dd3e7e020.yaml new file mode 100644 index 000000000..740d48c5d --- /dev/null +++ b/releasenotes/notes/bug-2098984-zone-migration-instance-not-found-b9ce947dd3e7e020.yaml @@ -0,0 +1,9 @@ +--- +fixes: + - | + Fixes a bug in the zone migration strategy where audits would fail due to + an unhandled exception when trying to plan instance migration that exist + in Nova but not in Watcher's compute model. + The strategy now filters out the elements that are not found in the model, + allowing the audit to complete successfully. For more details, please see + `Bug #2098984 `_. diff --git a/watcher/decision_engine/strategy/strategies/zone_migration.py b/watcher/decision_engine/strategy/strategies/zone_migration.py index 8e7360a7f..e5182d5c8 100644 --- a/watcher/decision_engine/strategy/strategies/zone_migration.py +++ b/watcher/decision_engine/strategy/strategies/zone_migration.py @@ -540,7 +540,7 @@ class ZoneMigration(base.ZoneMigrationBaseStrategy): return [i for i in self.nova.get_instance_list() if getattr(i, 'OS-EXT-SRV-ATTR:host') in src_node_list and - self.compute_model.get_instance_by_uuid(i.id)] + self.compute_model.has_node(i.id)] def get_volumes(self): """Get migrate target volumes diff --git a/watcher/tests/decision_engine/strategy/strategies/test_zone_migration.py b/watcher/tests/decision_engine/strategy/strategies/test_zone_migration.py index 6e36138d0..35e9db2fd 100644 --- a/watcher/tests/decision_engine/strategy/strategies/test_zone_migration.py +++ b/watcher/tests/decision_engine/strategy/strategies/test_zone_migration.py @@ -17,7 +17,6 @@ from unittest import mock import cinderclient import novaclient -from watcher.common import exception as watcher_exception from watcher.common import utils from watcher.decision_engine.strategy import strategies from watcher.tests.decision_engine.model import faker_cluster_state @@ -168,15 +167,9 @@ class TestZoneMigration(TestBaseStrategy): # Mock nova helper to return our test instance self.m_n_helper.get_instance_list.return_value = [instance_on_src1] - # FIXME(dviroel): Fix this test together with bug #2098984 - # It should return an empty list and not raise an exception # Verify that the instance does not exist in the model - # instances = self.strategy.get_instances() - # self.assertEqual([], instances) - - self.assertRaises( - watcher_exception.InstanceNotFound, - self.strategy.get_instances) + instances = self.strategy.get_instances() + self.assertEqual([], instances) def test_get_volumes_with_volume_not_found(self): # Create a test volume without an known id