From 66e1a8b47544e225721f0ccd3a33580dde337793 Mon Sep 17 00:00:00 2001 From: Russell Bryant Date: Wed, 28 Nov 2012 15:43:37 -0500 Subject: Convert datetimes for conductor instance_update. This patch ensures that jsonutils.to_primitive() is used on the updates being sent to conductor's instance_update method. This is primarily so that we convert datetimes to a string using a very specific format defined in the timeutils module. Then, in the conductor manager, convert these fields back into datetime objects using timeutils. The conversion to a string was already happening implicitly if you were using the kombu rpc driver. The reason is that kombu uses anyjson, which we hook in to and will automatically use our own to_primitive() to fix serialization problems for kombu. Doing it explicitly is better, and is required for the other rpc drivers to work. This is to address a problem with sqlite where it would raise an exception when we try to do an update to a datetime field with a string. Fix bug 1084240. Change-Id: I2d703a92df1e85f0f3a7a793b301fe16cbd81ff5 --- nova/tests/conductor/test_conductor.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'nova/tests') diff --git a/nova/tests/conductor/test_conductor.py b/nova/tests/conductor/test_conductor.py index d3c555822..3dcfe0209 100644 --- a/nova/tests/conductor/test_conductor.py +++ b/nova/tests/conductor/test_conductor.py @@ -25,6 +25,7 @@ from nova import db from nova.db.sqlalchemy import models from nova import notifications from nova.openstack.common import jsonutils +from nova.openstack.common import timeutils from nova import test @@ -156,7 +157,10 @@ class ConductorPolicyTest(test.TestCase): conductor = conductor_api.LocalAPI() updates = {} for key in conductor_manager.allowed_updates: - updates[key] = 'foo' + if key in conductor_manager.datetime_fields: + updates[key] = timeutils.utcnow() + else: + updates[key] = 'foo' conductor.instance_update(ctxt, 'fake-instance', **updates) def test_allowed_keys_are_real(self): -- cgit