Merge ~smoser/curtin:fix/1527664-grub-cmdline-linux-default-in-default-grub into curtin:master

Proposed by Scott Moser
Status: Merged
Approved by: Scott Moser
Approved revision: a232743c8f653414a2db15318e555cd2116114fe
Merge reported by: Server Team CI bot
Merged at revision: not available
Proposed branch: ~smoser/curtin:fix/1527664-grub-cmdline-linux-default-in-default-grub
Merge into: curtin:master
Diff against target: 103 lines (+53/-5)
2 files modified
helpers/common (+50/-5)
tests/vmtests/__init__.py (+3/-0)
Reviewer Review Type Date Requested Status
Scott Moser (community) Approve
Ryan Harper (community) Approve
Server Team CI bot continuous-integration Approve
Review via email: mp+359871@code.launchpad.net

Commit message

Adjust helpers/common to edit GRUB_CMDLINE_LINUX_DEFAULT in place.

This will help us avoid hitting upgrade prompts as seen
and described in bug 564853. The change here is only to move
GRUB_CMDLINE_LINUX_DEFAULT to /etc/default/grub from
/etc/default/grub.d/50-curtin-settings.cfg.
Currently, other changes will still to into 50-curtin-settings.cfg.

Also collect /etc/default/grub files to artifacts and fix small issue
that resulted in the carryover args having an additional white space
at the end.

LP: #1527664

Description of the change

see commit message

To post a comment you must log in.
Revision history for this message
Scott Moser (smoser) wrote :

tempted to write the shell parser in python and either
 a.) have the helper call 'curtin edit-shell-file /etc/default/grub ...'
 b.) have curtin python code edit the file itslef and drop that function from install-grub

if 'b', we'd have to do the change before calling 'install-grub' so that changes would
be seen.

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

I'm find with this shell. Long term, I'd like to drop install-grub from shell and write that in python; if/when we do that, we could fold this into that transition. Sound reasonable?

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

Some in-line comments/questions

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) :
71c0260... by Scott Moser

take Ryan's suggestions for code readability

605b250... by Scott Moser

collect etc/default/grub files

Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
4d0086b... by Scott Moser

fix a bug, add some debug

d8b2f6c... by Scott Moser

more debug

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

I'm missing something with the ret=3 case, see inline comment.

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

remove trailing white space when carrying over params.

when carrying over parameters that occurred before the --
and no other params, we would see a trailing space on the end
of the 'carry over' parameters.

3259873... by Scott Moser

cleanup, add some quoting to add obviousness

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

simplify a bit.

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

@Ryan,
I simplified the code a bit.
I was over-engineering the shell_config_update. I was trying to account for the case where the /etc/default/grub file did not exist and to let the caller handle the behavior of what to do if it did not.

We can add that function later if we want.
For now, the behavior is
 - if /etc/default/grub exists and has GRUB_CMDLINE_LINUX_DEFAULT= in it, then edit in place.
 - otherwise append to it

Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
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 :

Yes, that looks good. Approved, let's get a jenkins run and then we can merge.

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

Jenkins run at
 https://jenkins.ubuntu.com/server/job/curtin-vmtest-devel-debug/138/

./tools/jenkins-runner -p4 tests/vmtests/test_basic.py tests/vmtests/test_lvm_raid.py

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

----------------------------------------------------------------------
Ran 343 tests in 2595.668s

OK (SKIP=12)
Fri, 30 Nov 2018 22:44:54 +0000: vmtest end [0] in 2600s

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

