Merge "Update instance.availability_zone on revertResize" into stable/stein

This commit is contained in:
Zuul
2019-04-11 23:23:35 +00:00
committed by Gerrit Code Review
3 changed files with 21 additions and 9 deletions

View File

@@ -3489,6 +3489,19 @@ class API(base.Base):
self._check_quota_for_upsize(context, instance, instance.flavor,
instance.old_flavor)
# The AZ for the server may have changed when it was migrated so while
# we are in the API and have access to the API DB, update the
# instance.availability_zone before casting off to the compute service.
# Note that we do this in the API to avoid an "up-call" from the
# compute service to the API DB. This is not great in case something
# fails during revert before the instance.host is updated to the
# original source host, but it is good enough for now. Long-term we
# could consider passing the AZ down to compute so it can set it when
# the instance.host value is set in finish_revert_resize.
instance.availability_zone = (
availability_zones.get_host_availability_zone(
context, migration.source_compute))
# 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

View File

@@ -165,10 +165,4 @@ class TestAvailabilityZoneScheduling(
# Revert the resize and the server should be back in the original AZ.
self.api.post_server_action(server['id'], {'revertResize': None})
server = self._wait_for_state_change(self.api, server, 'ACTIVE')
# FIXME(mriedem): This is bug 1819963 where the API will show the
# source host AZ but the instance.availability_zone value in the DB
# is still wrong because nothing updated it on revert. Remove the
# explicit API check and uncomment the _assert_instance_az call when
# the bug is fixed.
self.assertEqual(original_az, server['OS-EXT-AZ:availability_zone'])
# self._assert_instance_az(server, original_az)
self._assert_instance_az(server, original_az)

View File

@@ -1846,12 +1846,14 @@ class _ComputeAPIUnitTestMixIn(object):
def test_confirm_resize_with_migration_ref(self):
self._test_confirm_resize(mig_ref_passed=True)
@mock.patch('nova.availability_zones.get_host_availability_zone',
return_value='nova')
@mock.patch('nova.objects.Quotas.check_deltas')
@mock.patch('nova.objects.Migration.get_by_instance_and_status')
@mock.patch('nova.context.RequestContext.elevated')
@mock.patch('nova.objects.RequestSpec.get_by_instance_uuid')
def _test_revert_resize(self, mock_get_reqspec, mock_elevated,
mock_get_migration, mock_check):
mock_get_migration, mock_check, mock_get_host_az):
params = dict(vm_state=vm_states.RESIZED)
fake_inst = self._create_instance_obj(params=params)
fake_inst.old_flavor = fake_inst.flavor
@@ -1894,12 +1896,15 @@ class _ComputeAPIUnitTestMixIn(object):
def test_revert_resize(self):
self._test_revert_resize()
@mock.patch('nova.availability_zones.get_host_availability_zone',
return_value='nova')
@mock.patch('nova.objects.Quotas.check_deltas')
@mock.patch('nova.objects.Migration.get_by_instance_and_status')
@mock.patch('nova.context.RequestContext.elevated')
@mock.patch('nova.objects.RequestSpec')
def test_revert_resize_concurrent_fail(self, mock_reqspec, mock_elevated,
mock_get_migration, mock_check):
mock_get_migration, mock_check,
mock_get_host_az):
params = dict(vm_state=vm_states.RESIZED)
fake_inst = self._create_instance_obj(params=params)
fake_inst.old_flavor = fake_inst.flavor