Skip to content

Commit 568769e

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Clean up when queued live migration aborted" into stable/xena
2 parents 025c6d1 + 8670ca8 commit 568769e

File tree

3 files changed

+69
-39
lines changed

3 files changed

+69
-39
lines changed

nova/compute/manager.py

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8595,15 +8595,41 @@ def live_migration_abort(self, context, instance, migration_id):
85958595
migration, future = (
85968596
self._waiting_live_migrations.pop(instance.uuid))
85978597
if future and future.cancel():
8598-
# If we got here, we've successfully aborted the queued
8599-
# migration and _do_live_migration won't run so we need
8600-
# to set the migration status to cancelled and send the
8601-
# notification. If Future.cancel() fails, it means
8602-
# _do_live_migration is running and the migration status
8603-
# is preparing, and _do_live_migration() itself will attempt
8604-
# to pop the queued migration, hit a KeyError, and rollback,
8605-
# set the migration to cancelled and send the
8606-
# live.migration.abort.end notification.
8598+
# If we got here, we've successfully dropped a queued
8599+
# migration from the queue, so _do_live_migration won't run
8600+
# and we only need to revert minor changes introduced by Nova
8601+
# control plane (port bindings, resource allocations and
8602+
# instance's PCI devices), restore VM's state, set the
8603+
# migration's status to cancelled and send the notification.
8604+
# If Future.cancel() fails, it means _do_live_migration is
8605+
# running and the migration status is preparing, and
8606+
# _do_live_migration() itself will attempt to pop the queued
8607+
# migration, hit a KeyError, and rollback, set the migration
8608+
# to cancelled and send the live.migration.abort.end
8609+
# notification.
8610+
self._revert_allocation(context, instance, migration)
8611+
try:
8612+
# This call will delete any inactive destination host
8613+
# port bindings.
8614+
self.network_api.setup_networks_on_host(
8615+
context, instance, host=migration.dest_compute,
8616+
teardown=True)
8617+
except exception.PortBindingDeletionFailed as e:
8618+
# Removing the inactive port bindings from the destination
8619+
# host is not critical so just log an error but don't fail.
8620+
LOG.error(
8621+
'Network cleanup failed for destination host %s '
8622+
'during live migration rollback. You may need to '
8623+
'manually clean up resources in the network service. '
8624+
'Error: %s', migration.dest_compute, str(e))
8625+
except Exception:
8626+
with excutils.save_and_reraise_exception():
8627+
LOG.exception(
8628+
'An error occurred while cleaning up networking '
8629+
'during live migration rollback.',
8630+
instance=instance)
8631+
instance.task_state = None
8632+
instance.save(expected_task_state=[task_states.MIGRATING])
86078633
self._set_migration_status(migration, 'cancelled')
86088634
except KeyError:
86098635
migration = objects.Migration.get_by_id(context, migration_id)

nova/tests/functional/libvirt/test_live_migration.py

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,12 @@ def test_queued_live_migration_abort_vm_status(self):
117117
'/servers/%s/migrations/%s' % (self.server_b['id'],
118118
serverb_migration['id']))
119119
self._wait_for_migration_status(self.server_b, ['cancelled'])
120-
# Unlock live migrations and confirm that server_a becomes
121-
# active again after successful live migration
120+
# Unlock live migrations and confirm that both servers become
121+
# active again after successful (server_a) and aborted
122+
# (server_b) live migrations
122123
self.lock_live_migration.release()
123124
self._wait_for_state_change(self.server_a, 'ACTIVE')
124-
125-
# FIXME(artom) Assert the server_b never comes out of 'MIGRATING'
126-
self.assertRaises(
127-
AssertionError,
128-
self._wait_for_state_change, self.server_b, 'ACTIVE')
129-
self._wait_for_state_change(self.server_b, 'MIGRATING')
125+
self._wait_for_state_change(self.server_b, 'ACTIVE')
130126

131127

132128
class LiveMigrationQueuedAbortTestLeftoversRemoved(LiveMigrationWithLockBase):
@@ -182,36 +178,28 @@ def test_queued_live_migration_abort_leftovers_removed(self):
182178
'/servers/%s/migrations/%s' % (self.server_b['id'],
183179
migration_server_b['id']))
184180
self._wait_for_migration_status(self.server_b, ['cancelled'])
185-
# Unlock live migrations and confirm that server_a becomes
186-
# active again after successful live migration
181+
# Unlock live migrations and confirm that both servers become
182+
# active again after successful (server_a) and aborted
183+
# (server_b) live migrations
187184
self.lock_live_migration.release()
188185
self._wait_for_state_change(self.server_a, 'ACTIVE')
189186
self._wait_for_migration_status(self.server_a, ['completed'])
190-
# FIXME(astupnikov) Assert the server_b never comes out of 'MIGRATING'
191-
# This should be fixed after bug #1949808 is addressed
192-
self._wait_for_state_change(self.server_b, 'MIGRATING')
187+
self._wait_for_state_change(self.server_b, 'ACTIVE')
193188

