Example #1
0
 def test_get_distroinfo(self):
     for distro_name in distro.DISTRO_NAMES:
         self.mock_os_release.return_value = {'ID': distro_name}
         variant = distro.name_to_distro(distro_name)
         family = distro.DISTRO_TO_OSFAMILY[variant]
         distro_info = distro.get_distroinfo()
         self.assertEqual(variant, distro_info.variant)
         self.assertEqual(family, distro_info.family)
Example #2
0
def get_target_kernel_version(target):
    pkg_ver = None

    distro_info = distro.get_distroinfo(target=target)
    if not distro_info:
        raise RuntimeError('Failed to determine target distro')
    osfamily = distro_info.family
    if osfamily == distro.DISTROS.debian:
        try:
            # check in-target version
            pkg_ver = distro.get_package_version('linux-image-generic',
                                                 target=target)
        except Exception as e:
            LOG.warn(
                "failed reading linux-image-generic package version, %s", e)
    return pkg_ver
Example #3
0
def install_grub(devices, target, uefi=None, grubcfg=None):
    """Install grub to devices inside target chroot.

    :param: devices: List of block device paths to install grub upon.
    :param: target: A string specifying the path to the chroot mountpoint.
    :param: uefi: A boolean set to True if system is UEFI bootable otherwise
                  False.
    :param: grubcfg: An config dict with grub config options.
    """

    if not devices:
        raise ValueError("Invalid parameter 'devices': %s" % devices)

    if not target:
        raise ValueError("Invalid parameter 'target': %s" % target)

    LOG.debug("installing grub to target=%s devices=%s [replace_defaults=%s]",
              target, devices, grubcfg.get('replace_default'))
    update_nvram = config.value_as_boolean(grubcfg.get('update_nvram', True))
    distroinfo = distro.get_distroinfo(target=target)
    target_arch = distro.get_architecture(target=target)
    rhel_ver = (distro.rpm_get_dist_id(target)
                if distroinfo.family == distro.DISTROS.redhat else None)

    check_target_arch_machine(target, arch=target_arch, uefi=uefi)
    grub_name, grub_target = get_grub_package_name(target_arch, uefi, rhel_ver)
    grub_conf = get_grub_config_file(target, distroinfo.family)
    new_params = get_carryover_params(distroinfo)
    prepare_grub_dir(target, grub_conf)
    write_grub_config(target, grubcfg, grub_conf, new_params)
    grub_cmd = get_grub_install_command(uefi, distroinfo, target)
    if uefi:
        install_cmds, post_cmds = gen_uefi_install_commands(
            grub_name, grub_target, grub_cmd, update_nvram, distroinfo,
            devices, target)
    else:
        install_cmds, post_cmds = gen_install_commands(grub_name, grub_cmd,
                                                       distroinfo, devices,
                                                       rhel_ver)

    env = os.environ.copy()
    env['DEBIAN_FRONTEND'] = 'noninteractive'

    LOG.debug('Grub install cmds:\n%s', str(install_cmds + post_cmds))
    with util.ChrootableTarget(target) as in_chroot:
        for cmd in install_cmds + post_cmds:
            in_chroot.subp(cmd, env=env, capture=True)