pvl.hosts.dhcp: use pvl.dhcp.config.Field() to format non-string field values
authorTero Marttila <tero.marttila@aalto.fi>
Mon, 02 Mar 2015 19:45:06 +0200
changeset 697 3c3ac207ce3f
parent 696 55796948021e
child 698 656178fb8607
pvl.hosts.dhcp: use pvl.dhcp.config.Field() to format non-string field values
pvl/hosts/dhcp.py
pvl/hosts/tests.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:
--- 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"'),
             ], []),
         ])