Merge "Fix compute_node_update() compatibility with older clients"

This commit is contained in:
Jenkins
2014-02-17 20:51:29 +00:00
committed by Gerrit Code Review
3 changed files with 30 additions and 4 deletions

View File

@@ -76,7 +76,7 @@ class ConductorManager(manager.Manager):
namespace. See the ComputeTaskManager class for details.
"""
target = messaging.Target(version='1.62')
target = messaging.Target(version='1.63')
def __init__(self, *args, **kwargs):
super(ConductorManager, self).__init__(service_name='conductor',
@@ -455,6 +455,13 @@ class ConductorManager(manager.Manager):
def compute_node_update(self, context, node, values, prune_stats=False):
# NOTE(belliott) prune_stats is no longer relevant and will be
# ignored
if isinstance(values.get('stats'), dict):
# NOTE(danms): In Icehouse, the 'stats' was changed from a dict
# to a JSON string. If we get a dict-based value, convert it to
# JSON, which the lower layers now expect. This can be removed
# in version 2.0 of the RPC API
values['stats'] = jsonutils.dumps(values['stats'])
result = self.db.compute_node_update(context, node['id'], values)
return jsonutils.to_primitive(result)

View File

@@ -122,6 +122,8 @@ class ConductorAPI(object):
security_group_rule_get_by_security_group()
1.61 - Return deleted instance from instance_destroy()
1.62 - Added object_backport()
1.63 - Changed the format of values['stats'] from a dict to a JSON string
in compute_node_update()
"""
VERSION_ALIASES = {
@@ -358,7 +360,13 @@ class ConductorAPI(object):
def compute_node_update(self, context, node, values, prune_stats=False):
node_p = jsonutils.to_primitive(node)
cctxt = self.client.prepare(version='1.33')
if self.client.can_send_version('1.63'):
version = '1.63'
else:
version = '1.33'
if 'stats' in values:
values['stats'] = jsonutils.loads(values['stats'])
cctxt = self.client.prepare(version=version)
return cctxt.call(context, 'compute_node_update',
node=node_p, values=values,
prune_stats=prune_stats)

View File

@@ -347,13 +347,24 @@ class _BaseTestCase(object):
def test_compute_node_update(self):
node = {'id': 'fake-id'}
self.mox.StubOutWithMock(db, 'compute_node_update')
db.compute_node_update(self.context, node['id'], 'fake-values').\
db.compute_node_update(self.context, node['id'], {'fake': 'values'}).\
AndReturn('fake-result')
self.mox.ReplayAll()
result = self.conductor.compute_node_update(self.context, node,
'fake-values', False)
{'fake': 'values'}, False)
self.assertEqual(result, 'fake-result')
def test_compute_node_update_with_non_json_stats(self):
node = {'id': 'fake-id'}
fake_input = {'stats': {'a': 'b'}}
fake_vals = {'stats': jsonutils.dumps(fake_input['stats'])}
self.mox.StubOutWithMock(db, 'compute_node_update')
db.compute_node_update(self.context, node['id'], fake_vals
).AndReturn('fake-result')
self.mox.ReplayAll()
self.conductor.compute_node_update(self.context, node,
fake_input, False)
def test_compute_node_delete(self):
node = {'id': 'fake-id'}
self.mox.StubOutWithMock(db, 'compute_node_delete')