From 19cc6e2ca897e65a630dfb3905ca62e8101d5b2e Mon Sep 17 00:00:00 2001 From: Rajesh Tailor Date: Thu, 5 May 2016 06:11:25 -0400 Subject: [PATCH] Fix inappropriate notification send The method '_build_and_run_instance' sends inappropriate notification 'create.end' when an exception is raised, instead it should be sending 'create.error' notification. Replaced 'create.end' notification with 'create.error' when exception is raised. Change-Id: I2661cc47b6ebb674cce2f2b43851aa9eca12b5f8 Closes-Bug:1578500 --- nova/compute/manager.py | 4 ++-- nova/tests/unit/compute/test_compute_mgr.py | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 189a1fed9b2f..8aa18b840f9d 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -1916,7 +1916,7 @@ class ComputeManager(manager.Manager): exception.UnexpectedDeletingTaskStateError) as e: with excutils.save_and_reraise_exception(): self._notify_about_instance_usage(context, instance, - 'create.end', fault=e) + 'create.error', fault=e) except exception.ComputeResourcesUnavailable as e: LOG.debug(e.format_message(), instance=instance) self._notify_about_instance_usage(context, instance, @@ -1991,7 +1991,7 @@ class ComputeManager(manager.Manager): exception.UnexpectedDeletingTaskStateError) as e: with excutils.save_and_reraise_exception(): self._notify_about_instance_usage(context, instance, - 'create.end', fault=e) + 'create.error', fault=e) self._update_scheduler_instance_info(context, instance) self._notify_about_instance_usage(context, instance, 'create.end', diff --git a/nova/tests/unit/compute/test_compute_mgr.py b/nova/tests/unit/compute/test_compute_mgr.py index dce24554d5c4..34cc3ea3fb02 100755 --- a/nova/tests/unit/compute/test_compute_mgr.py +++ b/nova/tests/unit/compute/test_compute_mgr.py @@ -3835,7 +3835,7 @@ class ComputeManagerBuildInstanceTestCase(test.NoDBTestCase): mock_notify.assert_has_calls([ mock.call(self.context, self.instance, 'create.start', extra_usage_info={'image_name': self.image.get('name')}), - mock.call(self.context, self.instance, 'create.end', + mock.call(self.context, self.instance, 'create.error', fault=exc)]) mock_build.assert_called_once_with(self.context, self.instance, self.requested_networks, self.security_groups) @@ -4412,10 +4412,10 @@ class ComputeManagerBuildInstanceTestCase(test.NoDBTestCase): _check_access_ip() @mock.patch.object(manager.ComputeManager, '_instance_update') - def test_create_end_on_instance_delete(self, mock_instance_update): + def test_create_error_on_instance_delete(self, mock_instance_update): def fake_notify(*args, **kwargs): - if args[2] == 'create.end': + if args[2] == 'create.error': # Check that launched_at is set on the instance self.assertIsNotNone(args[1].launched_at) @@ -4437,10 +4437,10 @@ class ComputeManagerBuildInstanceTestCase(test.NoDBTestCase): self.security_groups, self.block_device_mapping, self.node, self.limits, self.filter_properties) expected_call = mock.call(self.context, self.instance, - 'create.end', fault=exc) - create_end_call = mock_notify.call_args_list[ + 'create.error', fault=exc) + create_error_call = mock_notify.call_args_list[ mock_notify.call_count - 1] - self.assertEqual(expected_call, create_end_call) + self.assertEqual(expected_call, create_error_call) class ComputeManagerMigrationTestCase(test.NoDBTestCase):