Move live_migration.pre.start to the start of the method

This simply moves the pre_live_migration start notification
back to the start of the method before creating new volume
attachments. While in here, the list of bdms are passed to
the notify_about_instance_action method so if
[notifications]/bdms_in_notifications is True we don't have
to pull them out of the database again for each versioned
notification.

Change-Id: I372eddb9e356b02328f937917a856bc631691f53
Partial-Bug: #1763051
This commit is contained in:
Matt Riedemann 2018-10-15 18:16:40 -04:00
parent f8727c4112
commit 7a2228142b
3 changed files with 25 additions and 17 deletions

View File

@ -6132,6 +6132,15 @@ class ComputeManager(manager.Manager):
migrate_data.old_vol_attachment_ids = {}
bdms = objects.BlockDeviceMappingList.get_by_instance_uuid(
context, instance.uuid)
network_info = self.network_api.get_instance_nw_info(context, instance)
self._notify_about_instance_usage(
context, instance, "live_migration.pre.start",
network_info=network_info)
compute_utils.notify_about_instance_action(
context, instance, self.host,
action=fields.NotificationAction.LIVE_MIGRATION_PRE,
phase=fields.NotificationPhase.START, bdms=bdms)
try:
connector = self.driver.get_volume_connector(instance)
for bdm in bdms:
@ -6176,15 +6185,6 @@ class ComputeManager(manager.Manager):
context, instance, refresh_conn_info=True,
bdms=bdms)
network_info = self.network_api.get_instance_nw_info(context, instance)
self._notify_about_instance_usage(
context, instance, "live_migration.pre.start",
network_info=network_info)
compute_utils.notify_about_instance_action(
context, instance, self.host,
action=fields.NotificationAction.LIVE_MIGRATION_PRE,
phase=fields.NotificationPhase.START)
# The driver pre_live_migration will plug vifs on the host.
# We call plug_vifs before calling ensure_filtering_rules_for_instance,
# to ensure bridge is set up.
@ -6229,7 +6229,7 @@ class ComputeManager(manager.Manager):
compute_utils.notify_about_instance_action(
context, instance, self.host,
action=fields.NotificationAction.LIVE_MIGRATION_PRE,
phase=fields.NotificationPhase.END)
phase=fields.NotificationPhase.END, bdms=bdms)
LOG.debug('pre_live_migration result data is %s', migrate_data)
return migrate_data

View File

@ -6088,7 +6088,10 @@ class ComputeTestCase(BaseTestCase,
@mock.patch.object(fake.FakeDriver, 'ensure_filtering_rules_for_instance')
@mock.patch.object(fake.FakeDriver, 'pre_live_migration')
@mock.patch('nova.compute.utils.notify_about_instance_action')
def test_pre_live_migration_works_correctly(self, mock_notify,
@mock.patch('nova.objects.BlockDeviceMappingList.get_by_instance_uuid',
return_value=objects.BlockDeviceMappingList())
def test_pre_live_migration_works_correctly(self, mock_get_bdms,
mock_notify,
mock_pre, mock_ensure):
# Confirm setup_compute_volume is called when volume is mounted.
def stupid(*args, **kwargs):
@ -6127,9 +6130,11 @@ class ComputeTestCase(BaseTestCase,
mock_notify.assert_has_calls([
mock.call(c, instance, 'fake-mini',
action='live_migration_pre', phase='start'),
action='live_migration_pre', phase='start',
bdms=mock_get_bdms.return_value),
mock.call(c, instance, 'fake-mini',
action='live_migration_pre', phase='end')])
action='live_migration_pre', phase='end',
bdms=mock_get_bdms.return_value)])
mock_pre.assert_called_once_with(
test.MatchType(nova.context.RequestContext),

View File

@ -7375,9 +7375,11 @@ class ComputeManagerMigrationTestCase(test.NoDBTestCase):
mock_notify_about_inst.assert_has_calls([
mock.call(self.context, instance, 'fake-mini',
action='live_migration_pre', phase='start'),
action='live_migration_pre', phase='start',
bdms=mock_get_bdms.return_value),
mock.call(self.context, instance, 'fake-mini',
action='live_migration_pre', phase='end')])
action='live_migration_pre', phase='end',
bdms=mock_get_bdms.return_value)])
self.assertIsInstance(r, migrate_data_obj.LiveMigrateData)
self.assertIsInstance(mock_plm.call_args_list[0][0][5],
migrate_data_obj.LiveMigrateData)
@ -7427,6 +7429,7 @@ class ComputeManagerMigrationTestCase(test.NoDBTestCase):
@mock.patch.object(compute_utils, 'add_instance_fault_from_exc')
@mock.patch.object(vol1_bdm, 'save')
@mock.patch.object(compute, '_notify_about_instance_usage')
@mock.patch('nova.compute.utils.notify_about_instance_action')
@mock.patch.object(compute, 'network_api')
@mock.patch.object(compute.driver, 'pre_live_migration')
@mock.patch.object(compute, '_get_instance_block_device_info')
@ -7436,8 +7439,8 @@ class ComputeManagerMigrationTestCase(test.NoDBTestCase):
@mock.patch.object(compute.volume_api, 'attachment_delete')
@mock.patch.object(compute.volume_api, 'attachment_create')
def _test(mock_attach_create, mock_attach_delete, mock_get_bdms,
mock_ivbi, mock_gibdi, mock_plm, mock_nwapi, mock_notify,
mock_bdm_save, mock_exception):
mock_ivbi, mock_gibdi, mock_plm, mock_nwapi, mock_ver_notify,
mock_notify, mock_bdm_save, mock_exception):
new_attachment_id = uuids.attachment3
mock_attach_create.side_effect = [{'id': new_attachment_id},
test.TestingException]