← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~allenap/maas/kernel-initrd-relpath into lp:maas

 

Gavin Panella has proposed merging lp:~allenap/maas/kernel-initrd-relpath into lp:maas with lp:~allenap/maas/render-pxe-in-tftp-server as a prerequisite.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~allenap/maas/kernel-initrd-relpath/+merge/117812
-- 
https://code.launchpad.net/~allenap/maas/kernel-initrd-relpath/+merge/117812
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~allenap/maas/kernel-initrd-relpath into lp:maas.
=== modified file 'src/provisioningserver/pxe/config.py'
--- src/provisioningserver/pxe/config.py	2012-08-01 22:07:22 +0000
+++ src/provisioningserver/pxe/config.py	2012-08-01 22:07:22 +0000
@@ -20,8 +20,10 @@
     ]
 
 
+from functools import partial
 from os import path
 
+import posixpath
 from provisioningserver.pxe.tftppath import compose_image_path
 import tempita
 
@@ -32,7 +34,7 @@
 
 
 def render_pxe_config(
-    title, arch, subarch, release, purpose, append, **extra):
+    title, arch, subarch, release, purpose, append, bootpath, **extra):
     """Render a PXE configuration file as a unicode string.
 
     :param title: Title that the node should show on its boot menu.
@@ -41,11 +43,17 @@
     :param release: The OS release, e.g. "precise".
     :param purpose: What's the purpose of this boot, e.g. "install".
     :param append: Additional kernel parameters.
+    :param bootpath: The directory path of `pxelinux.0`.
     :param extra: Allow for other arguments. This is a safety valve;
         parameters generated in another component (for example, see
         `TFTPBackend.get_config_reader`) won't cause this to break.
     """
     image_dir = compose_image_path(arch, subarch, release, purpose)
-    return template.substitute(
-        title=title, kernel="%s/kernel" % image_dir,
-        initrd="%s/initrd.gz" % image_dir, append=append)
+    namespace = {
+        "append": append,
+        "initrd": "%s/initrd.gz" % image_dir,
+        "kernel": "%s/kernel" % image_dir,
+        "relpath": partial(posixpath.relpath, start=bootpath),
+        "title": title,
+        }
+    return template.substitute(namespace)

=== modified file 'src/provisioningserver/pxe/config.template'
--- src/provisioningserver/pxe/config.template	2012-07-30 20:57:19 +0000
+++ src/provisioningserver/pxe/config.template	2012-08-01 22:07:22 +0000
@@ -5,8 +5,8 @@
 ONTIMEOUT execute
 
 LABEL execute
-        KERNEL {{kernel}}
-        INITRD {{initrd}}
+        KERNEL {{kernel|relpath}}
+        INITRD {{initrd|relpath}}
         MENU LABEL Continue
         APPEND {{append}}
         IPAPPEND 2

=== modified file 'src/provisioningserver/pxe/tests/test_config.py'
--- src/provisioningserver/pxe/tests/test_config.py	2012-08-01 22:07:22 +0000
+++ src/provisioningserver/pxe/tests/test_config.py	2012-08-01 22:07:22 +0000
@@ -16,6 +16,7 @@
 
 from maastesting.factory import factory
 from maastesting.testcase import TestCase
+import posixpath
 from provisioningserver.pxe.config import render_pxe_config
 from provisioningserver.pxe.tftppath import compose_image_path
 from testtools.matchers import (
@@ -40,6 +41,7 @@
             "purpose": factory.make_name("purpose"),
             "append": factory.make_name("append"),
             }
+        options["bootpath"] = "maas/%(arch)s/%(subarch)s" % options
         output = render_pxe_config(**options)
         # The output is always a Unicode string.
         self.assertThat(output, IsInstance(unicode))
@@ -50,6 +52,7 @@
         image_dir = compose_image_path(
             arch=options["arch"], subarch=options["subarch"],
             release=options["release"], purpose=options["purpose"])
+        image_dir = posixpath.relpath(image_dir, options["bootpath"])
         self.assertThat(
             output, MatchesAll(
                 MatchesRegex(
@@ -73,6 +76,7 @@
             "subarch": factory.make_name("subarch"),
             "release": factory.make_name("release"),
             "purpose": factory.make_name("purpose"),
+            "bootpath": factory.make_name("bootpath"),
             "append": factory.make_name("append"),
             }
         # Capture the output before sprinking in some random options.

=== modified file 'src/provisioningserver/pxe/tests/test_tftppath.py'
--- src/provisioningserver/pxe/tests/test_tftppath.py	2012-07-30 16:21:30 +0000
+++ src/provisioningserver/pxe/tests/test_tftppath.py	2012-08-01 22:07:22 +0000
@@ -43,7 +43,7 @@
         subarch = factory.make_name('subarch')
         name = factory.make_name('config')
         self.assertEqual(
-            '/maas/%s/%s/pxelinux.cfg/%02x-%s' % (
+            'maas/%s/%s/pxelinux.cfg/%02x-%s' % (
                 arch, subarch, ARP_HTYPE.ETHERNET, name),
             compose_config_path(arch, subarch, name))
 
@@ -61,7 +61,7 @@
         release = factory.make_name('release')
         purpose = factory.make_name('purpose')
         self.assertEqual(
-            '/maas/%s/%s/%s/%s' % (arch, subarch, release, purpose),
+            'maas/%s/%s/%s/%s' % (arch, subarch, release, purpose),
             compose_image_path(arch, subarch, release, purpose))
 
     def test_compose_image_path_does_not_include_tftp_root(self):
@@ -77,7 +77,7 @@
         arch = factory.make_name('arch')
         subarch = factory.make_name('subarch')
         self.assertEqual(
-            '/maas/%s/%s/pxelinux.0' % (arch, subarch),
+            'maas/%s/%s/pxelinux.0' % (arch, subarch),
             compose_bootloader_path(arch, subarch))
 
     def test_compose_bootloader_path_does_not_include_tftp_root(self):

=== modified file 'src/provisioningserver/pxe/tftppath.py'
--- src/provisioningserver/pxe/tftppath.py	2012-07-31 08:14:37 +0000
+++ src/provisioningserver/pxe/tftppath.py	2012-08-01 22:07:22 +0000
@@ -24,7 +24,7 @@
 
 def compose_bootloader_path(arch, subarch):
     """Compose the TFTP path for a PXE pre-boot loader."""
-    return '/'.join(['/maas', arch, subarch, 'pxelinux.0'])
+    return '/'.join(['maas', arch, subarch, 'pxelinux.0'])
 
 
 # TODO: move this; it is now only used for testing.
@@ -43,7 +43,7 @@
     # Not using os.path.join: this is a TFTP path, not a native path. Yes, in
     # practice for us they're the same. We always assume that the ARP HTYPE
     # (hardware type) that PXELINUX sends is Ethernet.
-    return "/maas/{arch}/{subarch}/pxelinux.cfg/{htype:02x}-{name}".format(
+    return "maas/{arch}/{subarch}/pxelinux.cfg/{htype:02x}-{name}".format(
         arch=arch, subarch=subarch, htype=ARP_HTYPE.ETHERNET, name=name)
 
 
@@ -61,7 +61,7 @@
     :return: Path for the corresponding image directory (containing a
         kernel and initrd) as exposed over TFTP.
     """
-    return '/'.join(['/maas', arch, subarch, release, purpose])
+    return '/'.join(['maas', arch, subarch, release, purpose])
 
 
 def locate_tftp_path(path, tftproot):