PCI: Fix network calls order on finish_revert_resize()

The driver was spawning the guest before migrate_instance_finish() was being
called which caused the neutron ports to not be updated with the old PCI
devices information.  Doing so results in spawning the guest to go in error
since the driver is using the wrong PCI devices.

Change-Id: I9b715f638fda65dd2be6c6693e55c8502156ed57
Partial-bug: #1512880
This commit is contained in:
Ludovic Beliveau 2016-07-29 15:57:07 -04:00
parent fe0e2eadde
commit 9a6fd30d2d
2 changed files with 47 additions and 8 deletions

View File

@ -3553,9 +3553,6 @@ class ComputeManager(manager.Manager):
with self._error_out_instance_on_exception(context, instance,
quotas=quotas):
network_info = self.network_api.get_instance_nw_info(context,
instance)
self._notify_about_instance_usage(
context, instance, "resize.revert.start")
@ -3578,6 +3575,12 @@ class ComputeManager(manager.Manager):
self.network_api.setup_networks_on_host(context, instance,
migration.source_compute)
migration_p = obj_base.obj_to_primitive(migration)
self.network_api.migrate_instance_finish(context,
instance,
migration_p)
network_info = self.network_api.get_instance_nw_info(context,
instance)
block_device_info = self._get_instance_block_device_info(
context, instance, refresh_conn_info=True)
@ -3590,11 +3593,6 @@ class ComputeManager(manager.Manager):
instance.launched_at = timeutils.utcnow()
instance.save(expected_task_state=task_states.RESIZE_REVERTING)
migration_p = obj_base.obj_to_primitive(migration)
self.network_api.migrate_instance_finish(context,
instance,
migration_p)
# if the original vm state was STOPPED, set it back to STOPPED
LOG.info(_LI("Updating instance to original state: '%s'"),
old_vm_state, instance=instance)

View File

@ -4604,6 +4604,47 @@ class ComputeManagerMigrationTestCase(test.NoDBTestCase):
def test_revert_resize_instance_destroy_disks_non_shared_storage(self):
self._test_revert_resize_instance_destroy_disks(is_shared=False)
def test_finish_revert_resize_network_calls_order(self):
self.nw_info = None
def _migrate_instance_finish(context, instance, migration):
self.nw_info = 'nw_info'
def _get_instance_nw_info(context, instance):
return self.nw_info
@mock.patch.object(self.compute, '_get_resource_tracker')
@mock.patch.object(self.compute.driver, 'finish_revert_migration')
@mock.patch.object(self.compute.network_api, 'get_instance_nw_info',
side_effect=_get_instance_nw_info)
@mock.patch.object(self.compute.network_api, 'migrate_instance_finish',
side_effect=_migrate_instance_finish)
@mock.patch.object(self.compute.network_api, 'setup_networks_on_host')
@mock.patch.object(self.migration, 'save')
@mock.patch.object(self.instance, 'save')
@mock.patch.object(self.compute, '_set_instance_info')
@mock.patch.object(compute_utils, 'notify_about_instance_usage')
def do_test(notify_about_instance_usage,
set_instance_info,
instance_save,
migration_save,
setup_networks_on_host,
migrate_instance_finish,
get_instance_nw_info,
finish_revert_migration,
get_resource_tracker):
self.migration.source_compute = self.instance['host']
self.migration.source_node = self.instance['host']
self.compute.finish_revert_resize(context=self.context,
migration=self.migration,
instance=self.instance,
reservations=None)
finish_revert_migration.assert_called_with(self.context,
self.instance, 'nw_info', mock.ANY, mock.ANY)
do_test()
def test_consoles_enabled(self):
self.flags(enabled=False, group='vnc')
self.flags(enabled=False, group='spice')