approving based on ryan's approval above.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/helpers/common b/helpers/common
2index f9217b7..34f0870 100644
3--- a/helpers/common
4+++ b/helpers/common
5@@ -537,7 +537,44 @@ get_carryover_params() {
6 done
7 echo "${c# }"
8 )
9- _RET="${carry_lead:+${carry_lead} }${carry_extra}"
10+ [ -n "${carry_lead}" -a -n "${carry_extra}" ] &&
11+ carry_lead="${carry_lead} "
12+ _RET="${carry_lead}${carry_extra}"
13+}
14+
15+shell_config_update() {
16+ # shell_config_update(file, name, value)
17+ # update variable 'name' setting value to 'val' in shell syntax 'file'.
18+ # if 'name' is not present, then append declaration.
19+ local file="$1" name="$2" val="$3"
20+ if ! [ -f "$file" ] || ! grep -q "^$name=" "$file"; then
21+ debug 2 "appending to $file shell $name=\"$val\""
22+ echo "$name=\"$val\"" >> "$file"
23+ return
24+ fi
25+ local cand="" del=""
26+ for cand in "|" "," "/"; do
27+ [ "${val#*${del}}" = "${val}" ] && del="$cand" && break
28+ done
29+ [ -n "$del" ] || {
30+ error "Couldn't find a sed delimiter for '$val'";
31+ return 1;
32+ }
33+
34+ sed -i -e "s${del}^$name=.*${del}$name=\"$val\"${del}" "$file" ||
35+ { error "Failed editing '$file' to set $name=$val"; return 1; }
36+ debug 2 "updated $file to set $name=\"$val\""
37+ return 0
38+}
39+
40+apply_grub_cmdline_linux_default() {
41+ local mp="$1" newargs="$2" edg="${3:-etc/default/grub}"
42+ local gcld="GRUB_CMDLINE_LINUX_DEFAULT"
43+ debug 1 "setting $gcld to '$newargs' in $edg"
44+ shell_config_update "$mp/$edg" "$gcld" "$newargs" || {
45+ error "Failed to set '$gcld=$newargs' in $edg"
46+ return 1
47+ }
48 }
49
50 install_grub() {
51@@ -709,6 +746,8 @@ install_grub() {
52 esac
53
54 local grub_d="etc/default/grub.d"
55+ # ubuntu writes to /etc/default/grub.d/50-curtin-settings.cfg
56+ # to avoid tripping prompts on upgrade LP: #564853
57 local mygrub_cfg="$grub_d/50-curtin-settings.cfg"
58 case $os_family in
59 redhat)
60@@ -736,9 +775,9 @@ install_grub() {
61 # always append rd.auto=1 for centos
62 case $os_family in
63 redhat)
64- newargs="$newargs rd.auto=1";;
65+ newargs="${newargs:+${newargs} }rd.auto=1";;
66 esac
67- debug 1 "carryover command line params: $newargs"
68+ debug 1 "carryover command line params '$newargs'"
69
70 case $os_family in
71 debian)
72@@ -746,9 +785,15 @@ install_grub() {
73 { error "Failed to write '$mygrub_cfg'"; return 1; }
74 ;;
75 esac
76+
77+ if [ "${REPLACE_GRUB_LINUX_DEFAULT:-1}" != "0" ]; then
78+ apply_grub_cmdline_linux_default "$mp" "$newargs" || {
79+ error "Failed to apply grub cmdline."
80+ return 1
81+ }
82+ fi
83+
84 {
85- [ "${REPLACE_GRUB_LINUX_DEFAULT:-1}" = "0" ] ||
86- echo "GRUB_CMDLINE_LINUX_DEFAULT=\"$newargs\""
87 echo "# Curtin disable grub os prober that might find other OS installs."
88 echo "GRUB_DISABLE_OS_PROBER=true"
89 echo "GRUB_TERMINAL=console"
90diff --git a/tests/vmtests/__init__.py b/tests/vmtests/__init__.py
91index 5ffa632..bc4a87b 100644
92--- a/tests/vmtests/__init__.py
93+++ b/tests/vmtests/__init__.py
94@@ -527,6 +527,9 @@ DEFAULT_COLLECT_SCRIPTS = {
95 if [ -e /sys/firmware/efi ]; then
96 efibootmgr -v | cat >efibootmgr.out;
97 fi
98+ [ ! -d /etc/default/grub.d ] ||
99+ cp -a /etc/default/grub.d etc_default_grub_d
100+ [ ! -f /etc/default/grub ] || cp /etc/default/grub etc_default_grub
101
102 exit 0
103 """)],

Subscribers

People subscribed via source and target branches