Update RequestSpec.flavor on resize_revert

Since I8abdf58a6537dd5e15a012ea37a7b48abd726579 in Newton
we update the RequestSpec.flavor to the new flavor during
a resize. However, if the resize is reverted, we didn't
revert the RequestSpec.flavor to the previous flavor
on the instance, which could cause issues later when
moving the instance since the scheduler will get a
RequestSpec with a flavor that doesn't match the actual
flavor on the instance.

This fixes the bug by updating the RequestSpec.flavor
with instance.old_flavor on resize_revert in the API.
Functional test wrinkles are added.

This fix was ported from the starlingx-staging/stx-nova
repo commit 71acfeae0.

Conflicts:
      nova/compute/api.py
      nova/tests/functional/test_servers.py
      nova/tests/unit/compute/test_compute_api.py

NOTE(mriedem): The compute API conflict is due to not
having change I9269ffa2b80e48db96c622d0dc0817738854f602
in Ocata. The unit test conflict was due to mox->mock
conversion in Pike. The functional test changes didn't
even exist in Ocata because they were introduced in Pike
with change If7b02bcd8d77e94c7fb42b721792c1391bc0e3b7
and wouldn't apply to Ocata, so they are removed here.

Change-Id: Ic6e74702f2a5b57b437f4ffdfbc86c1e34cdac7d
Closes-Bug: #1785339
(cherry picked from commit ef3849e2da)
(cherry picked from commit 9125fc7caf)
(cherry picked from commit f2d2a9a7c5)
(cherry picked from commit 556079a339)
This commit is contained in:
Matt Riedemann 2018-08-03 19:11:37 -04:00
parent 4246d5779e
commit c4ea58eb86
2 changed files with 20 additions and 1 deletions

View File

@ -3206,6 +3206,21 @@ class API(base.Base):
self._record_action_start(context, instance,
instance_actions.REVERT_RESIZE)
# Conductor updated the RequestSpec.flavor during the initial resize
# operation to point at the new flavor, so we need to update the
# RequestSpec to point back at the original flavor, otherwise
# subsequent move operations through the scheduler will be using the
# wrong flavor.
try:
reqspec = objects.RequestSpec.get_by_instance_uuid(
context, instance.uuid)
reqspec.flavor = instance.old_flavor
reqspec.save()
except exception.RequestSpecNotFound:
# TODO(mriedem): Make this a failure in Stein when we drop
# compatibility for missing request specs.
pass
self.compute_rpcapi.revert_resize(context, instance,
migration,
migration.dest_compute,

View File

@ -1746,7 +1746,8 @@ class _ComputeAPIUnitTestMixIn(object):
def test_confirm_resize_with_migration_ref(self):
self._test_confirm_resize(mig_ref_passed=True)
def _test_revert_resize(self):
@mock.patch('nova.objects.RequestSpec.get_by_instance_uuid')
def _test_revert_resize(self, mock_get_reqspec):
params = dict(vm_state=vm_states.RESIZED)
fake_inst = self._create_instance_obj(params=params)
fake_mig = objects.Migration._from_db_object(
@ -1805,6 +1806,9 @@ class _ComputeAPIUnitTestMixIn(object):
self.mox.ReplayAll()
self.compute_api.revert_resize(self.context, fake_inst)
mock_get_reqspec.assert_called_once_with(
self.context, fake_inst.uuid)
mock_get_reqspec.return_value.save.assert_called_once_with()
def test_revert_resize(self):
self._test_revert_resize()