Merge lp:~smoser/maas/lp1402042 into lp:~maas-committers/maas/trunk

Proposed by Scott Moser
Status: Merged
Approved by: Scott Moser
Approved revision: no longer in the source branch.
Merged at revision: 4080
Proposed branch: lp:~smoser/maas/lp1402042
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 118 lines (+49/-6)
2 files modified
src/provisioningserver/kernel_opts.py (+16/-3)
src/provisioningserver/tests/test_kernel_opts.py (+33/-3)
To merge this branch: bzr merge lp:~smoser/maas/lp1402042
Reviewer Review Type Date Requested Status
Raphaël Badin (community) Approve
Review via email: mp+264049@code.launchpad.net

Commit message

support using '---' as separator for copy-over kernel params

See bug 1402042 for a full description of why this change is necessary.

Description of the change

Suggestions on the variable name are welcome. I'd like to keep it consistent between maas and curtin.

To post a comment you must log in.
Revision history for this message
Raphaël Badin (rvb) wrote :

Looks okay but here are my suggestions for this code: http://paste.ubuntu.com/11841389/
What do you think?

Revision history for this message
Scott Moser (smoser) wrote :

the only comment i have is that CURTIN_KERNEL_CMDLINE_NAME seems not useful.
the name 'KERNEL_CMDLINE_COPY_TO_INSTALL_SEP' is obnoxiously large, but it better describes it.
CURTIN_KERNEL_CMDLINE_NAME doesn't really mean anything if you read that by itself.

i fully accept that this is a bikeshed, but as i said in the description i'd like to have the name stay the same between maas and curtin.

its up to you, i dont really have a strong feelings.

Revision history for this message
Raphaël Badin (rvb) wrote :

> the only comment i have is that CURTIN_KERNEL_CMDLINE_NAME seems not useful.
> the name 'KERNEL_CMDLINE_COPY_TO_INSTALL_SEP' is obnoxiously large, but it
> better describes it.
> CURTIN_KERNEL_CMDLINE_NAME doesn't really mean anything if you read that by
> itself.
>
> i fully accept that this is a bikeshed, but as i said in the description i'd
> like to have the name stay the same between maas and curtin.
>
> its up to you, i dont really have a strong feelings.

Okay, sure, let's rename CURTIN_KERNEL_CMDLINE_NAME.

