Add new task: DeterminKernelVersion, this can potentially fix a lot of small problems

This commit is contained in:
Anders Ingemann 2015-01-16 01:53:35 +01:00
parent 767b32d20e
commit 149db4c989
2 changed files with 32 additions and 1 deletions

View file

@ -15,6 +15,7 @@ from tasks import locale
from tasks import network
from tasks import initd
from tasks import ssh
from tasks import kernel
def get_standard_groups(manifest):
@ -26,6 +27,7 @@ def get_standard_groups(manifest):
if 'boot' in manifest.volume['partitions']:
group.extend(boot_partition_group)
group.extend(mounting_group)
group.extend(kernel_group)
group.extend(get_fs_specific_group(manifest))
group.extend(get_network_group(manifest))
group.extend(get_apt_group(manifest))
@ -76,6 +78,9 @@ mounting_group = [filesystem.CreateMountDir,
filesystem.DeleteMountDir,
]
kernel_group = [kernel.DetermineKernelVersion,
]
ssh_group = [ssh.AddOpenSSHPackage,
ssh.DisableSSHPasswordAuthentication,
ssh.DisableSSHDNSLookup,

View file

@ -1,6 +1,7 @@
from bootstrapvz.base import Task
from .. import phases
from ..tasks import packages
import logging
class AddDKMSPackages(Task):
@ -22,5 +23,30 @@ class UpdateInitramfs(Task):
@classmethod
def run(cls, info):
from bootstrapvz.common.tools import log_check_call
# Update initramfs (-u) for all currently installed kernel versions (-k all)
# Update initramfs (-u) for all currently installed kernel versions (-k all)
log_check_call(['chroot', info.root, 'update-initramfs', '-u', '-k', 'all'])
class DetermineKernelVersion(Task):
description = 'Determining kernel version'
phase = phases.package_installation
predecessors = [packages.InstallPackages]
@classmethod
def run(cls, info):
# Snatched from `extlinux-update' in wheezy
# list the files in boot/ that match vmlinuz-*
# sort what the * matches, the first entry is the kernel version
import os.path
import re
regexp = re.compile('^vmlinuz-(?P<version>.+)$')
def get_kernel_version(vmlinuz_path):
vmlinux_basename = os.path.basename(vmlinuz_path)
return regexp.match(vmlinux_basename).group('version')
from glob import glob
boot = os.path.join(info.root, 'boot')
vmlinuz_paths = glob('{boot}/vmlinuz-*'.format(boot=boot))
kernels = map(get_kernel_version, vmlinuz_paths)
info.kernel_version = sorted(kernels, reverse=True)[0]
logging.getLogger(__name__).debug('Kernel version is {version}'.format(version=info.kernel_version))