Fix RPC and Object version pinning on API

The way the API node initializes it requires that all nodes are up and
running for version pinning to work correctly, otherwise it will set
version to None for the RPC clients and the serializers same thing
happens to the scheduler node for the volume rpc.

This is a problem, also on CI, because you cannot guarantee that the API
will start last, and so versions will be incorrect and cause problems in
some cases.

This patch pins RPC client and serializer to the latest known versions
when there are no services on the DB.  This should only happen on CI,
devstack, and similar cases where we start everything for the first time
almost simultaneously.

An alternative that would work for the API would be to make the RPC
client lazily instantiated which solves the problem of load order as no
API requests come in before the other nodes are up and running.

But it would not solve the problem of the scheduler, as it fires a
request to volumes to publish_service_capabilities on start and that
would instantiate the rpc client.

Closes-Bug: #1569350
backport-potential: mitaka
Change-Id: I301c60c4c75cebb4fa6392fe7c9c11cedd1c09c8
This commit is contained in:
Gorka Eguileor 2016-04-13 11:25:15 +02:00
parent 7efb2c6267
commit 8ea9f67b03
5 changed files with 51 additions and 11 deletions

View File

@ -202,6 +202,10 @@ class RPCAPI(object):
# NOTE(dulek): This means that one of the services is Liberty,
# we should cap to it's RPC version.
version_cap = LIBERTY_RPC_VERSIONS[self.BINARY]
elif not version_cap:
# If there is no service we assume they will come up later and will
# have the same version as we do.
version_cap = self.RPC_API_VERSION
LOG.info(_LI('Automatically selected %(binary)s RPC version '
'%(version)s as minimum service version.'),
{'binary': self.BINARY, 'version': version_cap})
@ -215,6 +219,10 @@ class RPCAPI(object):
version_cap = objects.Service.get_minimum_obj_version(
cinder.context.get_admin_context(), self.BINARY)
# If there is no service we assume they will come up later and will
# have the same version as we do.
if not version_cap:
version_cap = base.OBJ_VERSIONS.get_current()
LOG.info(_LI('Automatically selected %(binary)s objects version '
'%(version)s as minimum service version.'),
{'binary': self.BINARY, 'version': version_cap})

View File

@ -70,9 +70,11 @@ class SchedulerManagerTestCase(test.TestCase):
sleep_mock.assert_called_once_with(CONF.periodic_interval)
self.assertFalse(self.manager._startup_delay)
@mock.patch('cinder.objects.service.Service.get_minimum_rpc_version')
@mock.patch('cinder.objects.service.Service.get_minimum_obj_version')
@mock.patch('cinder.rpc.LAST_RPC_VERSIONS', {'cinder-volume': '1.3'})
@mock.patch('cinder.rpc.LAST_OBJ_VERSIONS', {'cinder-volume': '1.5'})
def test_reset(self):
def test_reset(self, get_min_obj, get_min_rpc):
mgr = self.manager_cls()
volume_rpcapi = mgr.driver.volume_rpcapi
@ -82,8 +84,10 @@ class SchedulerManagerTestCase(test.TestCase):
mgr.reset()
volume_rpcapi = mgr.driver.volume_rpcapi
self.assertIsNone(volume_rpcapi.client.version_cap)
self.assertIsNone(volume_rpcapi.client.serializer._base.version_cap)
self.assertEqual(get_min_rpc.return_value,
volume_rpcapi.client.version_cap)
self.assertEqual(get_min_obj.return_value,
volume_rpcapi.client.serializer._base.version_cap)
@mock.patch('cinder.scheduler.driver.Scheduler.'
'update_service_capabilities')

View File

