Implements host uptime API call for cell setup.
Fixes bug os-hypervisors/<id>/uptime fails in cell setup.Implements 'get_host_uptime' for cells_api, which returns hypervisor uptime from the target child cell. Fixes bug LP 1192911 Change-Id: Iac75e46e565f17c91117dcb810f6d2f2e62708d8
This commit is contained in:
@@ -65,7 +65,7 @@ class CellsManager(manager.Manager):
|
||||
|
||||
Scheduling requests get passed to the scheduler class.
|
||||
"""
|
||||
RPC_API_VERSION = '1.16'
|
||||
RPC_API_VERSION = '1.17'
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
# Mostly for tests.
|
||||
@@ -261,6 +261,18 @@ class CellsManager(manager.Manager):
|
||||
cells_utils.add_cell_to_service(service, response.cell_name)
|
||||
return service
|
||||
|
||||
def get_host_uptime(self, ctxt, host_name):
|
||||
"""
|
||||
Return host uptime for a compute host in a certain cell
|
||||
|
||||
:param host_name: fully qualified hostname. It should be in format of
|
||||
parent!child@host_id
|
||||
"""
|
||||
cell_name, host_name = cells_utils.split_cell_and_item(host_name)
|
||||
response = self.msg_runner.get_host_uptime(ctxt, cell_name,
|
||||
host_name)
|
||||
return response.value_or_raise()
|
||||
|
||||
def service_update(self, ctxt, host_name, binary, params_to_update):
|
||||
"""
|
||||
Used to enable/disable a service. For compute services, setting to
|
||||
|
||||
@@ -852,6 +852,9 @@ class _TargetedMessageMethods(_BaseMessageMethods):
|
||||
"""Resume an instance via compute_api.suspend()."""
|
||||
self._call_compute_api_with_obj(message.ctxt, instance, 'resume')
|
||||
|
||||
def get_host_uptime(self, message, host_name):
|
||||
return self.host_api.get_host_uptime(message.ctxt, host_name)
|
||||
|
||||
|
||||
class _BroadcastMessageMethods(_BaseMessageMethods):
|
||||
"""These are the methods that can be called as a part of a broadcast
|
||||
@@ -1368,6 +1371,14 @@ class MessageRunner(object):
|
||||
need_response=True)
|
||||
return message.process()
|
||||
|
||||
def get_host_uptime(self, ctxt, cell_name, host_name):
|
||||
method_kwargs = dict(host_name=host_name)
|
||||
message = _TargetedMessage(self, ctxt,
|
||||
'get_host_uptime',
|
||||
method_kwargs, 'down', cell_name,
|
||||
need_response=True)
|
||||
return message.process()
|
||||
|
||||
def service_update(self, ctxt, cell_name, host_name, binary,
|
||||
params_to_update):
|
||||
"""
|
||||
|
||||
@@ -73,6 +73,7 @@ class CellsAPI(rpc_proxy.RpcProxy):
|
||||
1.14 - Adds reboot_instance()
|
||||
1.15 - Adds suspend_instance() and resume_instance()
|
||||
1.16 - Adds instance_update_from_api()
|
||||
1.17 - Adds get_host_uptime()
|
||||
'''
|
||||
BASE_RPC_API_VERSION = '1.0'
|
||||
|
||||
@@ -224,6 +225,14 @@ class CellsAPI(rpc_proxy.RpcProxy):
|
||||
host_name=host_name),
|
||||
version='1.2')
|
||||
|
||||
def get_host_uptime(self, context, host_name):
|
||||
"""Gets the host uptime in a particular cell. The cell name should
|
||||
be encoded within the host_name
|
||||
"""
|
||||
return self.call(context, self.make_msg('get_host_uptime',
|
||||
host_name=host_name),
|
||||
version='1.17')
|
||||
|
||||
def service_update(self, ctxt, host_name, binary, params_to_update):
|
||||
"""
|
||||
Used to enable/disable a service. For compute services, setting to
|
||||
|
||||
@@ -579,6 +579,10 @@ class HostAPI(compute_api.HostAPI):
|
||||
"""
|
||||
pass
|
||||
|
||||
def get_host_uptime(self, context, host_name):
|
||||
"""Returns the result of calling "uptime" on the target host."""
|
||||
return self.cells_rpcapi.get_host_uptime(context, host_name)
|
||||
|
||||
def service_get_all(self, context, filters=None, set_zones=False):
|
||||
if filters is None:
|
||||
filters = {}
|
||||
|
||||
@@ -304,6 +304,24 @@ class CellsManagerClassTestCase(test.TestCase):
|
||||
host_name=cell_and_host)
|
||||
self.assertEqual(expected_response, response)
|
||||
|
||||
def test_get_host_uptime(self):
|
||||
fake_cell = 'parent!fake-cell'
|
||||
fake_host = 'fake-host'
|
||||
fake_cell_and_host = cells_utils.cell_with_item(fake_cell, fake_host)
|
||||
host_uptime = (" 08:32:11 up 93 days, 18:25, 12 users, load average:"
|
||||
" 0.20, 0.12, 0.14")
|
||||
fake_response = messaging.Response(fake_cell, host_uptime, False)
|
||||
|
||||
self.mox.StubOutWithMock(self.msg_runner,
|
||||
'get_host_uptime')
|
||||
self.msg_runner.get_host_uptime(self.ctxt, fake_cell, fake_host).\
|
||||
AndReturn(fake_response)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
response = self.cells_manager.get_host_uptime(self.ctxt,
|
||||
fake_cell_and_host)
|
||||
self.assertEqual(host_uptime, response)
|
||||
|
||||
def test_service_update(self):
|
||||
fake_cell = 'fake-cell'
|
||||
fake_response = messaging.Response(
|
||||
|
||||
@@ -640,6 +640,7 @@ class CellsTargetedMethodsTestCase(test.TestCase):
|
||||
methods_cls = self.tgt_msg_runner.methods_by_type['targeted']
|
||||
self.tgt_methods_cls = methods_cls
|
||||
self.tgt_compute_api = methods_cls.compute_api
|
||||
self.tgt_host_api = methods_cls.host_api
|
||||
self.tgt_db_inst = methods_cls.db
|
||||
self.tgt_c_rpcapi = methods_cls.compute_rpcapi
|
||||
|
||||
@@ -1202,6 +1203,20 @@ class CellsTargetedMethodsTestCase(test.TestCase):
|
||||
def test_resume_instance(self):
|
||||
self._test_instance_action_method('resume', (), {}, (), {}, False)
|
||||
|
||||
def test_get_host_uptime(self):
|
||||
host_name = "fake-host"
|
||||
host_uptime = (" 08:32:11 up 93 days, 18:25, 12 users, load average:"
|
||||
" 0.20, 0.12, 0.14")
|
||||
self.mox.StubOutWithMock(self.tgt_host_api, 'get_host_uptime')
|
||||
self.tgt_host_api.get_host_uptime(self.ctxt, host_name).\
|
||||
AndReturn(host_uptime)
|
||||
self.mox.ReplayAll()
|
||||
response = self.src_msg_runner.get_host_uptime(self.ctxt,
|
||||
self.tgt_cell_name,
|
||||
host_name)
|
||||
expected_host_uptime = response.value_or_raise()
|
||||
self.assertEqual(host_uptime, expected_host_uptime)
|
||||
|
||||
|
||||
class CellsBroadcastMethodsTestCase(test.TestCase):
|
||||
"""Test case for _BroadcastMessageMethods class. Most of these
|
||||
|
||||
@@ -276,6 +276,16 @@ class CellsAPITestCase(test.TestCase):
|
||||
version='1.2')
|
||||
self.assertEqual(result, 'fake_response')
|
||||
|
||||
def test_get_host_uptime(self):
|
||||
call_info = self._stub_rpc_method('call', 'fake_response')
|
||||
result = self.cells_rpcapi.get_host_uptime(
|
||||
self.fake_context, host_name='fake-host-name')
|
||||
expected_args = {'host_name': 'fake-host-name'}
|
||||
self._check_result(call_info, 'get_host_uptime',
|
||||
expected_args,
|
||||
version='1.17')
|
||||
self.assertEqual(result, 'fake_response')
|
||||
|
||||
def test_service_update(self):
|
||||
call_info = self._stub_rpc_method('call', 'fake_response')
|
||||
result = self.cells_rpcapi.service_update(
|
||||
|
||||
@@ -402,3 +402,14 @@ class ComputeHostAPICellsTestCase(ComputeHostAPITestCase):
|
||||
# The corresponing Compute test case depends on the
|
||||
# _assert_host_exists which is a no-op in the cells api
|
||||
pass
|
||||
|
||||
def test_get_host_uptime(self):
|
||||
self.mox.StubOutWithMock(self.host_api.cells_rpcapi,
|
||||
'get_host_uptime')
|
||||
|
||||
self.host_api.cells_rpcapi.get_host_uptime(self.ctxt,
|
||||
'fake-host'). \
|
||||
AndReturn('fake-response')
|
||||
self.mox.ReplayAll()
|
||||
result = self.host_api.get_host_uptime(self.ctxt, 'fake-host')
|
||||
self.assertEqual('fake-response', result)
|
||||
|
||||
@@ -37,6 +37,7 @@ from nova.cells import rpcapi as cells_rpcapi
|
||||
from nova.cells import state
|
||||
from nova.cloudpipe import pipelib
|
||||
from nova.compute import api as compute_api
|
||||
from nova.compute import cells_api as cells_api
|
||||
from nova.compute import manager as compute_manager
|
||||
from nova import context
|
||||
from nova import db
|
||||
@@ -74,6 +75,7 @@ CONF.import_opt('vpn_image_id', 'nova.cloudpipe.pipelib')
|
||||
CONF.import_opt('osapi_compute_link_prefix', 'nova.api.openstack.common')
|
||||
CONF.import_opt('osapi_glance_link_prefix', 'nova.api.openstack.common')
|
||||
CONF.import_opt('enable', 'nova.cells.opts', group='cells')
|
||||
CONF.import_opt('cell_type', 'nova.cells.opts', group='cells')
|
||||
CONF.import_opt('db_check_interval', 'nova.cells.state', group='cells')
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
@@ -3629,6 +3631,40 @@ class HypervisorsSampleXmlTests(HypervisorsSampleJsonTests):
|
||||
ctype = "xml"
|
||||
|
||||
|
||||
class HypervisorsCellsSampleJsonTests(ApiSampleTestBase):
|
||||
extension_name = ("nova.api.openstack.compute.contrib.hypervisors."
|
||||
"Hypervisors")
|
||||
|
||||
def setUp(self):
|
||||
self.flags(enable=True, cell_type='api', group='cells')
|
||||
super(HypervisorsCellsSampleJsonTests, self).setUp()
|
||||
|
||||
def test_hypervisor_uptime(self):
|
||||
fake_hypervisor = {'service': {'host': 'fake-mini'}, 'id': 1,
|
||||
'hypervisor_hostname': 'fake-mini'}
|
||||
|
||||
def fake_get_host_uptime(self, context, hyp):
|
||||
return (" 08:32:11 up 93 days, 18:25, 12 users, load average:"
|
||||
" 0.20, 0.12, 0.14")
|
||||
|
||||
def fake_compute_node_get(self, context, hyp):
|
||||
return fake_hypervisor
|
||||
|
||||
self.stubs.Set(cells_api.HostAPI, 'compute_node_get',
|
||||
fake_compute_node_get)
|
||||
|
||||
self.stubs.Set(cells_api.HostAPI,
|
||||
'get_host_uptime', fake_get_host_uptime)
|
||||
hypervisor_id = fake_hypervisor['id']
|
||||
response = self._do_get('os-hypervisors/%s/uptime' % hypervisor_id)
|
||||
subs = {'hypervisor_id': hypervisor_id}
|
||||
self._verify_response('hypervisors-uptime-resp', subs, response, 200)
|
||||
|
||||
|
||||
class HypervisorsCellsSampleXmlTests(HypervisorsCellsSampleJsonTests):
|
||||
ctype = "xml"
|
||||
|
||||
|
||||
class AttachInterfacesSampleJsonTest(ServersSampleBase):
|
||||
extension_name = ('nova.api.openstack.compute.contrib.attach_interfaces.'
|
||||
'Attach_interfaces')
|
||||
|
||||
Reference in New Issue
Block a user