Change base rpc version to 1.0 in compute rpcapi.

A recent patch change the RPC_API_VERSION in compute/rpcapi.py to 1.1.
This change was the right thing to do in compute/manager.py, but not
compute/rpcapi.py.  This patch changes it back to 1.0, and changes the
code to only specify that 1.1 is required for the new method.

This version in the rpcapi modules is used as the default version to set
in a message.  The version sent in a message is the minimum version
required to be implemented on the manager side for the message to be
successfully processed.  For most messages, that is just 1.0.  In the
case of the new method, it's 1.1.

This patch also changes the name of his variable in the rpcapi modules
from RPC_API_VERSION to BASE_RPC_API_VERSION to help clarify this a bit
more.

Change-Id: I2bb4602845869bd44b39531eeb4f1e7c0c4c20c2
This commit is contained in:
Russell Bryant
2012-07-12 16:08:14 -04:00
parent 6d9a3e62b0
commit b0377bc6d6
12 changed files with 57 additions and 45 deletions

View File

@@ -33,11 +33,12 @@ class CertAPI(nova.openstack.common.rpc.proxy.RpcProxy):
1.0 - Initial version.
'''
RPC_API_VERSION = '1.0'
BASE_RPC_API_VERSION = '1.0'
def __init__(self):
super(CertAPI, self).__init__(topic=FLAGS.cert_topic,
default_version=self.RPC_API_VERSION)
super(CertAPI, self).__init__(
topic=FLAGS.cert_topic,
default_version=self.BASE_RPC_API_VERSION)
def revoke_certs_by_user(self, ctxt, user_id):
return self.call(ctxt, self.make_msg('revoke_certs_by_user',

View File

@@ -57,11 +57,12 @@ class ComputeAPI(nova.openstack.common.rpc.proxy.RpcProxy):
1.1 - Adds get_host_uptime()
'''
RPC_API_VERSION = '1.1'
BASE_RPC_API_VERSION = '1.0'
def __init__(self):
super(ComputeAPI, self).__init__(topic=FLAGS.compute_topic,
default_version=self.RPC_API_VERSION)
super(ComputeAPI, self).__init__(
topic=FLAGS.compute_topic,
default_version=self.BASE_RPC_API_VERSION)
def add_aggregate_host(self, ctxt, aggregate_id, host_param, host):
'''Add aggregate host.
@@ -316,7 +317,8 @@ class ComputeAPI(nova.openstack.common.rpc.proxy.RpcProxy):
def get_host_uptime(self, ctxt, host):
topic = _compute_topic(self.topic, ctxt, host, None)
return self.call(ctxt, self.make_msg('get_host_uptime'), topic)
return self.call(ctxt, self.make_msg('get_host_uptime'), topic,
version='1.1')
def snapshot_instance(self, ctxt, instance, image_id, image_type,
backup_type, rotation):
@@ -371,11 +373,12 @@ class SecurityGroupAPI(nova.openstack.common.rpc.proxy.RpcProxy):
1.0 - Initial version.
'''
RPC_API_VERSION = '1.0'
BASE_RPC_API_VERSION = '1.0'
def __init__(self):
super(SecurityGroupAPI, self).__init__(topic=FLAGS.compute_topic,
default_version=self.RPC_API_VERSION)
super(SecurityGroupAPI, self).__init__(
topic=FLAGS.compute_topic,
default_version=self.BASE_RPC_API_VERSION)
def refresh_security_group_rules(self, ctxt, security_group_id, host):
self.cast(ctxt, self.make_msg('refresh_security_group_rules',

View File

@@ -33,12 +33,13 @@ class ConsoleAPI(nova.openstack.common.rpc.proxy.RpcProxy):
1.0 - Initial version.
'''
RPC_API_VERSION = '1.0'
BASE_RPC_API_VERSION = '1.0'
def __init__(self, topic=None):
topic = topic if topic else FLAGS.console_topic
super(ConsoleAPI, self).__init__(topic=topic,
default_version=self.RPC_API_VERSION)
super(ConsoleAPI, self).__init__(
topic=topic,
default_version=self.BASE_RPC_API_VERSION)
def add_console(self, ctxt, instance_id):
self.cast(ctxt, self.make_msg('add_console', instance_id=instance_id))

View File

@@ -33,11 +33,12 @@ class ConsoleAuthAPI(nova.openstack.common.rpc.proxy.RpcProxy):
1.0 - Initial version.
'''
RPC_API_VERSION = '1.0'
BASE_RPC_API_VERSION = '1.0'
def __init__(self):
super(ConsoleAuthAPI, self).__init__(topic=FLAGS.consoleauth_topic,
default_version=self.RPC_API_VERSION)
super(ConsoleAuthAPI, self).__init__(
topic=FLAGS.consoleauth_topic,
default_version=self.BASE_RPC_API_VERSION)
def authorize_console(self, ctxt, token, console_type, host, port,
internal_access_path):

View File

@@ -33,11 +33,11 @@ class SchedulerAPI(nova.openstack.common.rpc.proxy.RpcProxy):
1.0 - Initial version.
'''
RPC_API_VERSION = '1.0'
BASE_RPC_API_VERSION = '1.0'
def __init__(self):
super(SchedulerAPI, self).__init__(topic=FLAGS.scheduler_topic,
default_version=self.RPC_API_VERSION)
default_version=self.BASE_RPC_API_VERSION)
def run_instance(self, ctxt, topic, request_spec, admin_password,
injected_files, requested_networks, is_first_time,

View File

@@ -41,7 +41,7 @@ class CertRpcAPITestCase(test.TestCase):
rpcapi = cert_rpcapi.CertAPI()
expected_retval = 'foo'
expected_msg = rpcapi.make_msg(method, **kwargs)
expected_msg['version'] = rpcapi.RPC_API_VERSION
expected_msg['version'] = rpcapi.BASE_RPC_API_VERSION
self.call_ctxt = None
self.call_topic = None

View File

@@ -1452,7 +1452,7 @@ class ComputeTestCase(BaseTestCase):
"args": {'instance_id': inst_ref['id'],
'block_migration': True,
'disk': None},
"version": compute_rpcapi.ComputeAPI.RPC_API_VERSION
"version": compute_rpcapi.ComputeAPI.BASE_RPC_API_VERSION
}, None).AndRaise(rpc.common.RemoteError('', '', ''))
# mocks for rollback
@@ -1464,7 +1464,8 @@ class ComputeTestCase(BaseTestCase):
{"method": "remove_volume_connection",
"args": {'instance_id': inst_ref['id'],
'volume_id': volume_id},
"version": compute_rpcapi.ComputeAPI.RPC_API_VERSION}, None)
"version": compute_rpcapi.ComputeAPI.BASE_RPC_API_VERSION},
None)
rpc.cast(c, topic, {"method": "rollback_live_migration_at_destination",
"args": {'instance_id': inst_ref['id']}})
@@ -1497,7 +1498,8 @@ class ComputeTestCase(BaseTestCase):
"args": {'instance_id': instance_id,
'block_migration': False,
'disk': None},
"version": compute_rpcapi.ComputeAPI.RPC_API_VERSION}, None)
"version": compute_rpcapi.ComputeAPI.BASE_RPC_API_VERSION},
None)
# start test
self.mox.ReplayAll()
@@ -1536,7 +1538,8 @@ class ComputeTestCase(BaseTestCase):
rpc.call(c, rpc.queue_get_for(c, FLAGS.compute_topic, dest),
{"method": "post_live_migration_at_destination",
"args": {'instance_id': i_ref['id'], 'block_migration': False},
"version": compute_rpcapi.ComputeAPI.RPC_API_VERSION}, None)
"version": compute_rpcapi.ComputeAPI.BASE_RPC_API_VERSION},
None)
self.mox.StubOutWithMock(self.compute.driver, 'unplug_vifs')
self.compute.driver.unplug_vifs(i_ref, [])
rpc.call(c, 'network', {'method': 'setup_networks_on_host',
@@ -3514,7 +3517,7 @@ class ComputeAPITestCase(BaseTestCase):
rpc_msg1 = {'method': 'get_vnc_console',
'args': {'instance_uuid': fake_instance['uuid'],
'console_type': fake_console_type},
'version': compute_rpcapi.ComputeAPI.RPC_API_VERSION}
'version': compute_rpcapi.ComputeAPI.BASE_RPC_API_VERSION}
rpc_msg2 = {'method': 'authorize_console',
'args': fake_connect_info,
'version': '1.0'}
@@ -3541,7 +3544,7 @@ class ComputeAPITestCase(BaseTestCase):
rpc_msg = {'method': 'get_console_output',
'args': {'instance_uuid': fake_instance['uuid'],
'tail_length': fake_tail_length},
'version': compute_rpcapi.ComputeAPI.RPC_API_VERSION}
'version': compute_rpcapi.ComputeAPI.BASE_RPC_API_VERSION}
rpc.call(self.context, 'compute.%s' % fake_instance['host'],
rpc_msg, None).AndReturn(fake_console_output)
@@ -4055,7 +4058,7 @@ class ComputeHostAPITestCase(BaseTestCase):
self.assertEqual(call_info['msg'],
{'method': 'set_host_enabled',
'args': {'enabled': 'fake_enabled'},
'version': compute_rpcapi.ComputeAPI.RPC_API_VERSION})
'version': compute_rpcapi.ComputeAPI.BASE_RPC_API_VERSION})
def test_get_host_uptime(self):
ctxt = context.RequestContext('fake', 'fake')
@@ -4068,7 +4071,7 @@ class ComputeHostAPITestCase(BaseTestCase):
self.assertEqual(call_info['msg'],
{'method': 'get_host_uptime',
'args': {},
'version': compute_rpcapi.ComputeAPI.RPC_API_VERSION})
'version': '1.1'})
def test_host_power_action(self):
ctxt = context.RequestContext('fake', 'fake')
@@ -4080,7 +4083,8 @@ class ComputeHostAPITestCase(BaseTestCase):
self.assertEqual(call_info['msg'],
{'method': 'host_power_action',
'args': {'action': 'fake_action'},
'version': compute_rpcapi.ComputeAPI.RPC_API_VERSION})
'version':
compute_rpcapi.ComputeAPI.BASE_RPC_API_VERSION})
def test_set_host_maintenance(self):
ctxt = context.RequestContext('fake', 'fake')
@@ -4092,7 +4096,7 @@ class ComputeHostAPITestCase(BaseTestCase):
self.assertEqual(call_info['msg'],
{'method': 'host_maintenance_mode',
'args': {'host': 'fake_host', 'mode': 'fake_mode'},
'version': compute_rpcapi.ComputeAPI.RPC_API_VERSION})
'version': compute_rpcapi.ComputeAPI.BASE_RPC_API_VERSION})
class KeypairAPITestCase(BaseTestCase):

View File

@@ -52,6 +52,7 @@ class ComputeRpcAPITestCase(test.TestCase):
rpcapi = rpcapi_class()
expected_retval = 'foo' if method == 'call' else None
expected_version = kwargs.pop('version', rpcapi.BASE_RPC_API_VERSION)
expected_msg = rpcapi.make_msg(method, **kwargs)
if 'host_param' in expected_msg['args']:
host_param = expected_msg['args']['host_param']
@@ -70,7 +71,7 @@ class ComputeRpcAPITestCase(test.TestCase):
expected_msg['args']['instance_name'] = instance['name']
else:
expected_msg['args']['instance_uuid'] = instance['uuid']
expected_msg['version'] = rpcapi.RPC_API_VERSION
expected_msg['version'] = expected_version
cast_and_call = ['confirm_resize', 'stop_instance']
if rpc_method == 'call' and method in cast_and_call:
@@ -282,7 +283,8 @@ class ComputeRpcAPITestCase(test.TestCase):
enabled='enabled', host='host')
def test_get_host_uptime(self):
self._test_compute_api('get_host_uptime', 'call', host='host')
self._test_compute_api('get_host_uptime', 'call', host='host',
version='1.1')
def test_snapshot_instance(self):
self._test_compute_api('snapshot_instance', 'cast',

View File

@@ -40,7 +40,7 @@ class ConsoleRpcAPITestCase(test.TestCase):
ctxt = context.RequestContext('fake_user', 'fake_project')
rpcapi = console_rpcapi.ConsoleAPI()
expected_msg = rpcapi.make_msg(method, **kwargs)
expected_msg['version'] = rpcapi.RPC_API_VERSION
expected_msg['version'] = rpcapi.BASE_RPC_API_VERSION
self.cast_ctxt = None
self.cast_topic = None

View File

@@ -41,7 +41,7 @@ class ConsoleAuthRpcAPITestCase(test.TestCase):
rpcapi = consoleauth_rpcapi.ConsoleAuthAPI()
expected_retval = 'foo'
expected_msg = rpcapi.make_msg(method, **kwargs)
expected_msg['version'] = rpcapi.RPC_API_VERSION
expected_msg['version'] = rpcapi.BASE_RPC_API_VERSION
self.call_ctxt = None
self.call_topic = None

View File

@@ -41,7 +41,7 @@ class SchedulerRpcAPITestCase(test.TestCase):
rpcapi = scheduler_rpcapi.SchedulerAPI()
expected_retval = 'foo' if method == 'call' else None
expected_msg = rpcapi.make_msg(method, **kwargs)
expected_msg['version'] = rpcapi.RPC_API_VERSION
expected_msg['version'] = rpcapi.BASE_RPC_API_VERSION
if rpc_method == 'cast' and method == 'run_instance':
kwargs['call'] = False

View File

@@ -476,21 +476,21 @@ class SchedulerTestCase(test.TestCase):
rpc.call(self.context, 'dest_queue',
{'method': 'create_shared_storage_test_file',
'args': {},
'version': compute_rpcapi.ComputeAPI.RPC_API_VERSION}, None
).AndReturn(tmp_filename)
'version': compute_rpcapi.ComputeAPI.BASE_RPC_API_VERSION},
None).AndReturn(tmp_filename)
rpc.queue_get_for(self.context, FLAGS.compute_topic,
instance['host']).AndReturn('src_queue')
rpc.call(self.context, 'src_queue',
{'method': 'check_shared_storage_test_file',
'args': {'filename': tmp_filename},
'version': compute_rpcapi.ComputeAPI.RPC_API_VERSION}, None
).AndReturn(check_result)
'version': compute_rpcapi.ComputeAPI.BASE_RPC_API_VERSION},
None).AndReturn(check_result)
rpc.queue_get_for(self.context, FLAGS.compute_topic,
dest).AndReturn('dest_queue')
rpc.cast(self.context, 'dest_queue',
{'method': 'cleanup_shared_storage_test_file',
'args': {'filename': tmp_filename},
'version': compute_rpcapi.ComputeAPI.RPC_API_VERSION})
'version': compute_rpcapi.ComputeAPI.BASE_RPC_API_VERSION})
def test_live_migration_all_checks_pass(self):
"""Test live migration when all checks pass."""
@@ -535,7 +535,7 @@ class SchedulerTestCase(test.TestCase):
'args': {
'instance_name': instance['name'],
},
'version': compute_rpcapi.ComputeAPI.RPC_API_VERSION,
'version': compute_rpcapi.ComputeAPI.BASE_RPC_API_VERSION,
}
instance_disk_info = [{'disk_size': 1024 * (1024 ** 3)}]
rpc.call(self.context,
@@ -560,8 +560,8 @@ class SchedulerTestCase(test.TestCase):
rpc.call(self.context, 'dest_queue',
{'method': 'compare_cpu',
'args': {'cpu_info': 'fake_cpu_info'},
'version': compute_rpcapi.ComputeAPI.RPC_API_VERSION}, None
).AndReturn(True)
'version': compute_rpcapi.ComputeAPI.BASE_RPC_API_VERSION},
None).AndReturn(True)
db.instance_update_and_get_original(self.context, instance['id'],
{"task_state": task_states.MIGRATING}).AndReturn(
@@ -746,7 +746,7 @@ class SchedulerTestCase(test.TestCase):
'args': {
'instance_name': instance['name'],
},
'version': compute_rpcapi.ComputeAPI.RPC_API_VERSION,
'version': compute_rpcapi.ComputeAPI.BASE_RPC_API_VERSION,
}
instance_disk_info = [{'disk_size': 1024 * (1024 ** 3)}]
rpc.call(self.context,
@@ -926,8 +926,8 @@ class SchedulerTestCase(test.TestCase):
rpc.call(self.context, 'dest_queue',
{'method': 'compare_cpu',
'args': {'cpu_info': 'fake_cpu_info'},
'version': compute_rpcapi.ComputeAPI.RPC_API_VERSION}, None
).AndRaise(rpc_common.RemoteError())
'version': compute_rpcapi.ComputeAPI.BASE_RPC_API_VERSION},
None).AndRaise(rpc_common.RemoteError())
self.mox.ReplayAll()
self.assertRaises(rpc_common.RemoteError,