pvl.hosts.dhcp: fix and test boot= variations
authorTero Marttila <tero.marttila@aalto.fi>
Thu, 26 Feb 2015 15:53:57 +0200
changeset 491 cfcb47a3dc3e
parent 490 805645dbb9bb
child 492 ddd13dadf6a8
pvl.hosts.dhcp: fix and test boot= variations
pvl/hosts/dhcp.py
pvl/hosts/tests.py
--- a/pvl/hosts/dhcp.py	Thu Feb 26 15:42:01 2015 +0200
+++ b/pvl/hosts/dhcp.py	Thu Feb 26 15:53:57 2015 +0200
@@ -17,14 +17,14 @@
       
     if not host.boot:
         next_server = filename = None
+    elif host.boot.startswith('/'):
+        next_server = None
+        filename = host.boot[1:]
+    elif host.boot.endswith(':'):
+        next_server = host.boot[:-1]
+        filename = None
     elif ':' in host.boot :
         next_server, filename = host.boot.split(':', 1)
-    elif host.boot.startswith('/') :
-        next_server = None
-        filename = host.boot
-    elif host.boot.endswith(':') :
-        next_server = host.boot
-        filename = None
     else :
         raise HostError(host, "invalid boot={host.boot}".format(host=host))
 
--- a/pvl/hosts/tests.py	Thu Feb 26 15:42:01 2015 +0200
+++ b/pvl/hosts/tests.py	Thu Feb 26 15:53:57 2015 +0200
@@ -450,18 +450,38 @@
         ])
 
     def testHostBoot(self):
-        host = Host.build('foo', 'test',
-                ethernet    = '00:11:22:33:44:55',
-                boot        = 'boot.lan:debian/wheezy/pxelinux.0',
-        )
+        hosts = [
+                Host.build('foo1', 'test',
+                        ethernet    = '00:11:22:33:44:55',
+                        boot        = 'boot.lan:debian/wheezy/pxelinux.0',
+                ),
+                Host.build('foo2', 'test',
+                        ethernet    = '00:11:22:33:44:55',
+                        boot        = 'boot.lan:',
+                ),
+                Host.build('foo3', 'test',
+                        ethernet    = '00:11:22:33:44:55',
+                        boot        = '/debian/wheezy/pxelinux.0',
+                ),
+        ]
 
-        self.assertBlocksEqual(list(dhcp.dhcp_host(host)), [
-            (('host', 'foo'), [
-                ('option', 'host-name', "foo"),
+        self.assertBlocksEqual(list(dhcp.dhcp_hosts(hosts)), [
+            (('host', 'foo1'), [
+                ('option', 'host-name', "foo1"),
                 ('hardware', 'ethernet', '00:11:22:33:44:55'),
                 ('next-server', 'boot.lan'),
                 ('filename', 'debian/wheezy/pxelinux.0'),
-            ], None)
+            ], None),
+            (('host', 'foo2'), [
+                ('option', 'host-name', "foo2"),
+                ('hardware', 'ethernet', '00:11:22:33:44:55'),
+                ('next-server', 'boot.lan'),
+            ], None),
+            (('host', 'foo3'), [
+                ('option', 'host-name', "foo3"),
+                ('hardware', 'ethernet', '00:11:22:33:44:55'),
+                ('filename', 'debian/wheezy/pxelinux.0'),
+            ], None),
         ])
 
     def testHosts(self):