From 820135933168feeb6320a23555ca0ebf5e14fa08 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Mon, 3 Jun 2013 09:41:01 -0700 Subject: Make instance object tolerate isotime strings Any time we get a db object over RPC, the datetime has been serialized to an isotime string. We have other legacy code that needs to tolerate this, and those hacks would need to be replicated in the objects transition. Instead, make the instance object type function tolerate isotime-formatted strings so that we can more easily convert RPC-transited database objects until we're fully converted, at which time we could remove the tolerance. Luckily, the objects still end up with a datetime internally, which means the rest of the code can stop needing to handle strings and datetimes gracefully. Related to blueprint unified-object-model Change-Id: I132559d3541d19353de6acc36a2740185e564105 --- nova/tests/objects/test_objects.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'nova/tests') diff --git a/nova/tests/objects/test_objects.py b/nova/tests/objects/test_objects.py index 754358230..cbaf8cb17 100644 --- a/nova/tests/objects/test_objects.py +++ b/nova/tests/objects/test_objects.py @@ -123,6 +123,14 @@ class TestUtils(test.TestCase): self.assertEqual(utils.datetime_or_none(None), None) self.assertRaises(ValueError, utils.datetime_or_none, 'foo') + def test_datetime_or_str_or_none(self): + dts = timeutils.isotime() + dt = timeutils.parse_isotime(dts) + self.assertEqual(utils.datetime_or_str_or_none(dt), dt) + self.assertEqual(utils.datetime_or_str_or_none(None), None) + self.assertEqual(utils.datetime_or_str_or_none(dts), dt) + self.assertRaises(ValueError, utils.datetime_or_str_or_none, 'foo') + def test_int_or_none(self): self.assertEqual(utils.int_or_none(1), 1) self.assertEqual(utils.int_or_none('1'), 1) -- cgit