Merge "Cells: Update set_admin_password for objects"

This commit is contained in:
Jenkins
2014-09-15 21:54:33 +00:00
committed by Gerrit Code Review
8 changed files with 49 additions and 10 deletions

View File

@@ -73,7 +73,7 @@ class CellsManager(manager.Manager):
Scheduling requests get passed to the scheduler class.
"""
target = oslo_messaging.Target(version='1.28')
target = oslo_messaging.Target(version='1.29')
def __init__(self, *args, **kwargs):
LOG.warn(_('The cells feature of Nova is considered experimental '
@@ -547,3 +547,6 @@ class CellsManager(manager.Manager):
self.msg_runner.rebuild_instance(ctxt, instance, image_href,
admin_password, files_to_inject,
preserve_ephemeral, kwargs)
def set_admin_password(self, ctxt, instance, new_pass):
self.msg_runner.set_admin_password(ctxt, instance, new_pass)

View File

@@ -951,6 +951,10 @@ class _TargetedMessageMethods(_BaseMessageMethods):
image_href, admin_password,
files_to_inject, **kwargs)
def set_admin_password(self, message, instance, new_pass):
self._call_compute_api_with_obj(message.ctxt, instance,
'set_admin_password', new_pass)
class _BroadcastMessageMethods(_BaseMessageMethods):
"""These are the methods that can be called as a part of a broadcast
@@ -1806,6 +1810,10 @@ class MessageRunner(object):
self._instance_action(ctxt, instance, 'rebuild_instance',
extra_kwargs=extra_kwargs)
def set_admin_password(self, ctxt, instance, new_pass):
self._instance_action(ctxt, instance, 'set_admin_password',
extra_kwargs={'new_pass': new_pass})
@staticmethod
def get_message_types():
return _CELL_MESSAGE_TYPE_TO_MESSAGE_CLS.keys()

View File

@@ -96,6 +96,7 @@ class CellsAPI(object):
can handle the version_cap being set to 1.27.
* 1.28 - Make bdm_update_or_create_at_top and use bdm objects
* 1.29 - Adds set_admin_password()
'''
VERSION_ALIASES = {
@@ -607,3 +608,11 @@ class CellsAPI(object):
instance=instance, image_href=image_ref,
admin_password=new_pass, files_to_inject=injected_files,
preserve_ephemeral=preserve_ephemeral, kwargs=kwargs)
def set_admin_password(self, ctxt, instance, new_pass):
if not CONF.cells.enable:
return
cctxt = self.client.prepare(version='1.29')
cctxt.cast(ctxt, 'set_admin_password', instance=instance,
new_pass=new_pass)

View File

@@ -2706,6 +2706,7 @@ class API(base.Base):
@wrap_check_policy
@check_instance_lock
@check_instance_cell
@check_instance_state(vm_state=[vm_states.ACTIVE])
def set_admin_password(self, context, instance, password=None):
"""Set the root/admin password for the given instance.

View File

@@ -49,7 +49,8 @@ class ComputeRPCAPIRedirect(object):
'unpause_instance', 'revert_resize',
'confirm_resize', 'reset_network',
'inject_network_info',
'backup_instance', 'snapshot_instance']
'backup_instance', 'snapshot_instance',
'set_admin_password']
def __init__(self, cells_rpcapi):
self.cells_rpcapi = cells_rpcapi
@@ -335,14 +336,6 @@ class ComputeCellsAPI(compute_api.API):
super(ComputeCellsAPI, self).unshelve(context, instance)
self._cast_to_cells(context, instance, 'unshelve')
@check_instance_cell
def set_admin_password(self, context, instance, password=None):
"""Set the root/admin password for the given instance."""
super(ComputeCellsAPI, self).set_admin_password(context, instance,
password=password)
self._cast_to_cells(context, instance, 'set_admin_password',
password=password)
@wrap_check_policy
@check_instance_cell
def get_vnc_console(self, context, instance, console_type):

View File

@@ -798,3 +798,11 @@ class CellsManagerClassTestCase(test.NoDBTestCase):
image_id='fake-id',
backup_type='backup-type',
rotation='rotation')
def test_set_admin_password(self):
with mock.patch.object(self.msg_runner,
'set_admin_password') as set_admin_password:
self.cells_manager.set_admin_password(self.ctxt,
instance='fake-instance', new_pass='fake-password')
set_admin_password.assert_called_once_with(self.ctxt,
'fake-instance', 'fake-password')

View File

@@ -1247,6 +1247,7 @@ class CellsTargetedMethodsTestCase(test.TestCase):
'confirm_resize': 'confirm_resize',
'reset_network': 'reset_network',
'inject_network_info': 'inject_network_info',
'set_admin_password': 'set_admin_password',
}
tgt_method = method_translations.get(method,
'%s_instance' % method)
@@ -1400,6 +1401,11 @@ class CellsTargetedMethodsTestCase(test.TestCase):
backup_type='backup-type',
rotation='rotation')
def test_set_admin_password(self):
args = ['fake-password']
self._test_instance_action_method('set_admin_password', args, {}, args,
{}, False)
class CellsBroadcastMethodsTestCase(test.TestCase):
"""Test case for _BroadcastMessageMethods class. Most of these

View File

@@ -747,3 +747,14 @@ class CellsAPITestCase(test.NoDBTestCase):
'rotation': 'rotation'}
self._check_result(call_info, 'backup_instance',
expected_args, version='1.24')
def test_set_admin_password(self):
call_info = self._stub_rpc_method('cast', None)
self.cells_rpcapi.set_admin_password(self.fake_context,
'fake-instance', 'fake-password')
expected_args = {'instance': 'fake-instance',
'new_pass': 'fake-password'}
self._check_result(call_info, 'set_admin_password',
expected_args, version='1.29')