diff --git a/nova/compute/api.py b/nova/compute/api.py index b248cac1c35b..8ec554c5510b 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -4070,7 +4070,7 @@ class API(base.Base): @check_instance_lock @check_instance_state(vm_state=[vm_states.ACTIVE]) - def set_admin_password(self, context, instance, password=None): + def set_admin_password(self, context, instance, password): """Set the root/admin password for the given instance. @param context: Nova auth context. diff --git a/nova/compute/manager.py b/nova/compute/manager.py index fb799894391e..81c7ee51b0ae 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -3949,10 +3949,6 @@ class ComputeManager(manager.Manager): """ context = context.elevated() - if new_pass is None: - # Generate a random password - new_pass = utils.generate_password() - current_power_state = self._get_power_state(context, instance) expected_state = power_state.RUNNING diff --git a/nova/tests/unit/api/openstack/compute/test_admin_password.py b/nova/tests/unit/api/openstack/compute/test_admin_password.py index 0a274b243674..c23b9a73453d 100644 --- a/nova/tests/unit/api/openstack/compute/test_admin_password.py +++ b/nova/tests/unit/api/openstack/compute/test_admin_password.py @@ -14,6 +14,7 @@ # License for the specific language governing permissions and limitations # under the License. import mock +import six import webob from nova.api.openstack.compute import admin_password as admin_password_v21 @@ -122,9 +123,11 @@ class AdminPasswordTestV21(test.NoDBTestCase): def test_change_password_none(self): body = {'changePassword': {'adminPass': None}} - self.assertRaises(self.validation_error, - self._get_action(), - self.fake_req, fakes.FAKE_UUID, body=body) + ex = self.assertRaises(self.validation_error, + self._get_action(), + self.fake_req, fakes.FAKE_UUID, body=body) + self.assertIn('adminPass. Value: None. None is not of type', + six.text_type(ex)) def test_change_password_adminpass_none(self): body = {'changePassword': None} diff --git a/nova/tests/unit/compute/test_compute_api.py b/nova/tests/unit/compute/test_compute_api.py index 51d5a751c6d5..448115fc9db7 100644 --- a/nova/tests/unit/compute/test_compute_api.py +++ b/nova/tests/unit/compute/test_compute_api.py @@ -4970,14 +4970,14 @@ class _ComputeAPIUnitTestMixIn(object): 'set_admin_password') def do_test(compute_rpcapi_mock, record_mock, instance_save_mock): # call the API - self.compute_api.set_admin_password(self.context, instance) + self.compute_api.set_admin_password(self.context, instance, 'pass') # make our assertions instance_save_mock.assert_called_once_with( expected_task_state=[None]) record_mock.assert_called_once_with( self.context, instance, instance_actions.CHANGE_PASSWORD) compute_rpcapi_mock.assert_called_once_with( - self.context, instance=instance, new_pass=None) + self.context, instance=instance, new_pass='pass') do_test() diff --git a/nova/tests/unit/compute/test_compute_mgr.py b/nova/tests/unit/compute/test_compute_mgr.py index e6290db7ffcc..348169e7bd43 100644 --- a/nova/tests/unit/compute/test_compute_mgr.py +++ b/nova/tests/unit/compute/test_compute_mgr.py @@ -4369,9 +4369,7 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase, @mock.patch('nova.compute.manager.ComputeManager._get_power_state', return_value=power_state.RUNNING) @mock.patch.object(objects.Instance, 'save') - @mock.patch('nova.utils.generate_password', return_value='fake-pass') - def test_set_admin_password(self, gen_password_mock, instance_save_mock, - power_state_mock): + def test_set_admin_password(self, instance_save_mock, power_state_mock): # Ensure instance can have its admin password set. instance = fake_instance.fake_instance_obj( self.context, @@ -4382,7 +4380,8 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase, @mock.patch.object(self.compute.driver, 'set_admin_password') def do_test(driver_mock, elevated_mock): # call the manager method - self.compute.set_admin_password(self.context, instance, None) + self.compute.set_admin_password(self.context, instance, + 'fake-pass') # make our assertions self.assertEqual(vm_states.ACTIVE, instance.vm_state) self.assertIsNone(instance.task_state)