# HG changeset patch # User Tero Marttila # Date 1425318306 -7200 # Node ID 3c3ac207ce3ffe404a3918ae0cc61e7eaae2d2eb # Parent 55796948021e32feccf0941cc786b37c649edfdf pvl.hosts.dhcp: use pvl.dhcp.config.Field() to format non-string field values diff -r 55796948021e -r 3c3ac207ce3f pvl/hosts/dhcp.py --- a/pvl/hosts/dhcp.py Mon Mar 02 19:43:38 2015 +0200 +++ b/pvl/hosts/dhcp.py Mon Mar 02 19:45:06 2015 +0200 @@ -10,10 +10,10 @@ """ yield 'option', 'host-name', host.name - yield 'hardware', 'ethernet', ethernet + yield 'hardware', 'ethernet', pvl.dhcp.config.Field(ethernet) if host.ip: - yield 'fixed-address', str(host.ip) + yield 'fixed-address', pvl.dhcp.config.Field(str(host.ip)) for bootopt in ('next-server', 'filename'): if bootopt in host.boot: diff -r 55796948021e -r 3c3ac207ce3f pvl/hosts/tests.py --- a/pvl/hosts/tests.py Mon Mar 02 19:43:38 2015 +0200 +++ b/pvl/hosts/tests.py Mon Mar 02 19:45:06 2015 +0200 @@ -624,7 +624,12 @@ class TestDhcp(unittest.TestCase): def assertBlockEqual(self, block, (key, items, blocks)): self.assertEqual(block.key, key) - self.assertItemsEqual(block.items, items) + + for _item, item in itertools.izip_longest(sorted(block.items), sorted(items)): + self.assertIsNotNone(_item, item) + self.assertIsNotNone(item, _item) + + self.assertEqual(tuple(pvl.dhcp.config.quote(field) for field in _item), item) for _block, expect_block in itertools.izip_longest(block.blocks, blocks): self.assertBlockEqual(_block, expect_block) @@ -659,7 +664,7 @@ self.assertBlocksEqual(list(dhcp.dhcp_host(host)), [ (('host', 'foo.test'), [ - ('option', 'host-name', "foo.test"), + ('option', 'host-name', '"foo.test"'), ('fixed-address', '192.0.2.1'), ('hardware', 'ethernet', '00:11:22:33:44:55'), ], []) @@ -710,24 +715,24 @@ (('host', 'foo1'), [ ('option', 'host-name', "foo1"), ('hardware', 'ethernet', '00:11:22:33:44:55'), - ('next-server', 'boot.lan'), - ('filename', 'debian/wheezy/pxelinux.0'), + ('next-server', '"boot.lan"'), + ('filename', '"debian/wheezy/pxelinux.0"'), ], []), (('host', 'foo2'), [ ('option', 'host-name', "foo2"), ('hardware', 'ethernet', '00:11:22:33:44:55'), - ('next-server', 'boot.lan'), + ('next-server', '"boot.lan"'), ], []), (('host', 'foo3'), [ ('option', 'host-name', "foo3"), ('hardware', 'ethernet', '00:11:22:33:44:55'), - ('filename', '/debian/wheezy/pxelinux.0'), + ('filename', '"/debian/wheezy/pxelinux.0"'), ], []), (('host', 'foo4'), [ ('option', 'host-name', "foo4"), ('hardware', 'ethernet', '00:11:22:33:44:55'), - ('next-server', 'boot.lan'), - ('filename', '/debian/wheezy/pxelinux.0'), + ('next-server', '"boot.lan"'), + ('filename', '"/debian/wheezy/pxelinux.0"'), ], []), ])