Improve error handling during service level check

The service level check introduced in
Ie15ec8299ae52ae8f5334d591ed3944e9585cf71 should handle the case when a
compute service is wrongly configured with DB credentials. The previous
patch did not handle this and it caused a misleading error at compute
service startup. This patch makes sure that a user friendly warning is
logged in this case then the service level check is done ignoring the DB
configuration and only checking the local cell.

A subsequent patch will add a separate check that fails the compute
service startup in such invalid configuration.

Change-Id: I89cdf3852266ed93a2ac7cd6261fe269932026ac
Related-Bug: #1871482
This commit is contained in:
Balazs Gibizer 2020-11-10 17:26:23 +01:00
parent dc93e3b510
commit 3b44275868
2 changed files with 46 additions and 2 deletions

View File

@ -1267,3 +1267,30 @@ class TestOldComputeCheck(test.NoDBTestCase):
self.assertIn('system', str(ex))
mock_get_min_service.assert_called_once_with(
mock.ANY, ['nova-compute'])
@mock.patch.object(utils.LOG, 'warning')
@mock.patch('nova.objects.service.Service.get_minimum_version')
@mock.patch('nova.objects.service.get_minimum_version_all_cells')
def test_api_db_is_configured_but_the_service_cannot_access_db(
self, mock_get_all, mock_get, mock_warn):
# This is the case when the nova-compute service is wrongly configured
# with db credentials but nova-compute is never allowed to access the
# db directly.
mock_get_all.side_effect = exception.DBNotAllowed(
binary='nova-compute')
oldest = service_obj.SERVICE_VERSION_ALIASES[
service_obj.OLDEST_SUPPORTED_SERVICE_VERSION]
mock_get.return_value = oldest - 1
ex = self.assertRaises(
exception.TooOldComputeService, utils.raise_if_old_compute)
self.assertIn('cell', str(ex))
mock_get_all.assert_called_once_with(mock.ANY, ['nova-compute'])
mock_get.assert_called_once_with(mock.ANY, 'nova-compute')
mock_warn.assert_called_once_with(
'This service is configured for access to the API database but is '
'not allowed to directly access the database. You should run this '
'service without the [api_database]/connection config option. The '
'service version check will only query the local cell.')

View File

@ -1063,8 +1063,25 @@ def raise_if_old_compute():
if CONF.api_database.connection is not None:
scope = 'system'
current_service_version = service.get_minimum_version_all_cells(
ctxt, ['nova-compute'])
try:
current_service_version = service.get_minimum_version_all_cells(
ctxt, ['nova-compute'])
except exception.DBNotAllowed:
# This most likely means we are in a nova-compute service
# configured which is configured with a connection to the API
# database. We should not be attempting to "get out" of our cell to
# look at the minimum versions of nova-compute services in other
# cells, so DBNotAllowed was raised. Leave a warning message
# and fall back to only querying computes in our cell.
LOG.warning(
'This service is configured for access to the API database '
'but is not allowed to directly access the database. You '
'should run this service without the '
'[api_database]/connection config option. The service version '
'check will only query the local cell.')
scope = 'cell'
current_service_version = service.Service.get_minimum_version(
ctxt, 'nova-compute')
else:
scope = 'cell'
# We in a cell so target our query to the current cell only