194-
# FIXME(astupnikov) Because of bug #1960412 allocations for aborted
195-
# queued live migration (server_b) would not be removed. Allocations
196-
# for completed live migration (server_a) should be empty.
189+
# Allocations for both successful (server_a) and aborted queued live
190+
# migration (server_b) should be removed.
197191
allocations_server_a_migration = self.placement.get(
198192
'/allocations/%s' % migration_server_a['uuid']
199193
).body['allocations']
200194
self.assertEqual({}, allocations_server_a_migration)
201195
allocations_server_b_migration = self.placement.get(
202196
'/allocations/%s' % migration_server_b['uuid']
203197
).body['allocations']
204-
src_uuid = self.api.api_get(
205-
'os-hypervisors?hypervisor_hostname_pattern=%s' %
206-
self.src_hostname).body['hypervisors'][0]['id']
207-
self.assertIn(src_uuid, allocations_server_b_migration)
208-
209-
# FIXME(astupnikov) Because of bug #1960412 INACTIVE port binding
210-
# on destination host would not be removed when queued live migration
211-
# is aborted, so 2 port bindings would exist for server_b port from
212-
# Neutron's perspective.
213-
# server_a should be migrated to dest compute, server_b should still
214-
# be hosted by src compute.
198+
self.assertEqual({}, allocations_server_b_migration)
199+
200+
# INACTIVE port binding on destination host should be removed when
201+
# queued live migration is aborted, so only 1 port binding would
202+
# exist for ports attached to both servers.
215203
port_binding_server_a = copy.deepcopy(
216204
self.neutron._port_bindings[self.neutron.port_1['id']]
217205
)
@@ -220,4 +208,5 @@ def test_queued_live_migration_abort_leftovers_removed(self):
220208
port_binding_server_b = copy.deepcopy(
221209
self.neutron._port_bindings[self.neutron.port_2['id']]
222210
)
223-
self.assertEqual(2, len(port_binding_server_b))
211+
self.assertEqual(1, len(port_binding_server_b))
212+
self.assertNotIn('dest', port_binding_server_b)

nova/tests/unit/compute/test_compute_mgr.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10414,19 +10414,34 @@ def test_live_migration_abort(self, mock_notify_action, mock_driver,
1041410414
action='live_migration_abort', phase='end')]
1041510415
)
1041610416

10417+
@mock.patch.object(objects.Instance, 'save')
10418+
@mock.patch.object(manager.ComputeManager, '_revert_allocation')
1041710419
@mock.patch.object(manager.ComputeManager, '_notify_about_instance_usage')
1041810420
@mock.patch.object(objects.Migration, 'get_by_id')
1041910421
@mock.patch('nova.compute.utils.notify_about_instance_action')
1042010422
def test_live_migration_abort_queued(self, mock_notify_action,
10421-
mock_get_migration, mock_notify):
10423+
mock_get_migration, mock_notify,
10424+
mock_revert_allocations,
10425+
mock_instance_save):
1042210426
instance = objects.Instance(id=123, uuid=uuids.instance)
1042310427
migration = self._get_migration(10, 'queued', 'live-migration')
10428+
migration.dest_compute = uuids.dest
10429+
migration.dest_node = uuids.dest
1042410430
migration.save = mock.MagicMock()
1042510431
mock_get_migration.return_value = migration
1042610432
fake_future = mock.MagicMock()
1042710433
self.compute._waiting_live_migrations[instance.uuid] = (
1042810434
migration, fake_future)
10429-
self.compute.live_migration_abort(self.context, instance, migration.id)
10435+
with mock.patch.object(
10436+
self.compute.network_api,
10437+
'setup_networks_on_host') as mock_setup_net:
10438+
self.compute.live_migration_abort(
10439+
self.context, instance, migration.id)
10440+
mock_setup_net.assert_called_once_with(
10441+
self.context, instance, host=migration.dest_compute,
10442+
teardown=True)
10443+
mock_revert_allocations.assert_called_once_with(
10444+
self.context, instance, migration)
1043010445
mock_notify.assert_has_calls(
1043110446
[mock.call(self.context, instance,
1043210447
'live.migration.abort.start'),

0 commit comments

Comments
 (0)