Only warn about not having computes nodes once in rpcapi

When we instantiate the compute rpcapi, with upgrade_levels=auto,
we determine the minimum service version of nova-compute. If we
find no computes, we log a message. This may be known, if we are
starting at zero day and no computes have started, but may also
indicate a more serious problem. In either case, logging this once
per process (especially in the case of multi-worker, multi-module
services) is more than enough.

Change-Id: I3350026c872a548839b857c53529c1dbbb88091c
Related-Bug: #1807044
This commit is contained in:
Dan Smith 2018-12-06 07:56:04 -08:00
parent c9dca64fa6
commit 183f6238c1
2 changed files with 20 additions and 4 deletions

View File

@ -34,6 +34,7 @@ RPC_TOPIC = "compute"
LOG = logging.getLogger(__name__)
LAST_VERSION = None
NO_COMPUTES_WARNING = False
def _compute_host(host, instance):
@ -382,6 +383,7 @@ class ComputeAPI(object):
def _determine_version_cap(self, target):
global LAST_VERSION
global NO_COMPUTES_WARNING
if LAST_VERSION:
return LAST_VERSION
service_version = objects.Service.get_minimum_version(
@ -394,10 +396,13 @@ class ComputeAPI(object):
# this result, because we will get a better answer next time.
# As a sane default, return the current version.
if service_version == 0:
LOG.debug("Not caching compute RPC version_cap, because min "
"service_version is 0. Please ensure a nova-compute "
"service has been started. Defaulting to current "
"version.")
if not NO_COMPUTES_WARNING:
# NOTE(danms): Only show this warning once
LOG.debug("Not caching compute RPC version_cap, because min "
"service_version is 0. Please ensure a nova-compute "
"service has been started. Defaulting to current "
"version.")
NO_COMPUTES_WARNING = True
return history[service_obj.SERVICE_VERSION]['compute_rpc']
try:

View File

@ -588,3 +588,14 @@ class ComputeRpcAPITestCase(test.NoDBTestCase):
return result
return _test()
@mock.patch('nova.compute.rpcapi.LOG')
@mock.patch('nova.objects.Service.get_minimum_version')
def test_version_cap_no_computes_log_once(self, mock_minver, mock_log):
self.flags(compute='auto', group='upgrade_levels')
mock_minver.return_value = 0
compute_rpcapi.NO_COMPUTES_WARNING = False
compute_rpcapi.LAST_VERSION = None
compute_rpcapi.ComputeAPI()
compute_rpcapi.ComputeAPI()
self.assertEqual(1, mock_log.debug.call_count)