I agree it's convenient if the names are the same but note that the MAAS instance doesn't need to be exported (aka put in __all__) because this is only used in this module (well, and the tests but that doesn't count).

Revision history for this message
Raphaël Badin (rvb) wrote :

Looks good to me :).

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/provisioningserver/kernel_opts.py'
2--- src/provisioningserver/kernel_opts.py 2015-06-10 11:35:04 +0000
3+++ src/provisioningserver/kernel_opts.py 2015-07-09 13:39:17 +0000
4@@ -21,6 +21,7 @@
5 from collections import namedtuple
6 import os
7
8+import curtin
9 from provisioningserver.drivers import ArchitectureRegistry
10 from provisioningserver.logger import get_maas_logger
11
12@@ -171,6 +172,15 @@
13 return []
14
15
16+CURTIN_KERNEL_CMDLINE_NAME = 'KERNEL_CMDLINE_COPY_TO_INSTALL_SEP'
17+
18+
19+def get_curtin_kernel_cmdline_sep():
20+ """Return the separator for passing extra parameters to the kernel."""
21+ return getattr(
22+ curtin, CURTIN_KERNEL_CMDLINE_NAME, '--')
23+
24+
25 def compose_kernel_command_line(params):
26 """Generate a line of kernel options for booting `node`.
27
28@@ -185,13 +195,16 @@
29 # as it would be nice to have.
30 options += compose_logging_opts(params.log_host)
31 options += compose_arch_opts(params)
32+ cmdline_sep = get_curtin_kernel_cmdline_sep()
33 if params.extra_opts:
34- # Using -- before extra opts makes both d-i and Curtin install
35+ # Using --- before extra opts makes both d-i and Curtin install
36 # them into the grub config when installing an OS, thus causing
37 # the options to "stick" when local booting later.
38- options.append('--')
39+ # see LP: #1402042 for info on '---' versus '--'
40+ options.append(cmdline_sep)
41 options.append(params.extra_opts)
42 kernel_opts = ' '.join(options)
43 maaslog.debug(
44- '%s: kernel parameters -- "%s"' % (params.hostname, kernel_opts))
45+ '%s: kernel parameters %s "%s"' %
46+ (cmdline_sep, params.hostname, kernel_opts))
47 return kernel_opts
48
49=== modified file 'src/provisioningserver/tests/test_kernel_opts.py'
50--- src/provisioningserver/tests/test_kernel_opts.py 2015-05-07 18:14:38 +0000
51+++ src/provisioningserver/tests/test_kernel_opts.py 2015-07-09 13:39:17 +0000
52@@ -20,6 +20,7 @@
53
54 from maastesting.factory import factory
55 from maastesting.testcase import MAASTestCase
56+from mock import sentinel
57 from provisioningserver import kernel_opts
58 from provisioningserver.drivers import (
59 Architecture,
60@@ -29,6 +30,8 @@
61 compose_arch_opts,
62 compose_kernel_command_line,
63 compose_preseed_opt,
64+ CURTIN_KERNEL_CMDLINE_NAME,
65+ get_curtin_kernel_cmdline_sep,
66 get_ephemeral_name,
67 get_last_directory,
68 ISCSI_TARGET_NAME_PREFIX,
69@@ -106,6 +109,29 @@
70 self.assertNotIn('::' + target, full_name)
71
72
73+class TestGetCurtinKernelCmdlineSepTest(MAASTestCase):
74+
75+ def test_get_curtin_kernel_cmdline_sep_returns_curtin_value(self):
76+ sep = factory.make_name('separator')
77+ self.patch(
78+ kernel_opts.curtin, CURTIN_KERNEL_CMDLINE_NAME, sep)
79+ self.assertEqual(sep, get_curtin_kernel_cmdline_sep())
80+
81+ def test_get_curtin_kernel_cmdline_sep_returns_default(self):
82+ original_sep = getattr(
83+ kernel_opts.curtin, CURTIN_KERNEL_CMDLINE_NAME,
84+ sentinel.missing)
85+
86+ if original_sep != sentinel.missing:
87+ def restore_sep():
88+ setattr(
89+ kernel_opts.curtin,
90+ CURTIN_KERNEL_CMDLINE_NAME, original_sep)
91+ self.addCleanup(restore_sep)
92+ delattr(kernel_opts.curtin, CURTIN_KERNEL_CMDLINE_NAME)
93+ self.assertEqual('--', get_curtin_kernel_cmdline_sep())
94+
95+
96 class TestKernelOpts(MAASTestCase):
97
98 def make_kernel_parameters(self, *args, **kwargs):
99@@ -191,12 +217,16 @@
100 "ip=::::%s:BOOTIF" % params.hostname]))
101
102 def test_commissioning_compose_kernel_command_line_inc_extra_opts(self):
103+ mock_get_curtin_sep = self.patch(
104+ kernel_opts, 'get_curtin_kernel_cmdline_sep')
105+ sep = factory.make_name('sep')
106+ mock_get_curtin_sep.return_value = sep
107 extra_opts = "special console=ABCD -- options to pass"
108 params = self.make_kernel_parameters(extra_opts=extra_opts)
109 cmdline = compose_kernel_command_line(params)
110- # There should be a double dash (--) surrounded by spaces before
111- # the options, but otherwise added verbatim.
112- self.assertThat(cmdline, Contains(' -- ' + extra_opts))
113+ # There should be KERNEL_CMDLINE_COPY_TO_INSTALL_SEP surrounded by
114+ # spaces before the options, but otherwise added verbatim.
115+ self.assertThat(cmdline, Contains(' %s ' % sep + extra_opts))
116
117 def test_commissioning_compose_kernel_handles_extra_opts_None(self):
118 params = self.make_kernel_parameters(extra_opts=None)