Merge ~raharper/curtin:feature/add-grub-config-options into curtin:master

Proposed by Ryan Harper
Status: Merged
Approved by: Ryan Harper
Approved revision: 3608a15c93a94ff79ba743d8546b18063ec0d5c0
Merge reported by: Server Team CI bot
Merged at revision: not available
Proposed branch: ~raharper/curtin:feature/add-grub-config-options
Merge into: curtin:master
Diff against target: 194 lines (+113/-12)
5 files modified
curtin/commands/curthooks.py (+14/-0)
doc/topics/config.rst (+50/-0)
examples/tests/no-grub-file.yaml (+9/-0)
helpers/common (+13/-12)
tests/vmtests/test_simple.py (+27/-0)
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Approve
Ryan Harper (community) Approve
Chad Smith Approve
Review via email: mp+366078@code.launchpad.net

Commit message

grub: add grub config to control os_prober,terminal settings in target

Curtin by default writes out some overrides to the default grub
behavior that is desirable for a MAAS installed machine. Curtin
now has two other use-cases where these defaults are not the
best choice. When installing a pet-system, it is far more likely
that the user has additional operating systems which they would
prefer to have grub discover and they may have different terminal
settings which make more sense than serial console.

- Add 'probe_additional_os' boolean, defaulting to False, which
  retains the default behavior of curtin for MAAS.
- Add 'terminal' key which will allows users to specify what
  terminal value for grub to use.

To post a comment you must log in.
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Scott Moser (smoser) :
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ryan Harper (raharper) wrote :
Revision history for this message
Ryan Harper (raharper) wrote :

Rebuild, had the wrong branch name.

Revision history for this message
Chad Smith (chad.smith) wrote :

Looks good Ryan, I had a couple of inline comments for your review

Revision history for this message
Ryan Harper (raharper) wrote :

Thanks, applied changes

Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Chad Smith (chad.smith) wrote :

Looks good to me. +1!

review: Approve
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ryan Harper (raharper) wrote :

All but three vmtests passed:

----------------------------------------------------------------------
Ran 4130 tests in 30115.216s

FAILED (SKIP=627, errors=3)
Fri, 10 May 2019 05:11:41 +0000: vmtest end [1] in 30119s

I've re-run those three which pass:

Fri, 10 May 2019 10:15:27 -0500: vmtest start: nosetests3 --process-timeout=86400 --processes=4 -vv --nologcapture tests/vmtests/test_bcache_ceph.py:DiscoTestBcacheCeph tests/vmtests/test_lvm_raid.py:DiscoTestLvmOverRaid tests/vmtests/test_mdadm_bcache.py:DiscoTestAllindata
...
----------------------------------------------------------------------
Ran 43 tests in 567.253s

OK
Fri, 10 May 2019 10:24:55 -0500: vmtest end [0] in 570s

Revision history for this message
Server Team CI bot (server-team-bot) wrote :

FAILED: Autolanding.
More details in the following jenkins job:
https://jenkins.ubuntu.com/server/job/curtin-autoland-test/176/
Executed test runs:
    None: https://jenkins.ubuntu.com/server/job/admin-lp-git-autoland/431/console

review: Needs Fixing (continuous-integration)
Revision history for this message
Ryan Harper (raharper) wrote :

Needed to rebase. Done

