33
33
from common .OpTestSystem import OpSystemState
34
34
from common .OpTestSOL import OpSOLMonitorThread
35
35
from common .OpTestInstallUtil import InstallUtil
36
+ from common .OpTestUtil import OpTestUtil
36
37
37
38
log = OpTestLogger .optest_logger_glob .get_logger (__name__ )
38
39
@@ -52,6 +53,8 @@ def setUp(self):
52
53
self .patch = self .conf .args .git_patch
53
54
self .use_kexec = self .conf .args .use_kexec
54
55
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 ()
55
58
if self .config_path :
56
59
self .config = "olddefconfig"
57
60
if not self .repo :
@@ -115,82 +118,76 @@ def is_url(path):
115
118
self .config_path , sourcedir = "" , dstdir = os .path .join (linux_path , ".config" ))
116
119
con .run_command ("make %s" % self .config )
117
120
# Capture kernel version & release
118
- res = con .run_command ("make kernelrelease" )
121
+ ker_ver = con .run_command ("make kernelrelease" )[ - 1 ]
119
122
sha = con .run_command ("git rev-parse HEAD" )
120
123
tcommit = con .run_command ("export 'TERM=xterm-256color';git show -s --format=%ci" )
121
124
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 )
123
126
log .info ("Upstream kernel commit-id: %s" , sha [- 1 ])
124
127
log .info ("Upstream kernel commit-time: %s" , tcommit )
125
128
log .debug ("Compile and install linux kernel" )
126
129
con .run_command ("make -j %d -s && make modules_install && make install" %
127
130
onlinecpus , timeout = self .host_cmd_timeout )
128
131
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 ))
129
139
if not self .use_kexec :
130
140
# FIXME: Handle distributions which do not support grub
131
- con .run_command (
132
- "grub2-mkconfig --output=/boot/grub2/grub.cfg" )
133
141
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'
147
143
else :
148
- self .console_thread .console_terminate ()
149
144
cmdline = con .run_command ("cat /proc/cmdline" )[- 1 ]
150
145
if self .append_kernel_cmdline :
151
146
cmdline += " %s" % self .append_kernel_cmdline
152
- kern_rel_str = con .run_command (
153
- "cat %s/include/config/kernel.release" % linux_path )[- 1 ]
154
147
try :
155
148
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 ]
157
150
except Exception :
158
151
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 ]
160
153
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 )
162
155
# Let's makesure we set the default boot index to current kernel
163
156
# 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' ]:
166
158
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 )
176
162
con .run_command (
177
163
"grub2-mkconfig --output=/boot/grub2/grub.cfg" )
178
164
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 ()
183
179
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" )
186
184
if self .conf .args .host_cmd :
187
185
con .run_command (self .conf .args .host_cmd ,
188
186
timeout = self .host_cmd_timeout )
189
187
self .cv_HOST .host_gather_opal_msg_log ()
190
188
self .cv_HOST .host_gather_kernel_log ()
191
189
finally :
192
- if self .console_thread .isAlive ():
193
- self .console_thread .console_terminate ()
190
+ self .console_thread .console_terminate ()
194
191
195
192
def wait_for (self , func , timeout , first = 0.0 , step = 1.0 , text = None , args = None , kwargs = None ):
196
193
args = args or []
0 commit comments