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