Merge "Refresh target cell instance after finish_snapshot_based_resize_at_dest"

This commit is contained in:
Zuul 2019-12-20 06:41:41 +00:00 committed by Gerrit Code Review
commit bbda16f634
2 changed files with 11 additions and 3 deletions

View File

@ -513,6 +513,9 @@ class FinishResizeAtDestTask(base.TaskBase):
self.compute_rpcapi.finish_snapshot_based_resize_at_dest(
self.context, self.instance, self.migration, self.snapshot_id,
self.request_spec)
# finish_snapshot_based_resize_at_dest updates the target cell
# instance so we need to refresh it here to have the latest copy.
self.instance.refresh()
except Exception:
# We need to mimic the error handlers on
# finish_snapshot_based_resize_at_dest in the destination compute

View File

@ -949,20 +949,25 @@ class FinishResizeAtDestTaskTestCase(test.TestCase):
def test_execute(self):
"""Tests the happy path scenario for the task execution."""
with mock.patch.object(
with test.nested(
mock.patch.object(
self.task.compute_rpcapi,
'finish_snapshot_based_resize_at_dest') as finish_resize:
'finish_snapshot_based_resize_at_dest'),
mock.patch.object(self.task.instance, 'refresh')
) as (
finish_resize, refresh
):
self.task.execute()
# _finish_snapshot_based_resize_at_dest will set the instance
# task_state to resize_migrated, save the change, and call the
# finish_snapshot_based_resize_at_dest method.
target_instance = self.task.instance
target_instance.refresh()
self.assertEqual(task_states.RESIZE_MIGRATED,
self.task.instance.task_state)
finish_resize.assert_called_once_with(
self.task.context, target_instance, self.task.migration,
self.task.snapshot_id, self.task.request_spec)
refresh.assert_called_once_with()
# _update_instance_mapping will swap the hidden fields and update
# the instance mapping to point at the target cell.
self.assertFalse(target_instance.hidden,