Skip to content

Commit 76e0d7e

Browse files
Merge pull request #797 from abdhaleegit/grubby-fix
Add grubby to handle latest grub2 changes
2 parents ff538b4 + cadb973 commit 76e0d7e

File tree

1 file changed

+39
-42
lines changed

1 file changed

+39
-42
lines changed

testcases/InstallUpstreamKernel.py

+39-42
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from common.OpTestSystem import OpSystemState
3434
from common.OpTestSOL import OpSOLMonitorThread
3535
from common.OpTestInstallUtil import InstallUtil
36+
from common.OpTestUtil import OpTestUtil
3637

3738
log = OpTestLogger.optest_logger_glob.get_logger(__name__)
3839

@@ -52,6 +53,8 @@ def setUp(self):
5253
self.patch = self.conf.args.git_patch
5354
self.use_kexec = self.conf.args.use_kexec
5455
self.append_kernel_cmdline = self.conf.args.append_kernel_cmdline
56+
self.util = OpTestUtil(OpTestConfiguration.conf)
57+
self.host_distro_name = self.util.distro_name()
5558
if self.config_path:
5659
self.config = "olddefconfig"
5760
if not self.repo:
@@ -115,82 +118,76 @@ def is_url(path):
115118
self.config_path, sourcedir="", dstdir=os.path.join(linux_path, ".config"))
116119
con.run_command("make %s" % self.config)
117120
# Capture kernel version & release
118-
res = con.run_command("make kernelrelease")
121+
ker_ver = con.run_command("make kernelrelease")[-1]
119122
sha = con.run_command("git rev-parse HEAD")
120123
tcommit = con.run_command("export 'TERM=xterm-256color';git show -s --format=%ci")
121124
tcommit = re.sub(r"\x1b\[[0-9;]*[mGKHF]", "", tcommit[1])
122-
log.info("Upstream kernel version: %s", res[-1])
125+
log.info("Upstream kernel version: %s", ker_ver)
123126
log.info("Upstream kernel commit-id: %s", sha[-1])
124127
log.info("Upstream kernel commit-time: %s", tcommit)
125128
log.debug("Compile and install linux kernel")
126129
con.run_command("make -j %d -s && make modules_install && make install" %
127130
onlinecpus, timeout=self.host_cmd_timeout)
128131
time.sleep(10)
132+
if self.host_distro_name in ['rhel', 'Red Hat', 'ubuntu', 'Ubuntu']:
133+
gruby_cmd = 'grubby --set-default'
134+
elif self.host_distro_name in ['sles', 'SLES']:
135+
gruby_cmd = 'grub2-set-default'
136+
else:
137+
raise self.skipTest("Unsupported OS")
138+
con.run_command("%s /boot/vmlinu*-%s" % (gruby_cmd, ker_ver))
129139
if not self.use_kexec:
130140
# FIXME: Handle distributions which do not support grub
131-
con.run_command(
132-
"grub2-mkconfig --output=/boot/grub2/grub.cfg")
133141
log.debug("Rebooting after kernel install...")
134-
self.console_thread.console_terminate()
135-
self.prompt = self.cv_SYSTEM.util.build_prompt()
136-
self.console_thread.console_terminate()
137-
con.close()
138-
for i in range(5):
139-
raw_pty = self.wait_for(self.cv_SYSTEM.console.get_console, timeout=20)
140-
time.sleep(10)
141-
if raw_pty is not None:
142-
raw_pty.sendline("uname -r")
143-
break
144-
raw_pty.sendline("reboot")
145-
raw_pty.expect("login:", timeout=600)
146-
raw_pty.close()
142+
boot_cmd = 'reboot'
147143
else:
148-
self.console_thread.console_terminate()
149144
cmdline = con.run_command("cat /proc/cmdline")[-1]
150145
if self.append_kernel_cmdline:
151146
cmdline += " %s" % self.append_kernel_cmdline
152-
kern_rel_str = con.run_command(
153-
"cat %s/include/config/kernel.release" % linux_path)[-1]
154147
try:
155148
initrd_file = con.run_command(
156-
"ls -l /boot/initr*-%s.img" % kern_rel_str)[-1].split(" ")[-1]
149+
"ls -l /boot/initr*-%s.img" % ker_ver)[-1].split(" ")[-1]
157150
except Exception:
158151
initrd_file = con.run_command(
159-
"ls -l /boot/initr*-%s" % kern_rel_str)[-1].split(" ")[-1]
152+
"ls -l /boot/initr*-%s" % ker_ver)[-1].split(" ")[-1]
160153
kexec_cmdline = "kexec --initrd %s --command-line=\"%s\" /boot/vmlinu*-%s -l" % (
161-
initrd_file, cmdline, kern_rel_str)
154+
initrd_file, cmdline, ker_ver)
162155
# Let's makesure we set the default boot index to current kernel
163156
# to avoid leaving host in unstable state incase boot failure
164-
res = con.run_command("cat /etc/os-release")
165-
if "Ubuntu" in res[0] or "Ubuntu" in res[1]:
157+
if self.host_distro_name in ['rhel', 'Red Hat', 'ubuntu', 'Ubuntu']:
166158
con.run_command(
167-
'grubby --set-default /boot/vmlinu*-`uname -r`')
168-
elif 'Red Hat' in res[0] or 'Red Hat' in res[1]:
169-
con.run_command(
170-
'grubby --set-default /boot/vmlinu*-`uname -r`')
171-
elif 'SLES' in res[0] or 'SLES' in res[1]:
172-
con.run_command(
173-
'grub2-set-default /boot/vmlinu*-`uname -r`')
174-
else:
175-
raise self.skipTest("Unsupported OS")
159+
'%s /boot/vmlinu*-`uname -r`' % gruby_cmd)
160+
elif self.host_distro_name in ['sles', 'SLES']:
161+
con.run_command('%s /boot/vmlinu*-`uname -r`' % gruby_cmd)
176162
con.run_command(
177163
"grub2-mkconfig --output=/boot/grub2/grub.cfg")
178164
con.run_command(kexec_cmdline)
179-
con.close()
180-
raw_pty = self.cv_SYSTEM.console.get_console()
181-
raw_pty.sendline("reboot")
182-
raw_pty.expect("login:", timeout=600)
165+
boot_cmd = 'kexec -e'
166+
self.console_thread.console_terminate()
167+
self.cv_SYSTEM.util.build_prompt()
168+
self.console_thread.console_terminate()
169+
con.close()
170+
for i in range(5):
171+
raw_pty = self.wait_for(self.cv_SYSTEM.console.get_console, timeout=20)
172+
time.sleep(10)
173+
if raw_pty is not None:
174+
raw_pty.sendline("uname -r")
175+
break
176+
raw_pty.sendline(boot_cmd)
177+
raw_pty.expect("login:", timeout=600)
178+
raw_pty.close()
183179
con = self.cv_SYSTEM.cv_HOST.get_ssh_connection()
184-
res = con.run_command("uname -r")
185-
log.info("Installed upstream kernel version: %s", res[-1])
180+
res = con.run_command("uname -r")[-1]
181+
log.info("Installed upstream kernel version: %s", res)
182+
if ker_ver != res:
183+
self.fail("Upstream kernel did not boot")
186184
if self.conf.args.host_cmd:
187185
con.run_command(self.conf.args.host_cmd,
188186
timeout=self.host_cmd_timeout)
189187
self.cv_HOST.host_gather_opal_msg_log()
190188
self.cv_HOST.host_gather_kernel_log()
191189
finally:
192-
if self.console_thread.isAlive():
193-
self.console_thread.console_terminate()
190+
self.console_thread.console_terminate()
194191

195192
def wait_for(self, func, timeout, first=0.0, step=1.0, text=None, args=None, kwargs=None):
196193
args = args or []

0 commit comments

Comments
 (0)