Don't warn on network-vif-unplugged event during live migration

The "network-vif-unplugged" event is expected during live migration
and nothing listens for it so we should not log a warning in that case.

Change-Id: I8fd8df211670f1abbcb7b496e62589295922bdc1
Closes-Bug: #1819764
This commit is contained in:
Matt Riedemann 2019-03-12 16:11:04 -04:00
parent a5e3054e1d
commit 521e59224e
2 changed files with 22 additions and 11 deletions

View File

@ -8204,13 +8204,21 @@ class ComputeManager(manager.Manager):
_event.send(event)
else:
# If it's a network-vif-unplugged event and the instance is being
# deleted then we don't need to make this a warning as it's
# expected. There are other things which could trigger this like
# detaching an interface, but we don't have a task state for that.
# deleted or live migrated then we don't need to make this a
# warning as it's expected. There are other expected things which
# could trigger this event like detaching an interface, but we
# don't have a task state for that.
# TODO(mriedem): We have other move operations and things like
# hard reboot (probably rebuild as well) which trigger this event
# but nothing listens for network-vif-unplugged. We should either
# handle those other known cases or consider just not logging a
# warning if we get this event and the instance is undergoing some
# task state transition.
if (event.name == 'network-vif-unplugged' and
instance.task_state == task_states.DELETING):
LOG.debug('Received event %s for instance which is being '
'deleted.', event.key, instance=instance)
instance.task_state in (
task_states.DELETING, task_states.MIGRATING)):
LOG.debug('Received event %s for instance with task_state %s.',
event.key, instance.task_state, instance=instance)
else:
LOG.warning('Received unexpected event %(event)s for '
'instance with vm_state %(vm_state)s and '

View File

@ -2830,14 +2830,17 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase,
self.assertEqual(event_obj, event.wait())
self.assertEqual({}, self.compute.instance_events._events)
@ddt.data(task_states.DELETING,
task_states.MIGRATING)
@mock.patch('nova.compute.manager.LOG')
def test_process_instance_event_deleting(self, mock_log):
def test_process_instance_event_expected_task(self, task_state, mock_log):
"""Tests that we don't log a warning when we get a
network-vif-unplugged event for an instance that's being deleted.
network-vif-unplugged event for an instance that's undergoing a task
state transition that will generate the expected event.
"""
inst_obj = objects.Instance(uuid=uuids.instance,
vm_state=vm_states.ACTIVE,
task_state=task_states.DELETING)
task_state=task_state)
event_obj = objects.InstanceExternalEvent(name='network-vif-unplugged',
tag=uuids.port_id)
with mock.patch.object(self.compute.instance_events,
@ -2847,8 +2850,8 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase,
mock_log.debug.assert_called()
self.assertThat(mock_log.debug.call_args[0][0],
testtools.matchers.MatchesRegex(
'Received event .* for instance which is being '
'deleted.'))
'Received event .* for instance with task_state '
'%s'))
@mock.patch('nova.compute.manager.LOG')
def test_process_instance_event_unexpected_warning(self, mock_log):