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
diff --git a/curtin/commands/curthooks.py b/curtin/commands/curthooks.py
index b6326fb..c4eed5b 100644
--- a/curtin/commands/curthooks.py
+++ b/curtin/commands/curthooks.py
@@ -484,6 +484,20 @@ def setup_grub(cfg, target, osfamily=DISTROS.debian):
484 else:484 else:
485 env['REPLACE_GRUB_LINUX_DEFAULT'] = "1"485 env['REPLACE_GRUB_LINUX_DEFAULT'] = "1"
486486
487 probe_os = grubcfg.get('probe_additional_os', False)
488 if probe_os not in (False, True):
489 raise ValueError("Unexpected value %s for 'probe_additional_os'. "
490 "Value must be boolean" % probe_os)
491 env['DISABLE_OS_PROBER'] = "0" if probe_os else "1"
492
493 # if terminal is present in config, but unset, then don't
494 grub_terminal = grubcfg.get('terminal', 'console')
495 if not isinstance(grub_terminal, str):
496 raise ValueError("Unexpected value %s for 'terminal'. "
497 "Value must be a string" % grub_terminal)
498 if not grub_terminal.lower() == "unmodified":
499 env['GRUB_TERMINAL'] = grub_terminal
500
487 if instdevs:501 if instdevs:
488 instdevs = [block.get_dev_name_entry(i)[1] for i in instdevs]502 instdevs = [block.get_dev_name_entry(i)[1] for i in instdevs]
489 else:503 else:
diff --git a/doc/topics/config.rst b/doc/topics/config.rst
index bad8fc2..b7cca43 100644
--- a/doc/topics/config.rst
+++ b/doc/topics/config.rst
@@ -207,6 +207,27 @@ update the NVRAM settings to preserve the system configuration.
207Users may want to force NVRAM to be updated such that the next boot207Users may want to force NVRAM to be updated such that the next boot
208of the system will boot from the installed device.208of the system will boot from the installed device.
209209
210**probe_additional_os**: *<boolean: default False>*
211
212This setting controls grub's os-prober functionality and Curtin will
213disable this feature by default to prevent grub from searching for other
214operating systems and adding them to the grub menu.
215
216When False, curtin writes "GRUB_DISABLE_OS_PROBER=true" to target system in
217/etc/default/grub.d/50-curtin-settings.cfg. If True, curtin won't modify the
218grub configuration value in the target system.
219
220**terminal**: *<['unmodified', 'console', ...]>*
221
222Configure target system grub option GRUB_TERMINAL ``terminal`` value
223which is written to /etc/default/grub.d/50-curtin-settings.cfg. Curtin
224does not attempt to validate this string, grub2 has many values that
225it accepts and the list is platform dependent. If ``terminal`` is
226not provided, Curtin will set the value to 'console'. If the ``terminal``
227value is 'unmodified' then Curtin will not set any value at all and will
228use Grub defaults.
229
230
210**Example**::231**Example**::
211232
212 grub:233 grub:
@@ -214,6 +235,35 @@ of the system will boot from the installed device.
214 - /dev/sda1235 - /dev/sda1
215 replace_linux_default: False236 replace_linux_default: False
216 update_nvram: True237 update_nvram: True
238 terminal: serial
239
240**Default terminal value, GRUB_TERMINAL=console**::
241
242 grub:
243 install_devices:
244 - /dev/sda1
245
246**Don't set GRUB_TERMINAL in target**::
247
248 grub:
249 install_devices:
250 - /dev/sda1
251 terminal: unmodified
252
253**Allow grub to probe for additional OSes**::
254
255 grub:
256 install_devices:
257 - /dev/sda1
258 probe_additional_os: True
259
260**Avoid writting any settings to etc/default/grub.d/50-curtin-settings.cfg**::
261
262 grub:
263 install_devices:
264 - /dev/sda1
265 probe_additional_os: True
266 terminal: unmodified
217267
218268
219http_proxy269http_proxy
diff --git a/examples/tests/no-grub-file.yaml b/examples/tests/no-grub-file.yaml
220new file mode 100644270new file mode 100644
index 0000000..d5ba698
--- /dev/null
+++ b/examples/tests/no-grub-file.yaml
@@ -0,0 +1,9 @@
1# This pushes curtin through a automatic installation
2# where no storage configuration is necessary.
3placeholder_simple_install: unused
4
5# configure curtin so it does not emit a grub config file
6# in etc/default/grub/grub.d
7grub:
8 probe_additional_os: true
9 terminal: unmodified
diff --git a/helpers/common b/helpers/common
index 34f0870..5928150 100644
--- a/helpers/common
+++ b/helpers/common
@@ -779,13 +779,6 @@ install_grub() {
779 esac779 esac
780 debug 1 "carryover command line params '$newargs'"780 debug 1 "carryover command line params '$newargs'"
781781
782 case $os_family in
783 debian)
784 : > "$mp/$mygrub_cfg" ||
785 { error "Failed to write '$mygrub_cfg'"; return 1; }
786 ;;
787 esac
788
789 if [ "${REPLACE_GRUB_LINUX_DEFAULT:-1}" != "0" ]; then782 if [ "${REPLACE_GRUB_LINUX_DEFAULT:-1}" != "0" ]; then
790 apply_grub_cmdline_linux_default "$mp" "$newargs" || {783 apply_grub_cmdline_linux_default "$mp" "$newargs" || {
791 error "Failed to apply grub cmdline."784 error "Failed to apply grub cmdline."
@@ -793,11 +786,19 @@ install_grub() {
793 }786 }
794 fi787 fi
795788
796 {789 if [ "${DISABLE_OS_PROBER:-1}" == "1" ]; then
797 echo "# Curtin disable grub os prober that might find other OS installs."790 {
798 echo "GRUB_DISABLE_OS_PROBER=true"791 echo "# Curtin disable grub os prober that might find other OS installs."
799 echo "GRUB_TERMINAL=console"792 echo "GRUB_DISABLE_OS_PROBER=true"
800 } >> "$mp/$mygrub_cfg"793 } >> "$mp/$mygrub_cfg"
794 fi
795
796 if [ -n "${GRUB_TERMINAL}" ]; then
797 {
798 echo "# Curtin configured GRUB_TERMINAL value"
799 echo "GRUB_TERMINAL=${GRUB_TERMINAL}"
800 } >> "$mp/$mygrub_cfg"
801 fi
801802
802 local short="" bd="" grubdev grubdevs_new=""803 local short="" bd="" grubdev grubdevs_new=""
803 grubdevs_new=()804 grubdevs_new=()
diff --git a/tests/vmtests/test_simple.py b/tests/vmtests/test_simple.py
index dca75cc..bfac4e9 100644
--- a/tests/vmtests/test_simple.py
+++ b/tests/vmtests/test_simple.py
@@ -4,6 +4,7 @@ from . import VMBaseClass
4from .releases import base_vm_classes as relbase4from .releases import base_vm_classes as relbase
5from .releases import centos_base_vm_classes as centos_relbase5from .releases import centos_base_vm_classes as centos_relbase
66
7import os
7import textwrap8import textwrap
89
910
@@ -118,4 +119,30 @@ class EoanTestSimpleStorage(relbase.eoan, TestSimpleStorage):
118 def test_output_files_exist(self):119 def test_output_files_exist(self):
119 self.output_files_exist(["netplan.yaml"])120 self.output_files_exist(["netplan.yaml"])
120121
122
123class TestGrubNoDefaults(VMBaseClass):
124 """ Test that curtin does not emit any grub configuration files. """
125 conf_file = "examples/tests/no-grub-file.yaml"
126 extra_disks = []
127 extra_nics = []
128 extra_collect_scripts = [textwrap.dedent("""
129 cd OUTPUT_COLLECT_D
130 cp /etc/netplan/50-cloud-init.yaml netplan.yaml
131
132 exit 0
133 """)]
134
135 def test_no_grub_file_created(self):
136 """ Curtin did not write a grub configuration file. """
137 grub_d_path = self.collect_path('etc_default_grub_d')
138 grub_d_files = os.listdir(grub_d_path)
139 self.assertNotIn('50-curtin-settings.cfg', grub_d_files)
140
141
142class DiscoTestGrubNoDefaults(relbase.disco, TestGrubNoDefaults):
143 __test__ = True
144
145 def test_output_files_exist(self):
146 self.output_files_exist(["netplan.yaml"])
147
121# vi: ts=4 expandtab syntax=python148# vi: ts=4 expandtab syntax=python

Subscribers

People subscribed via source and target branches