Add get_backdoor_port to console.
This adds a get_backdoor_port function to the console service which enables returning the eventlet_backdoor port from rpc for the service. Change-Id: I3cb7d199fac8c10e4b5fdc04c403b63e75a69d2d
This commit is contained in:
@@ -68,3 +68,8 @@ class API(base.Base):
|
||||
else:
|
||||
instance = self.db.instance_get(context, instance_uuid)
|
||||
return instance
|
||||
|
||||
def get_backdoor_port(self, context, host):
|
||||
topic = self._get_console_topic(context, host)
|
||||
rpcapi = console_rpcapi.ConsoleAPI(topic=topic)
|
||||
return rpcapi.get_backdoor_port(context, host)
|
||||
|
||||
@@ -52,7 +52,7 @@ class ConsoleProxyManager(manager.Manager):
|
||||
|
||||
"""
|
||||
|
||||
RPC_API_VERSION = '1.0'
|
||||
RPC_API_VERSION = '1.1'
|
||||
|
||||
def __init__(self, console_driver=None, *args, **kwargs):
|
||||
if not console_driver:
|
||||
@@ -132,3 +132,6 @@ class ConsoleProxyManager(manager.Manager):
|
||||
pool_info['compute_host'] = instance_host
|
||||
pool = self.db.console_pool_create(context, pool_info)
|
||||
return pool
|
||||
|
||||
def get_backdoor_port(self, context):
|
||||
return self.backdoor_port
|
||||
|
||||
@@ -31,6 +31,7 @@ class ConsoleAPI(nova.openstack.common.rpc.proxy.RpcProxy):
|
||||
API version history:
|
||||
|
||||
1.0 - Initial version.
|
||||
1.1 - Added get_backdoor_port()
|
||||
'''
|
||||
|
||||
#
|
||||
@@ -54,3 +55,7 @@ class ConsoleAPI(nova.openstack.common.rpc.proxy.RpcProxy):
|
||||
|
||||
def remove_console(self, ctxt, console_id):
|
||||
self.cast(ctxt, self.make_msg('remove_console', console_id=console_id))
|
||||
|
||||
def get_backdoor_port(self, ctxt, host):
|
||||
return self.call(ctxt, self.make_msg('get_backdoor_port'),
|
||||
version='1.1')
|
||||
|
||||
@@ -185,3 +185,13 @@ class ConsoleAPITestCase(test.TestCase):
|
||||
self.mox.ReplayAll()
|
||||
|
||||
self.console_api.create_console(self.context, self.fake_uuid)
|
||||
|
||||
def test_get_backdoor_port(self):
|
||||
self.mox.StubOutWithMock(console_rpcapi.ConsoleAPI,
|
||||
'get_backdoor_port')
|
||||
|
||||
console_rpcapi.ConsoleAPI.get_backdoor_port(self.context, 'fake_host')
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
self.console_api.get_backdoor_port(self.context, 'fake_host')
|
||||
|
||||
@@ -29,31 +29,43 @@ CONF.import_opt('console_topic', 'nova.config')
|
||||
|
||||
|
||||
class ConsoleRpcAPITestCase(test.TestCase):
|
||||
def _test_console_api(self, method, **kwargs):
|
||||
def _test_console_api(self, method, rpc_method, **kwargs):
|
||||
ctxt = context.RequestContext('fake_user', 'fake_project')
|
||||
rpcapi = console_rpcapi.ConsoleAPI()
|
||||
expected_retval = 'foo' if method == 'call' else None
|
||||
expected_version = kwargs.pop('version', rpcapi.BASE_RPC_API_VERSION)
|
||||
expected_msg = rpcapi.make_msg(method, **kwargs)
|
||||
expected_msg['version'] = rpcapi.BASE_RPC_API_VERSION
|
||||
expected_msg['version'] = expected_version
|
||||
|
||||
self.cast_ctxt = None
|
||||
self.cast_topic = None
|
||||
self.cast_msg = None
|
||||
if method == 'get_backdoor_port':
|
||||
del expected_msg['args']['host']
|
||||
|
||||
def _fake_cast(_ctxt, _topic, _msg):
|
||||
self.cast_ctxt = _ctxt
|
||||
self.cast_topic = _topic
|
||||
self.cast_msg = _msg
|
||||
self.fake_args = None
|
||||
self.fake_kwargs = None
|
||||
|
||||
self.stubs.Set(rpc, 'cast', _fake_cast)
|
||||
def _fake_rpc_method(*args, **kwargs):
|
||||
self.fake_args = args
|
||||
self.fake_kwargs = kwargs
|
||||
if expected_retval:
|
||||
return expected_retval
|
||||
|
||||
getattr(rpcapi, method)(ctxt, **kwargs)
|
||||
self.stubs.Set(rpc, rpc_method, _fake_rpc_method)
|
||||
|
||||
self.assertEqual(self.cast_ctxt, ctxt)
|
||||
self.assertEqual(self.cast_topic, CONF.console_topic)
|
||||
self.assertEqual(self.cast_msg, expected_msg)
|
||||
retval = getattr(rpcapi, method)(ctxt, **kwargs)
|
||||
|
||||
self.assertEqual(retval, expected_retval)
|
||||
expected_args = [ctxt, CONF.console_topic, expected_msg]
|
||||
for arg, expected_arg in zip(self.fake_args, expected_args):
|
||||
self.assertEqual(arg, expected_arg)
|
||||
|
||||
def test_add_console(self):
|
||||
self._test_console_api('add_console', instance_id='i')
|
||||
self._test_console_api('add_console', instance_id='i',
|
||||
rpc_method='cast')
|
||||
|
||||
def test_remove_console(self):
|
||||
self._test_console_api('remove_console', console_id='i')
|
||||
self._test_console_api('remove_console', console_id='i',
|
||||
rpc_method='cast')
|
||||
|
||||
def test_get_backdoor_port(self):
|
||||
self._test_console_api('get_backdoor_port', host='fake_host',
|
||||
rpc_method='call', version='1.1')
|
||||
|
||||
Reference in New Issue
Block a user