From ee42181c5310fce1ead2fefa8084f4689fec799d Mon Sep 17 00:00:00 2001 From: Balazs Gibizer Date: Tue, 27 Jan 2015 14:07:57 +0100 Subject: [PATCH] object: serialize set to list The NovaObjectSerializer is changed to serialize set iterables to list instead of tuple. This was needed to ensure that every rpc driver work in the same way. The normal rpc driver coverts tuples to lists anyhow so this modification does not change the behavior in production. In the functional test environment the fake rpc driver does not change anything on the message and it caused the filter scheduler to receive a tuple in the filter_properties through rpc and failed to append items to it. This change is needed to use the functional test environment for testing the filter scheduler. Change-Id: I889badd85c96e0efadb3bc05f43c47bb995c9dce --- nova/objects/base.py | 10 ++++++---- nova/tests/unit/objects/test_objects.py | 4 ++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/nova/objects/base.py b/nova/objects/base.py index fef9a44..c4c3f9f 100644 --- a/nova/objects/base.py +++ b/nova/objects/base.py @@ -783,11 +783,13 @@ class NovaObjectSerializer(messaging.NoOpSerializer): return iterable(**{k: action_fn(context, v) for k, v in six.iteritems(values)}) else: - # NOTE(danms): A set can't have an unhashable value inside, such as - # a dict. Convert sets to tuples, which is fine, since we can't - # send them over RPC anyway. + # NOTE(danms, gibi) A set can't have an unhashable value inside, + # such as a dict. Convert the set to list, which is fine, since we + # can't send them over RPC anyway. We convert it to list as this + # way there will be no semantic change between the fake rpc driver + # used in functional test and a normal rpc driver. if iterable == set: - iterable = tuple + iterable = list return iterable([action_fn(context, value) for value in values]) def serialize_entity(self, context, entity): diff --git a/nova/tests/unit/objects/test_objects.py b/nova/tests/unit/objects/test_objects.py index 07ed88f..5178da9 100644 --- a/nova/tests/unit/objects/test_objects.py +++ b/nova/tests/unit/objects/test_objects.py @@ -1013,6 +1013,10 @@ class TestObjectSerializer(_BaseTestCase): for thing in (1, 'foo', [1, 2], {'foo': 'bar'}): self.assertEqual(thing, ser.deserialize_entity(None, thing)) + def test_serialize_set_to_list(self): + ser = base.NovaObjectSerializer() + self.assertEqual([1, 2], ser.serialize_entity(None, set([1, 2]))) + def _test_deserialize_entity_newer(self, obj_version, backported_to, my_version='1.6'): ser = base.NovaObjectSerializer()