From 513f2d3d254e2ffcc5c9eb786bc1c7d52036d392 Mon Sep 17 00:00:00 2001 From: jichen Date: Thu, 22 Mar 2018 14:07:20 +0800 Subject: [PATCH] Not set instance to ERROR if set_admin_password failed In some cases, an instance will be set to ERROR state when set_admin_password failed (some Exception like Forbidden) this is inconsistent to other exceptions and also set_admin_password is a sync call from API to compute, we can simply return the error to the upper layer (operator or user) to avoid make user run reset to restore instance status since no changes to guest at all. Change-Id: If1c901b974bc7295927b3f033a04eaa6ac36f603 Closes-Bug: 1757061 --- nova/compute/manager.py | 1 - nova/tests/unit/compute/test_compute_mgr.py | 9 ++------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 5dbbd0933b49..7e4ede30a9d6 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -3655,7 +3655,6 @@ class ComputeManager(manager.Manager): except Exception: # Catch all here because this could be anything. LOG.exception('set_admin_password failed', instance=instance) - self._set_instance_obj_error_state(context, instance) # We create a new exception here so that we won't # potentially reveal password information to the # API caller. The real exception is logged above diff --git a/nova/tests/unit/compute/test_compute_mgr.py b/nova/tests/unit/compute/test_compute_mgr.py index e7af9ff8b44d..bcf783db90f6 100644 --- a/nova/tests/unit/compute/test_compute_mgr.py +++ b/nova/tests/unit/compute/test_compute_mgr.py @@ -3749,14 +3749,9 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase): instance=instance, new_pass=None) - if (expected_exception == exception.SetAdminPasswdNotSupported or - expected_exception == exception.InstanceAgentNotEnabled or - expected_exception == NotImplementedError): + if expected_exception != exception.InstancePasswordSetFailed: instance_save_mock.assert_called_once_with( expected_task_state=task_states.UPDATING_PASSWORD) - else: - # setting the instance to error state - instance_save_mock.assert_called_once_with() self.assertEqual(expected_vm_state, instance.vm_state) # check revert_task_state decorator @@ -3774,7 +3769,7 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase): exc = exception.Forbidden('Internal error') expected_exception = exception.InstancePasswordSetFailed self._do_test_set_admin_password_driver_error( - exc, vm_states.ERROR, None, expected_exception) + exc, vm_states.ACTIVE, None, expected_exception) def test_set_admin_password_driver_not_implemented(self): # Ensure expected exception is raised if set_admin_password not