From b8ca269a679ceecfcfa4e95ded148df07e8dd3b2 Mon Sep 17 00:00:00 2001 From: Matt Riedemann Date: Tue, 12 Mar 2019 16:11:04 -0400 Subject: [PATCH] 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 (cherry picked from commit 521e59224e8a595af66ec898f1bb739a9dbe7d97) (cherry picked from commit 17e6ca727207a21028f2878a1e01047c1be2ad36) --- nova/compute/manager.py | 20 ++++++++++++++------ nova/tests/unit/compute/test_compute_mgr.py | 13 ++++++++----- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 85427d62c5fb..0ec2cc0059cb 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -8071,13 +8071,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 ' diff --git a/nova/tests/unit/compute/test_compute_mgr.py b/nova/tests/unit/compute/test_compute_mgr.py index 2b9364adae60..dd73747ea0b2 100644 --- a/nova/tests/unit/compute/test_compute_mgr.py +++ b/nova/tests/unit/compute/test_compute_mgr.py @@ -2810,14 +2810,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, @@ -2827,8 +2830,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):