Make compute rpcapi version calculation check all cells

For top-level services, the compute rpcapi module needs to check for the
minimum version of nova-compute in all cells in order to function
properly during an upgrade. This moves that module to use the all-cells
variant of this routine in the case where [api_database]/connection is
set.

Change-Id: Icddbe4760eaff30e4e13c1e8d3d5d3f489dac3c4
Closes-Bug: #1807044
This commit is contained in:
Dan Smith 2018-12-06 08:07:37 -08:00
parent 183f6238c1
commit d779b33d72
2 changed files with 35 additions and 10 deletions

View File

@ -386,8 +386,15 @@ class ComputeAPI(object):
global NO_COMPUTES_WARNING
if LAST_VERSION:
return LAST_VERSION
service_version = objects.Service.get_minimum_version(
context.get_admin_context(), 'nova-compute')
# NOTE(danms): If we have a connection to the api database,
# we should iterate all cells. If not, we must only look locally.
if CONF.api_database.connection:
service_version = service_obj.get_minimum_version_all_cells(
context.get_admin_context(), ['nova-compute'])
else:
service_version = objects.Service.get_minimum_version(
context.get_admin_context(), 'nova-compute')
history = service_obj.SERVICE_VERSION_HISTORY

View File

@ -66,16 +66,16 @@ class ComputeRpcAPITestCase(test.NoDBTestCase):
self.patcher1.stop()
self.patcher2.stop()
@mock.patch('nova.objects.Service.get_minimum_version')
@mock.patch('nova.objects.service.get_minimum_version_all_cells')
def test_auto_pin(self, mock_get_min):
mock_get_min.return_value = 1
self.flags(compute='auto', group='upgrade_levels')
compute_rpcapi.LAST_VERSION = None
rpcapi = compute_rpcapi.ComputeAPI()
self.assertEqual('4.4', rpcapi.router.version_cap)
mock_get_min.assert_called_once_with(mock.ANY, 'nova-compute')
mock_get_min.assert_called_once_with(mock.ANY, ['nova-compute'])
@mock.patch('nova.objects.Service.get_minimum_version')
@mock.patch('nova.objects.service.get_minimum_version_all_cells')
def test_auto_pin_fails_if_too_old(self, mock_get_min):
mock_get_min.return_value = 1955
self.flags(compute='auto', group='upgrade_levels')
@ -83,7 +83,7 @@ class ComputeRpcAPITestCase(test.NoDBTestCase):
self.assertRaises(exception.ServiceTooOld,
compute_rpcapi.ComputeAPI)
@mock.patch('nova.objects.Service.get_minimum_version')
@mock.patch('nova.objects.service.get_minimum_version_all_cells')
def test_auto_pin_with_service_version_zero(self, mock_get_min):
mock_get_min.return_value = 0
self.flags(compute='auto', group='upgrade_levels')
@ -92,17 +92,17 @@ class ComputeRpcAPITestCase(test.NoDBTestCase):
history = service_obj.SERVICE_VERSION_HISTORY
current_version = history[service_obj.SERVICE_VERSION]['compute_rpc']
self.assertEqual(current_version, rpcapi.router.version_cap)
mock_get_min.assert_called_once_with(mock.ANY, 'nova-compute')
mock_get_min.assert_called_once_with(mock.ANY, ['nova-compute'])
self.assertIsNone(compute_rpcapi.LAST_VERSION)
@mock.patch('nova.objects.Service.get_minimum_version')
@mock.patch('nova.objects.service.get_minimum_version_all_cells')
def test_auto_pin_caches(self, mock_get_min):
mock_get_min.return_value = 1
self.flags(compute='auto', group='upgrade_levels')
compute_rpcapi.LAST_VERSION = None
compute_rpcapi.ComputeAPI()
compute_rpcapi.ComputeAPI()
mock_get_min.assert_called_once_with(mock.ANY, 'nova-compute')
mock_get_min.assert_called_once_with(mock.ANY, ['nova-compute'])
self.assertEqual('4.4', compute_rpcapi.LAST_VERSION)
def _test_compute_api(self, method, rpc_method,
@ -591,7 +591,10 @@ class ComputeRpcAPITestCase(test.NoDBTestCase):
@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):
@mock.patch('nova.objects.service.get_minimum_version_all_cells')
def test_version_cap_no_computes_log_once(self, mock_allcells, mock_minver,
mock_log):
self.flags(connection=None, group='api_database')
self.flags(compute='auto', group='upgrade_levels')
mock_minver.return_value = 0
compute_rpcapi.NO_COMPUTES_WARNING = False
@ -599,3 +602,18 @@ class ComputeRpcAPITestCase(test.NoDBTestCase):
compute_rpcapi.ComputeAPI()
compute_rpcapi.ComputeAPI()
self.assertEqual(1, mock_log.debug.call_count)
mock_allcells.assert_not_called()
mock_minver.assert_has_calls([
mock.call(mock.ANY, 'nova-compute'),
mock.call(mock.ANY, 'nova-compute')])
@mock.patch('nova.objects.Service.get_minimum_version')
@mock.patch('nova.objects.service.get_minimum_version_all_cells')
def test_version_cap_all_cells(self, mock_allcells, mock_minver):
self.flags(connection='sqlite:///', group='api_database')
self.flags(compute='auto', group='upgrade_levels')
compute_rpcapi.LAST_VERSION = None
mock_allcells.return_value = 0
compute_rpcapi.ComputeAPI()
mock_allcells.assert_called_once_with(mock.ANY, ['nova-compute'])
mock_minver.assert_not_called()