コード例 #1
0
def get_kernel_version_list():
    """Get a list of installed kernel versions.

    :return: a list of kernel versions
    """
    files = []
    efi_dir = conf.bootloader.efi_dir

    # Find all installed RPMs that provide 'kernel'.
    ts = rpm.TransactionSet(conf.target.system_root)
    mi = ts.dbMatch('providename', 'kernel')

    for hdr in mi:
        unicode_fnames = (decode_bytes(f) for f in hdr.filenames)

        # Find all /boot/vmlinuz- files and strip off vmlinuz-.
        files.extend(
            (f.split("/")[-1][8:] for f in unicode_fnames
             if fnmatch.fnmatch(f, "/boot/vmlinuz-*")
             or fnmatch.fnmatch(f, "/boot/efi/EFI/%s/vmlinuz-*" % efi_dir)))

    # Sort the kernel versions.
    sort_kernel_version_list(files)

    return files
コード例 #2
0
def get_kernel_version_list_from_tar(tarfile_path):
    with tarfile.open(tarfile_path) as archive:
        names = archive.getnames()

    # Strip out vmlinuz- from the names
    kernel_version_list = [
        n.split("/")[-1][8:] for n in names if "boot/vmlinuz-" in n
    ]

    sort_kernel_version_list(kernel_version_list)
    return kernel_version_list
コード例 #3
0
    def test_sort_kernel_version_list(self):
        """Test the sort_kernel_version_list function."""
        # Test fake versions.
        kernel_version_list = [
            '9.1.1-100.f1',
            '10.1.1-100.f1',
            '1.9.1-100.f1',
            '1.10.1-100.f1',
            '1.1.9-100.f1',
            '1.1.10-100.f1',
            '1.1.1-999.f1',
            '1.1.1-1000.f1',
            '1.1.1-100.f1',
            '1.1.1-100.f2',
        ]

        sort_kernel_version_list(kernel_version_list)
        assert kernel_version_list == [
            '1.1.1-100.f1',
            '1.1.1-100.f2',
            '1.1.1-999.f1',
            '1.1.1-1000.f1',
            '1.1.9-100.f1',
            '1.1.10-100.f1',
            '1.9.1-100.f1',
            '1.10.1-100.f1',
            '9.1.1-100.f1',
            '10.1.1-100.f1'
        ]

        # Test real versions.
        kernel_version_list = [
            '5.8.16-200.fc32.x86_64',
            '5.8.18-200.fc32.x86_64',
            '5.10.0-0.rc4.78.fc34.x86_64',
            '5.9.8-100.fc33.x86_64',
            '5.8.18-300.fc33.x86_64',
            '5.8.15-201.fc32.x86_64',
            '5.9.8-200.fc33.x86_64',
        ]

        sort_kernel_version_list(kernel_version_list)
        assert kernel_version_list == [
            '5.8.15-201.fc32.x86_64',
            '5.8.16-200.fc32.x86_64',
            '5.8.18-200.fc32.x86_64',
            '5.8.18-300.fc33.x86_64',
            '5.9.8-100.fc33.x86_64',
            '5.9.8-200.fc33.x86_64',
            '5.10.0-0.rc4.78.fc34.x86_64'
        ]
コード例 #4
0
ファイル: utils.py プロジェクト: zhoupeng/anaconda
def get_kernel_version_list(root_path):
    """Get a list of installed kernel versions.

    :param root_path: a path to the system root
    :return: a list of kernel versions
    """
    efi_dir = conf.bootloader.efi_dir
    files = glob.glob(root_path + "/boot/vmlinuz-*")
    files.extend(
        glob.glob(root_path + "/boot/efi/EFI/{}/vmlinuz-*".format(efi_dir)))

    kernel_version_list = [
        f.split("/")[-1][8:] for f in files
        if os.path.isfile(f) and "-rescue-" not in f
    ]

    sort_kernel_version_list(kernel_version_list)
    return kernel_version_list