Cells: Improve invalid hostname handling
The invalid hostnames that Tempest generates for the negative testing don't include cells routing paths. This generates an AttributeError in the cells service which is not handled by the API. This is changed to be a proper NovaException which is caught and handled by the API. Change-Id: I876a23889af1a0cc88f7bf9e81deca4bb32c7fcb
This commit is contained in:
@@ -276,6 +276,7 @@ class CellsManager(manager.Manager):
|
||||
ret_services.append(service)
|
||||
return ret_services
|
||||
|
||||
@oslo_messaging.expected_exceptions(exception.CellRoutingInconsistency)
|
||||
def service_get_by_compute_host(self, ctxt, host_name):
|
||||
"""Return a service entry for a compute host in a certain cell."""
|
||||
cell_name, host_name = cells_utils.split_cell_and_item(host_name)
|
||||
@@ -320,6 +321,7 @@ class CellsManager(manager.Manager):
|
||||
cell_service_id)
|
||||
self.msg_runner.service_delete(ctxt, cell_name, service_id)
|
||||
|
||||
@oslo_messaging.expected_exceptions(exception.CellRoutingInconsistency)
|
||||
def proxy_rpc_to_manager(self, ctxt, topic, rpc_message, call, timeout):
|
||||
"""Proxy an RPC message as-is to a manager."""
|
||||
compute_topic = CONF.compute_topic
|
||||
|
||||
@@ -346,6 +346,11 @@ class _TargetedMessage(_BaseMessage):
|
||||
target_cell = '%s%s%s' % (self.our_path_part,
|
||||
_PATH_CELL_SEP,
|
||||
target_cell.name)
|
||||
# NOTE(alaski): This occurs when hosts are specified with no cells
|
||||
# routing information.
|
||||
if target_cell is None:
|
||||
reason = _('No cell given in routing path.')
|
||||
raise exception.CellRoutingInconsistency(reason=reason)
|
||||
self.target_cell = target_cell
|
||||
self.base_attrs_to_json.append('target_cell')
|
||||
|
||||
|
||||
@@ -509,6 +509,24 @@ class HostAPI(compute_api.HostAPI):
|
||||
"""
|
||||
pass
|
||||
|
||||
def set_host_enabled(self, context, host_name, enabled):
|
||||
try:
|
||||
result = super(HostAPI, self).set_host_enabled(context, host_name,
|
||||
enabled)
|
||||
except exception.CellRoutingInconsistency:
|
||||
raise exception.HostNotFound(host=host_name)
|
||||
|
||||
return result
|
||||
|
||||
def host_power_action(self, context, host_name, action):
|
||||
try:
|
||||
result = super(HostAPI, self).host_power_action(context, host_name,
|
||||
action)
|
||||
except exception.CellRoutingInconsistency:
|
||||
raise exception.HostNotFound(host=host_name)
|
||||
|
||||
return result
|
||||
|
||||
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)
|
||||
@@ -554,8 +572,12 @@ class HostAPI(compute_api.HostAPI):
|
||||
return services
|
||||
|
||||
def service_get_by_compute_host(self, context, host_name):
|
||||
db_service = self.cells_rpcapi.service_get_by_compute_host(context,
|
||||
host_name)
|
||||
try:
|
||||
db_service = self.cells_rpcapi.service_get_by_compute_host(context,
|
||||
host_name)
|
||||
except exception.CellRoutingInconsistency:
|
||||
raise exception.ComputeHostNotFound(host=host_name)
|
||||
|
||||
# NOTE(danms): Currently cells does not support objects as
|
||||
# return values, so just convert the db-formatted service objects
|
||||
# to new-world objects here
|
||||
|
||||
@@ -443,6 +443,16 @@ class CellsMessageClassesTestCase(test.TestCase):
|
||||
self.assertRaises(exception.CellRoutingInconsistency,
|
||||
response.value_or_raise)
|
||||
|
||||
def test_targeted_message_target_cell_none(self):
|
||||
target_cell = None
|
||||
method = 'our_fake_method'
|
||||
method_kwargs = dict(arg=1, arg2=2)
|
||||
direction = 'down'
|
||||
|
||||
self.assertRaises(exception.CellRoutingInconsistency,
|
||||
messaging._TargetedMessage, self.msg_runner, self.ctxt, method,
|
||||
method_kwargs, direction, target_cell, need_response=False)
|
||||
|
||||
def test_broadcast_routing(self):
|
||||
method = 'our_fake_method'
|
||||
method_kwargs = dict(arg1=1, arg2=2)
|
||||
|
||||
Reference in New Issue
Block a user