Merge "Remove dead set_admin_password code to generate password"
This commit is contained in:
commit
22d7f95e03
@ -4070,7 +4070,7 @@ class API(base.Base):
|
|||||||
|
|
||||||
@check_instance_lock
|
@check_instance_lock
|
||||||
@check_instance_state(vm_state=[vm_states.ACTIVE])
|
@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.
|
"""Set the root/admin password for the given instance.
|
||||||
|
|
||||||
@param context: Nova auth context.
|
@param context: Nova auth context.
|
||||||
|
@ -3949,10 +3949,6 @@ class ComputeManager(manager.Manager):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
context = context.elevated()
|
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)
|
current_power_state = self._get_power_state(context, instance)
|
||||||
expected_state = power_state.RUNNING
|
expected_state = power_state.RUNNING
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
import mock
|
import mock
|
||||||
|
import six
|
||||||
import webob
|
import webob
|
||||||
|
|
||||||
from nova.api.openstack.compute import admin_password as admin_password_v21
|
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):
|
def test_change_password_none(self):
|
||||||
body = {'changePassword': {'adminPass': None}}
|
body = {'changePassword': {'adminPass': None}}
|
||||||
self.assertRaises(self.validation_error,
|
ex = self.assertRaises(self.validation_error,
|
||||||
self._get_action(),
|
self._get_action(),
|
||||||
self.fake_req, fakes.FAKE_UUID, body=body)
|
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):
|
def test_change_password_adminpass_none(self):
|
||||||
body = {'changePassword': None}
|
body = {'changePassword': None}
|
||||||
|
@ -4970,14 +4970,14 @@ class _ComputeAPIUnitTestMixIn(object):
|
|||||||
'set_admin_password')
|
'set_admin_password')
|
||||||
def do_test(compute_rpcapi_mock, record_mock, instance_save_mock):
|
def do_test(compute_rpcapi_mock, record_mock, instance_save_mock):
|
||||||
# call the API
|
# 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
|
# make our assertions
|
||||||
instance_save_mock.assert_called_once_with(
|
instance_save_mock.assert_called_once_with(
|
||||||
expected_task_state=[None])
|
expected_task_state=[None])
|
||||||
record_mock.assert_called_once_with(
|
record_mock.assert_called_once_with(
|
||||||
self.context, instance, instance_actions.CHANGE_PASSWORD)
|
self.context, instance, instance_actions.CHANGE_PASSWORD)
|
||||||
compute_rpcapi_mock.assert_called_once_with(
|
compute_rpcapi_mock.assert_called_once_with(
|
||||||
self.context, instance=instance, new_pass=None)
|
self.context, instance=instance, new_pass='pass')
|
||||||
|
|
||||||
do_test()
|
do_test()
|
||||||
|
|
||||||
|
@ -4369,9 +4369,7 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase,
|
|||||||
@mock.patch('nova.compute.manager.ComputeManager._get_power_state',
|
@mock.patch('nova.compute.manager.ComputeManager._get_power_state',
|
||||||
return_value=power_state.RUNNING)
|
return_value=power_state.RUNNING)
|
||||||
@mock.patch.object(objects.Instance, 'save')
|
@mock.patch.object(objects.Instance, 'save')
|
||||||
@mock.patch('nova.utils.generate_password', return_value='fake-pass')
|
def test_set_admin_password(self, instance_save_mock, power_state_mock):
|
||||||
def test_set_admin_password(self, gen_password_mock, instance_save_mock,
|
|
||||||
power_state_mock):
|
|
||||||
# Ensure instance can have its admin password set.
|
# Ensure instance can have its admin password set.
|
||||||
instance = fake_instance.fake_instance_obj(
|
instance = fake_instance.fake_instance_obj(
|
||||||
self.context,
|
self.context,
|
||||||
@ -4382,7 +4380,8 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase,
|
|||||||
@mock.patch.object(self.compute.driver, 'set_admin_password')
|
@mock.patch.object(self.compute.driver, 'set_admin_password')
|
||||||
def do_test(driver_mock, elevated_mock):
|
def do_test(driver_mock, elevated_mock):
|
||||||
# call the manager method
|
# 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
|
# make our assertions
|
||||||
self.assertEqual(vm_states.ACTIVE, instance.vm_state)
|
self.assertEqual(vm_states.ACTIVE, instance.vm_state)
|
||||||
self.assertIsNone(instance.task_state)
|
self.assertIsNone(instance.task_state)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user