2013/2/4 Iustin Pop <[email protected]>:
> On Mon, Feb 04, 2013 at 02:03:03PM +0100, Michael Hanselmann wrote:
>> - Handle de-serialization correctly when pool is not defined
>> - Don't serialize when the attribute is None (this should never happen
>> in reality as the attribute is always set when de-serializing)
>> - Add tests
>
> LGTM on 1 and 3, but I'm not sure about the second change. Wouldn't it
> be better to serialise it as empty list instead, so that the config is
> directly correct instead of two steps?
Ack, interdiff:
diff --git a/lib/objects.py b/lib/objects.py
index d389336..fc47c84 100644
--- a/lib/objects.py
+++ b/lib/objects.py
@@ -1585,8 +1585,14 @@ class Cluster(TaggableObject):
"""
mydict = super(Cluster, self).ToDict()
- if self.tcpudp_port_pool is not None:
- mydict["tcpudp_port_pool"] = list(self.tcpudp_port_pool)
+
+ if self.tcpudp_port_pool is None:
+ tcpudp_port_pool = []
+ else:
+ tcpudp_port_pool = list(self.tcpudp_port_pool)
+
+ mydict["tcpudp_port_pool"] = tcpudp_port_pool
+
return mydict
@classmethod
diff --git a/test/py/ganeti.objects_unittest.py
b/test/py/ganeti.objects_unittest.py
index dc40c9a..400c32b 100755
--- a/test/py/ganeti.objects_unittest.py
+++ b/test/py/ganeti.objects_unittest.py
@@ -221,7 +221,9 @@ class TestClusterObjectTcpUdpPortPool(unittest.TestCase):
self.assertTrue(objects.Cluster().tcpudp_port_pool is None)
def testSerializingEmpty(self):
- self.assertEqual(objects.Cluster().ToDict(), {})
+ self.assertEqual(objects.Cluster().ToDict(), {
+ "tcpudp_port_pool": [],
+ })
def testSerializing(self):
cluster = objects.Cluster.FromDict({})
Michael