Revision 4d36fbf4
b/lib/objects.py | ||
---|---|---|
1623 | 1623 |
|
1624 | 1624 |
""" |
1625 | 1625 |
mydict = super(Cluster, self).ToDict() |
1626 |
mydict["tcpudp_port_pool"] = list(self.tcpudp_port_pool) |
|
1626 |
|
|
1627 |
if self.tcpudp_port_pool is None: |
|
1628 |
tcpudp_port_pool = [] |
|
1629 |
else: |
|
1630 |
tcpudp_port_pool = list(self.tcpudp_port_pool) |
|
1631 |
|
|
1632 |
mydict["tcpudp_port_pool"] = tcpudp_port_pool |
|
1633 |
|
|
1627 | 1634 |
return mydict |
1628 | 1635 |
|
1629 | 1636 |
@classmethod |
... | ... | |
1632 | 1639 |
|
1633 | 1640 |
""" |
1634 | 1641 |
obj = super(Cluster, cls).FromDict(val) |
1635 |
if not isinstance(obj.tcpudp_port_pool, set): |
|
1642 |
|
|
1643 |
if obj.tcpudp_port_pool is None: |
|
1644 |
obj.tcpudp_port_pool = set() |
|
1645 |
elif not isinstance(obj.tcpudp_port_pool, set): |
|
1636 | 1646 |
obj.tcpudp_port_pool = set(obj.tcpudp_port_pool) |
1647 |
|
|
1637 | 1648 |
return obj |
1638 | 1649 |
|
1639 | 1650 |
def SimpleFillDP(self, diskparams): |
b/test/py/ganeti.objects_unittest.py | ||
---|---|---|
216 | 216 |
self.assertEqual(self.fake_cl.primary_hypervisor, constants.HT_CHROOT) |
217 | 217 |
|
218 | 218 |
|
219 |
class TestClusterObjectTcpUdpPortPool(unittest.TestCase): |
|
220 |
def testNewCluster(self): |
|
221 |
self.assertTrue(objects.Cluster().tcpudp_port_pool is None) |
|
222 |
|
|
223 |
def testSerializingEmpty(self): |
|
224 |
self.assertEqual(objects.Cluster().ToDict(), { |
|
225 |
"tcpudp_port_pool": [], |
|
226 |
}) |
|
227 |
|
|
228 |
def testSerializing(self): |
|
229 |
cluster = objects.Cluster.FromDict({}) |
|
230 |
self.assertEqual(cluster.tcpudp_port_pool, set()) |
|
231 |
|
|
232 |
cluster.tcpudp_port_pool.add(3546) |
|
233 |
cluster.tcpudp_port_pool.add(62511) |
|
234 |
|
|
235 |
data = cluster.ToDict() |
|
236 |
self.assertEqual(data.keys(), ["tcpudp_port_pool"]) |
|
237 |
self.assertEqual(sorted(data["tcpudp_port_pool"]), sorted([3546, 62511])) |
|
238 |
|
|
239 |
def testDeserializingEmpty(self): |
|
240 |
cluster = objects.Cluster.FromDict({}) |
|
241 |
self.assertEqual(cluster.tcpudp_port_pool, set()) |
|
242 |
|
|
243 |
def testDeserialize(self): |
|
244 |
cluster = objects.Cluster.FromDict({ |
|
245 |
"tcpudp_port_pool": [26214, 10039, 267], |
|
246 |
}) |
|
247 |
self.assertEqual(cluster.tcpudp_port_pool, set([26214, 10039, 267])) |
|
248 |
|
|
249 |
|
|
219 | 250 |
class TestOS(unittest.TestCase): |
220 | 251 |
ALL_DATA = [ |
221 | 252 |
"debootstrap", |
Also available in: Unified diff