Merge "Only warn about not having computes nodes once in rpcapi"

This commit is contained in:
Zuul 2018-12-12 03:35:44 +00:00 committed by Gerrit Code Review
commit 2e5caf9019
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)