Skip to content

Commit

Permalink
task/kernel: some cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Kyr Shatskyy <[email protected]>
  • Loading branch information
Kyr Shatskyy committed Jan 23, 2025
1 parent d059647 commit 3f25c42
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions teuthology/task/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,8 +861,9 @@ def install_kernel(remote, role_config, path=None, version=None):
if package_type == 'deb':
newversion = get_latest_image_version_deb(remote, dist_release, role_config)
if 'ubuntu' in dist_release:
grub2conf = teuthology.get_file(remote,
'/boot/grub/grub.cfg', sudo=True).decode()
#grub2conf = teuthology.get_file(remote,
# '/boot/grub/grub.cfg', sudo=True).decode()
grub2conf = remote.read_file('/boot/grub/grub.cfg', sudo=True).decode()
submenu = ''
menuentry = ''
for line in grub2conf.split('\n'):
Expand All @@ -882,9 +883,10 @@ def install_kernel(remote, role_config, path=None, version=None):
grubvalue = submenu + '>' + menuentry
else:
grubvalue = menuentry
grubfile = 'cat <<EOF\nset default="' + grubvalue + '"\nEOF'
teuthology.delete_file(remote, '/etc/grub.d/01_ceph_kernel', sudo=True, force=True)
teuthology.sudo_write_file(remote, '/etc/grub.d/01_ceph_kernel', StringIO(grubfile), '755')
path = '/etc/grub.d/01_ceph_kernel'
data = f"cat <<EOF\nset default=\"{grubvalue}\"\nEOF"
remote.sh(f"sudo rm -rf {path}")
remote.write_file(path, data, sudo=True, mode='755')
log.info('Distro Kernel Version: {version}'.format(version=newversion))
remote.run(args=['sudo', 'update-grub'])
remote.run(args=['sudo', 'shutdown', '-r', 'now'], wait=False )
Expand Down Expand Up @@ -1077,19 +1079,17 @@ def get_latest_image_version_deb(remote, ostype, role_config):
"""
remote.run(args=['sudo', 'apt-get', 'clean'])
remote.run(args=['sudo', 'apt-get', 'update'])
output = StringIO()
newest = ''
# Depend of virtual package has uname -r output in package name. Grab that.
# Note that a dependency list may have multiple comma-separated entries,
# but also each entry may be an alternative (pkg1 | pkg2)
if 'debian' in ostype:
args=['sudo', 'apt-get', '-y', 'install', 'linux-image-amd64']
install_dep_packages(remote, args)
remote.run(args=['dpkg', '-s', 'linux-image-amd64'], stdout=output)
for line in output.getvalue().split('\n'):
status = remote.run("dpkg -s linux-image-amd64")
for line in status.split('\n'):
if 'Depends:' in line:
newest = line.split('linux-image-')[1]
output.close()
return newest
# Ubuntu is a depend in a depend.
if 'ubuntu' in ostype:
Expand All @@ -1100,10 +1100,8 @@ def get_latest_image_version_deb(remote, ostype, role_config):
args=['sudo', 'DEBIAN_FRONTEND=noninteractive',
'apt-get', '-y', 'install', name]
install_dep_packages(remote, args)
remote.run(args=['dpkg', '-s', name],
stdout=output)

for line in output.getvalue().split('\n'):
status = remote.sh(f"dpkg -s {name}")
for line in status.split('\n'):
if 'Depends:' in line:
newest = line.split('linux-image-')[1]
if ',' in newest:
Expand All @@ -1112,7 +1110,6 @@ def get_latest_image_version_deb(remote, ostype, role_config):
# not strictly correct, as any of the |-joined
# packages may satisfy the dependency
newest = newest.split('|')[0].strip()
output.close()
return newest


Expand Down

0 comments on commit 3f25c42

Please sign in to comment.