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] cb6fb16097

Closes-Bug: #2098984
Assisted-By: Cursor (claude-3.5-sonnet)

Change-Id: I4c8993f051b797104172047eaae1fe1523eaf7eb
Signed-off-by: Douglas Viroel <viroel@gmail.com>
This commit is contained in:
Douglas Viroel
2025-07-30 17:29:16 -03:00
parent cada9acced
commit 680518ad6d
3 changed files with 12 additions and 10 deletions

View File

@@ -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 <https://bugs.launchpad.net/watcher/+bug/2098984>`_.

View File

@@ -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

View File

@@ -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