@ -293,11 +293,13 @@ class BackupTestCase(BaseBackupTest):
mock_add_threadpool.assert_has_calls(calls, any_order=True)
self.assertEqual(2, mock_add_threadpool.call_count)
@mock.patch('cinder.objects.service.Service.get_minimum_rpc_version')
@mock.patch('cinder.objects.service.Service.get_minimum_obj_version')
@mock.patch('cinder.rpc.LAST_RPC_VERSIONS', {'cinder-backup': '1.3',
'cinder-volume': '1.7'})
@mock.patch('cinder.rpc.LAST_OBJ_VERSIONS', {'cinder-backup': '1.5',
'cinder-volume': '1.4'})
def test_reset(self):
def test_reset(self, get_min_obj, get_min_rpc):
backup_mgr = manager.BackupManager()
backup_rpcapi = backup_mgr.backup_rpcapi
@ -312,10 +314,14 @@ class BackupTestCase(BaseBackupTest):
backup_rpcapi = backup_mgr.backup_rpcapi
volume_rpcapi = backup_mgr.volume_rpcapi
self.assertIsNone(backup_rpcapi.client.version_cap)
self.assertIsNone(backup_rpcapi.client.serializer._base.version_cap)
self.assertIsNone(volume_rpcapi.client.version_cap)
self.assertIsNone(volume_rpcapi.client.serializer._base.version_cap)
self.assertEqual(get_min_rpc.return_value,
backup_rpcapi.client.version_cap)
self.assertEqual(get_min_obj.return_value,
backup_rpcapi.client.serializer._base.version_cap)
self.assertEqual(get_min_rpc.return_value,
volume_rpcapi.client.version_cap)
self.assertEqual(get_min_obj.return_value,
volume_rpcapi.client.serializer._base.version_cap)
def test_is_working(self):
self.assertTrue(self.backup_mgr.is_working())

View File

@ -14,6 +14,7 @@
import mock
from cinder.objects import base
from cinder import rpc
from cinder import test
@ -64,6 +65,23 @@ class RPCAPITestCase(test.TestCase):
get_client.side_effect = fake_get_client
FakeAPI()
@mock.patch('cinder.objects.Service.get_minimum_rpc_version',
return_value=None)
@mock.patch('cinder.objects.Service.get_minimum_obj_version',
return_value=None)
@mock.patch('cinder.objects.base.CinderObjectSerializer')
@mock.patch('cinder.rpc.get_client')
def test_init_none_caps(self, get_client, serializer, get_min_obj,
get_min_rpc):
"""Test that with no service latest versions are selected."""
FakeAPI()
serializer.assert_called_once_with(base.OBJ_VERSIONS.get_current())
get_client.assert_called_once_with(mock.ANY,
version_cap=FakeAPI.RPC_API_VERSION,
serializer=serializer.return_value)
self.assertTrue(get_min_obj.called)
self.assertTrue(get_min_rpc.called)
@mock.patch('cinder.objects.Service.get_minimum_rpc_version')
@mock.patch('cinder.objects.Service.get_minimum_obj_version')
@mock.patch('cinder.rpc.get_client')

View File

@ -437,9 +437,11 @@ class VolumeTestCase(BaseVolumeTestCase):
self.volume.delete_volume(self.context, vol3['id'])
self.volume.delete_volume(self.context, vol4['id'])
@mock.patch('cinder.objects.service.Service.get_minimum_rpc_version')
@mock.patch('cinder.objects.service.Service.get_minimum_obj_version')
@mock.patch('cinder.rpc.LAST_RPC_VERSIONS', {'cinder-scheduler': '1.3'})
@mock.patch('cinder.rpc.LAST_OBJ_VERSIONS', {'cinder-scheduler': '1.5'})
def test_reset(self):
def test_reset(self, get_min_obj, get_min_rpc):
vol_mgr = vol_manager.VolumeManager()
scheduler_rpcapi = vol_mgr.scheduler_rpcapi
@ -449,8 +451,10 @@ class VolumeTestCase(BaseVolumeTestCase):
vol_mgr.reset()
scheduler_rpcapi = vol_mgr.scheduler_rpcapi
self.assertIsNone(scheduler_rpcapi.client.version_cap)
self.assertIsNone(scheduler_rpcapi.client.serializer._base.version_cap)
self.assertEqual(get_min_rpc.return_value,
scheduler_rpcapi.client.version_cap)
self.assertEqual(get_min_obj.return_value,
scheduler_rpcapi.client.serializer._base.version_cap)
@mock.patch.object(vol_manager.VolumeManager,
'update_service_capabilities')