review: Approve
Revision history for this message
Server Team CI bot (server-team-bot) :
review: Approve (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/curtin/commands/curthooks.py b/curtin/commands/curthooks.py
2index b6326fb..c4eed5b 100644
3--- a/curtin/commands/curthooks.py
4+++ b/curtin/commands/curthooks.py
5@@ -484,6 +484,20 @@ def setup_grub(cfg, target, osfamily=DISTROS.debian):
6 else:
7 env['REPLACE_GRUB_LINUX_DEFAULT'] = "1"
8
9+ probe_os = grubcfg.get('probe_additional_os', False)
10+ if probe_os not in (False, True):
11+ raise ValueError("Unexpected value %s for 'probe_additional_os'. "
12+ "Value must be boolean" % probe_os)
13+ env['DISABLE_OS_PROBER'] = "0" if probe_os else "1"
14+
15+ # if terminal is present in config, but unset, then don't
16+ grub_terminal = grubcfg.get('terminal', 'console')
17+ if not isinstance(grub_terminal, str):
18+ raise ValueError("Unexpected value %s for 'terminal'. "
19+ "Value must be a string" % grub_terminal)
20+ if not grub_terminal.lower() == "unmodified":
21+ env['GRUB_TERMINAL'] = grub_terminal
22+
23 if instdevs:
24 instdevs = [block.get_dev_name_entry(i)[1] for i in instdevs]
25 else:
26diff --git a/doc/topics/config.rst b/doc/topics/config.rst
27index bad8fc2..b7cca43 100644
28--- a/doc/topics/config.rst
29+++ b/doc/topics/config.rst
30@@ -207,6 +207,27 @@ update the NVRAM settings to preserve the system configuration.
31 Users may want to force NVRAM to be updated such that the next boot
32 of the system will boot from the installed device.
33
34+**probe_additional_os**: *<boolean: default False>*
35+
36+This setting controls grub's os-prober functionality and Curtin will
37+disable this feature by default to prevent grub from searching for other
38+operating systems and adding them to the grub menu.
39+
40+When False, curtin writes "GRUB_DISABLE_OS_PROBER=true" to target system in
41+/etc/default/grub.d/50-curtin-settings.cfg. If True, curtin won't modify the
42+grub configuration value in the target system.
43+
44+**terminal**: *<['unmodified', 'console', ...]>*
45+
46+Configure target system grub option GRUB_TERMINAL ``terminal`` value
47+which is written to /etc/default/grub.d/50-curtin-settings.cfg. Curtin
48+does not attempt to validate this string, grub2 has many values that
49+it accepts and the list is platform dependent. If ``terminal`` is
50+not provided, Curtin will set the value to 'console'. If the ``terminal``
51+value is 'unmodified' then Curtin will not set any value at all and will
52+use Grub defaults.
53+
54+
55 **Example**::
56
57 grub:
58@@ -214,6 +235,35 @@ of the system will boot from the installed device.
59 - /dev/sda1
60 replace_linux_default: False
61 update_nvram: True
62+ terminal: serial
63+
64+**Default terminal value, GRUB_TERMINAL=console**::
65+
66+ grub:
67+ install_devices:
68+ - /dev/sda1
69+
70+**Don't set GRUB_TERMINAL in target**::
71+
72+ grub:
73+ install_devices:
74+ - /dev/sda1
75+ terminal: unmodified
76+
77+**Allow grub to probe for additional OSes**::
78+
79+ grub:
80+ install_devices:
81+ - /dev/sda1
82+ probe_additional_os: True
83+
84+**Avoid writting any settings to etc/default/grub.d/50-curtin-settings.cfg**::
85+
86+ grub:
87+ install_devices:
88+ - /dev/sda1
89+ probe_additional_os: True
90+ terminal: unmodified
91
92
93 http_proxy
94diff --git a/examples/tests/no-grub-file.yaml b/examples/tests/no-grub-file.yaml
95new file mode 100644
96index 0000000..d5ba698
97--- /dev/null
98+++ b/examples/tests/no-grub-file.yaml
99@@ -0,0 +1,9 @@
100+# This pushes curtin through a automatic installation
101+# where no storage configuration is necessary.
102+placeholder_simple_install: unused
103+
104+# configure curtin so it does not emit a grub config file
105+# in etc/default/grub/grub.d
106+grub:
107+ probe_additional_os: true
108+ terminal: unmodified
109diff --git a/helpers/common b/helpers/common
110index 34f0870..5928150 100644
111--- a/helpers/common
112+++ b/helpers/common
113@@ -779,13 +779,6 @@ install_grub() {
114 esac
115 debug 1 "carryover command line params '$newargs'"
116
117- case $os_family in
118- debian)
119- : > "$mp/$mygrub_cfg" ||
120- { error "Failed to write '$mygrub_cfg'"; return 1; }
121- ;;
122- esac
123-
124 if [ "${REPLACE_GRUB_LINUX_DEFAULT:-1}" != "0" ]; then
125 apply_grub_cmdline_linux_default "$mp" "$newargs" || {
126 error "Failed to apply grub cmdline."
127@@ -793,11 +786,19 @@ install_grub() {
128 }
129 fi
130
131- {
132- echo "# Curtin disable grub os prober that might find other OS installs."
133- echo "GRUB_DISABLE_OS_PROBER=true"
134- echo "GRUB_TERMINAL=console"
135- } >> "$mp/$mygrub_cfg"
136+ if [ "${DISABLE_OS_PROBER:-1}" == "1" ]; then
137+ {
138+ echo "# Curtin disable grub os prober that might find other OS installs."
139+ echo "GRUB_DISABLE_OS_PROBER=true"
140+ } >> "$mp/$mygrub_cfg"
141+ fi
142+
143+ if [ -n "${GRUB_TERMINAL}" ]; then
144+ {
145+ echo "# Curtin configured GRUB_TERMINAL value"
146+ echo "GRUB_TERMINAL=${GRUB_TERMINAL}"
147+ } >> "$mp/$mygrub_cfg"
148+ fi
149
150 local short="" bd="" grubdev grubdevs_new=""
151 grubdevs_new=()
152diff --git a/tests/vmtests/test_simple.py b/tests/vmtests/test_simple.py
153index dca75cc..bfac4e9 100644
154--- a/tests/vmtests/test_simple.py
155+++ b/tests/vmtests/test_simple.py
156@@ -4,6 +4,7 @@ from . import VMBaseClass
157 from .releases import base_vm_classes as relbase
158 from .releases import centos_base_vm_classes as centos_relbase
159
160+import os
161 import textwrap
162
163
164@@ -118,4 +119,30 @@ class EoanTestSimpleStorage(relbase.eoan, TestSimpleStorage):
165 def test_output_files_exist(self):
166 self.output_files_exist(["netplan.yaml"])
167
168+
169+class TestGrubNoDefaults(VMBaseClass):
170+ """ Test that curtin does not emit any grub configuration files. """
171+ conf_file = "examples/tests/no-grub-file.yaml"
172+ extra_disks = []
173+ extra_nics = []
174+ extra_collect_scripts = [textwrap.dedent("""
175+ cd OUTPUT_COLLECT_D
176+ cp /etc/netplan/50-cloud-init.yaml netplan.yaml
177+
178+ exit 0
179+ """)]
180+
181+ def test_no_grub_file_created(self):
182+ """ Curtin did not write a grub configuration file. """
183+ grub_d_path = self.collect_path('etc_default_grub_d')
184+ grub_d_files = os.listdir(grub_d_path)
185+ self.assertNotIn('50-curtin-settings.cfg', grub_d_files)
186+
187+
188+class DiscoTestGrubNoDefaults(relbase.disco, TestGrubNoDefaults):
189+ __test__ = True
190+
191+ def test_output_files_exist(self):
192+ self.output_files_exist(["netplan.yaml"])
193+
194 # vi: ts=4 expandtab syntax=python

Subscribers

People subscribed via source and target branches