Merge lp:~jtv/maas/bug-1041318 into lp:maas/trunk

Proposed by Jeroen T. Vermeulen on 2012-08-24
Status: Merged
Approved by: Jeroen T. Vermeulen on 2012-08-27
Approved revision: 932
Merged at revision: 936
Proposed branch: lp:~jtv/maas/bug-1041318
Merge into: lp:maas/trunk
Diff against target: 100 lines (+39/-7)
3 files modified
src/provisioningserver/pxe/config.py (+3/-0)
src/provisioningserver/tests/test_tftp.py (+27/-2)
src/provisioningserver/tftp.py (+9/-5)
To merge this branch: bzr merge lp:~jtv/maas/bug-1041318
Reviewer Review Type Date Requested Status
Gavin Panella (community) 2012-08-24 Approve on 2012-08-24
Review via email: mp+121266@code.launchpad.net

Commit Message

Allow PXE configs to come from TFTP paths starting at “pxelinux.cfg”

Description of the Change

This may help Andres with his upgrade Q/A. He is not running MAAS's DHCP server, and so PXE clients are directed to download “pxelinux.0” (at the TFTP root, not in the “maas” directory).

That works for pxelinux.0 itself (you get the version pxelinux-common installs), but not for the config files. But it looks like the “maas” directory has been more or less abstracted away anyawy, so in this branch I make it optional. It's mostly just a small change to the regex in the TFTPBackend. That will still leave multi-architecture problems, but at least it will support i386 smoothly as a default.

I also added some missing negative tests for the regex. There were no tests to establish that the config-path regex was not matching things it shouldn't.

Jeroen

To post a comment you must log in.
Gavin Panella (allenap) wrote :

> This may help Andres with his upgrade Q/A. He is not running MAAS's
> DHCP server, and so PXE clients are directed to download
> “pxelinux.0” (at the TFTP root, not in the “maas” directory).

Do you have any insight into why this is happening? Is is not possible
to configure the boot filename on Andres' DHCP server? This has a
bearing on our not-managing-DHCP story.

Should we get rid of the bootpath altogether, instead of making it
optional, or does it still serve a purpose? I think its original
purpose was so that MAAS's boot files could coexist alongside other
resources served by the TFTP server. Now that MAAS has a dedicated
server this is largely irrelevant.

review: Approve
Gavin Panella (allenap) wrote :

Some context that I was previously unaware of: Andres has said that
this is a problem for upgrades only, where users are running their own
DHCP servers. Their settings for MAAS in 12.04 will not work with the
current versions. This branch smooths the upgrade.

The question still stands about removing the maas/ prefix entirely.

Julian Edwards (julian-edwards) wrote :

On Friday 24 August 2012 22:04:19 Gavin Panella wrote:
> Some context that I was previously unaware of: Andres has said that
> this is a problem for upgrades only, where users are running their own
> DHCP servers. Their settings for MAAS in 12.04 will not work with the
> current versions. This branch smooths the upgrade.
>
> The question still stands about removing the maas/ prefix entirely.

It doesn't make a lot of sense to keep it, given that it's now optional.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/provisioningserver/pxe/config.py'
2--- src/provisioningserver/pxe/config.py 2012-08-23 22:45:54 +0000
3+++ src/provisioningserver/pxe/config.py 2012-08-24 19:22:22 +0000
4@@ -80,6 +80,9 @@
5 parameters generated in another component (for example, see
6 `TFTPBackend.get_config_reader`) won't cause this to break.
7 """
8+ if bootpath is None:
9+ bootpath = ''
10+
11 template = get_pxe_template(
12 kernel_params.purpose, kernel_params.arch,
13 kernel_params.subarch)
14
15=== modified file 'src/provisioningserver/tests/test_tftp.py'
16--- src/provisioningserver/tests/test_tftp.py 2012-08-24 16:23:15 +0000
17+++ src/provisioningserver/tests/test_tftp.py 2012-08-24 19:22:22 +0000
18@@ -23,7 +23,6 @@
19
20 from maastesting.factory import factory
21 from maastesting.testcase import TestCase
22-import mock
23 from provisioningserver.pxe.tftppath import compose_config_path
24 from provisioningserver.tests.test_kernel_opts import make_kernel_parameters
25 from provisioningserver.tftp import (
26@@ -78,7 +77,7 @@
27 config_path = compose_config_path(components["mac"])
28 return config_path, components
29
30- def test_re_config_file(self):
31+ def test_re_config_file_is_compatible_with_config_path_generator(self):
32 # The regular expression for extracting components of the file path is
33 # compatible with the PXE config path generator.
34 regex = TFTPBackend.re_config_file
35@@ -110,6 +109,32 @@
36 self.assertIsNotNone(match, config_path)
37 self.assertEqual(args, match.groupdict())
38
39+ def test_re_config_file_matches_classic_pxelinux_cfg(self):
40+ # The default config path is simply "pxelinux.cfg" (without
41+ # leading slash). The regex matches this.
42+ mac = 'aa-bb-cc-dd-ee-ff'
43+ match = TFTPBackend.re_config_file.match('pxelinux.cfg/01-%s' % mac)
44+ self.assertIsNotNone(match)
45+ self.assertEqual({'mac': mac, 'bootpath': None}, match.groupdict())
46+
47+ def test_re_config_file_matches_pxelinux_cfg_with_leading_slash(self):
48+ mac = 'aa-bb-cc-dd-ee-ff'
49+ match = TFTPBackend.re_config_file.match('/pxelinux.cfg/01-%s' % mac)
50+ self.assertIsNotNone(match)
51+ self.assertEqual({'mac': mac, 'bootpath': None}, match.groupdict())
52+
53+ def test_re_config_file_does_not_match_non_config_file(self):
54+ self.assertIsNone(
55+ TFTPBackend.re_config_file.match('maas/pxelinux.cfg/kernel'))
56+
57+ def test_re_config_file_does_not_match_file_in_root(self):
58+ self.assertIsNone(
59+ TFTPBackend.re_config_file.match('01-aa-bb-cc-dd-ee-ff'))
60+
61+ def test_re_config_file_does_not_match_file_not_in_pxelinux_cfg(self):
62+ self.assertIsNone(
63+ TFTPBackend.re_config_file.match('foo/01-aa-bb-cc-dd-ee-ff'))
64+
65
66 class TestTFTPBackend(TestCase):
67 """Tests for `provisioningserver.tftp.TFTPBackend`."""
68
69=== modified file 'src/provisioningserver/tftp.py'
70--- src/provisioningserver/tftp.py 2012-08-23 21:31:46 +0000
71+++ src/provisioningserver/tftp.py 2012-08-24 19:22:22 +0000
72@@ -85,11 +85,15 @@
73 # always Ethernet.
74 re_config_file = re.compile(
75 r'''
76+ # Optional leading slash(es).
77 ^/?
78- (?P<bootpath>
79- maas # Static namespacing.
80- ) # Capture boot directory.
81- /
82+ # Optional boot path prefix (separated from the rest by slash):
83+ (?:
84+ (?P<bootpath>
85+ maas
86+ )
87+ /
88+ )?
89 pxelinux[.]cfg # PXELINUX expects this.
90 /
91 {htype:02x} # ARP HTYPE.
92@@ -170,7 +174,7 @@
93 """See `IBackend.get_reader()`.
94
95 If `file_name` matches `re_config_file` then the response is obtained
96- from a remote server. Otherwise the filesystem is used to service the
97+ from a server. Otherwise the filesystem is used to service the
98 response.
99 """
100 config_file_match = self.re_config_file.match(file_name)