Beispiel #1
0
def test_cmdline_ab():
    with pytest.raises(SkipException):
        CmdLine(context_wrap(CMDLINE_GRUB2_EMPTY))

    with pytest.raises(ParseException) as ex:
        CmdLine(context_wrap(CMDLINE_GRUB2_AB))
    assert 'Invalid output:' in str(ex)
def test_grub1_only1():
    grub1 = Grub1Config(context_wrap(GRUB1_TEMPLATE))
    cmdline = CmdLine(context_wrap(CMDLINE_V1))
    result = GrubConf(grub1, None, None, None, None, cmdline, None)
    assert result.kernel_initrds['grub_kernels'][
        0] == 'vmlinuz-2.6.32-642.el6.x86_64'
    assert result.kernel_initrds['grub_initrds'][
        0] == 'initramfs-2.6.32-642.el6.x86_64.img'
    assert result.is_kdump_iommu_enabled is True
    assert result.get_grub_cmdlines() == result.get_grub_cmdlines('/vmlinuz')
    assert len(result.get_grub_cmdlines()) == 3
    assert result.version == 1
    assert result.is_efi is False
Beispiel #3
0
def test_grub2_efi_cmdline():
    grub1 = Grub1Config(context_wrap(GRUB1_TEMPLATE))
    grub2 = Grub2Config(context_wrap(GRUB2_TEMPLATE))
    grub1e = Grub1EFIConfig(context_wrap(GRUB1_EFI_CFG))
    grub2e = Grub2EFIConfig(context_wrap(GRUB2_EFI_CFG))
    cmdline = CmdLine(context_wrap(CMDLINE_V2))
    sys_firmware = LsSysFirmware(context_wrap(SYS_FIRMWARE_DIR_EFI))
    result = GrubConf(grub1, grub2, grub1e, grub2e, None, None, None, cmdline,
                      sys_firmware, None)
    assert result.get_grub_cmdlines() == result.get_grub_cmdlines('/vmlinuz')
    assert result.get_grub_cmdlines('rescue')[0].name.startswith(
        "'Red Hat Enterprise Linux Server (0-rescue")
    assert len(result.get_grub_cmdlines()) == 4
    assert result.version == 2
    assert result.is_efi is True
Beispiel #4
0
def test_cmdline_v1():
    cmd_line = CmdLine(context_wrap(CMDLINE_V1))
    assert cmd_line.get('ro') == [True]
    assert cmd_line.get('root') == ['/dev/mapper/vg_rootvg-lv_root']
    assert cmd_line.get('rd_LVM_LV') == [
        'vg_rootvg/lv_root', 'vg_rootvg/lv_swap'
    ]
    # Handle non-alphabet characters and extra spaces
    assert cmd_line['crashkernel'] == ['191M@0M']
    assert cmd_line.get('audit') == [True, '1']
Beispiel #5
0
def test_grub1_efi_cmdline():
    grub1 = Grub1Config(context_wrap(GRUB1_TEMPLATE))
    grub2 = Grub2Config(context_wrap(GRUB2_TEMPLATE))
    grub1e = Grub1EFIConfig(context_wrap(GRUB1_EFI_CFG))
    grub2e = Grub2EFIConfig(context_wrap(GRUB2_EFI_CFG))
    cmdline = CmdLine(context_wrap(CMDLINE_V1))
    sys_firmware = LsSysFirmware(context_wrap(SYS_FIRMWARE_DIR_EFI))
    result = GrubConf(grub1, grub2, grub1e, grub2e, None, None, None, cmdline,
                      sys_firmware, None)
    assert result.kernel_initrds['grub_kernels'][
        0] == 'vmlinuz-2.6.32-71.el6.x86_64'
    assert result.kernel_initrds['grub_initrds'][
        0] == 'initramfs-2.6.32-71.el6.x86_64.img'
    assert result.is_kdump_iommu_enabled is False
    assert len(result.get_grub_cmdlines()) == 1
    assert result.version == 1
    assert result.is_efi is True
Beispiel #6
0
def test_grub2_efi_rpms():
    grub1 = Grub1Config(context_wrap(GRUB1_TEMPLATE))
    grub2 = Grub2Config(context_wrap(GRUB2_TEMPLATE))
    grub1e = Grub1EFIConfig(context_wrap(GRUB1_EFI_CFG))
    grub2e = Grub2EFIConfig(context_wrap(GRUB2_EFI_CFG))
    rpms = InstalledRpms(context_wrap(INSTALLED_RPMS_V2))
    cmdline = CmdLine(context_wrap(CMDLINE_V1))
    sys_firmware = LsSysFirmware(context_wrap(SYS_FIRMWARE_DIR_EFI))
    result = GrubConf(grub1, grub2, grub1e, grub2e, None, None, rpms, cmdline,
                      sys_firmware, None)
    assert result.kernel_initrds['grub_initrds'][
        0] == 'initramfs-3.10.0-514.16.1.el7.x86_64.img'
    assert result.get_grub_cmdlines() == result.get_grub_cmdlines('/vmlinuz')
    assert result.get_grub_cmdlines('rescue')[0].name.startswith(
        "'Red Hat Enterprise Linux Server (0-rescue")
    assert len(result.get_grub_cmdlines()) == 4
    assert result.version == 2
    assert result.is_efi is True
def test_grub1_rpms():
    grub1 = Grub1Config(context_wrap(GRUB1_TEMPLATE))
    grub2 = Grub2Config(context_wrap(GRUB2_TEMPLATE))
    grub1e = Grub1EFIConfig(context_wrap(GRUB1_EFI_CFG))
    grub2e = Grub2EFIConfig(context_wrap(GRUB2_EFI_CFG))
    rpms = InstalledRpms(context_wrap(INSTALLED_RPMS_V1))
    cmdline = CmdLine(context_wrap(CMDLINE_V2))
    sys_firmware = LsSysFirmware(context_wrap(SYS_FIRMWARE_DIR_NOEFI))
    result = GrubConf(grub1, grub2, grub1e, grub2e, rpms, cmdline,
                      sys_firmware)
    assert result.kernel_initrds['grub_kernels'][
        0] == 'vmlinuz-2.6.32-642.el6.x86_64'
    assert result.kernel_initrds['grub_initrds'][
        0] == 'initramfs-2.6.32-642.el6.x86_64.img'
    assert result.is_kdump_iommu_enabled is True
    assert result.get_grub_cmdlines() == result.get_grub_cmdlines('/vmlinuz')
    assert len(result.get_grub_cmdlines()) == 3
    assert result.version == 1
    assert result.is_efi is False
def test_get_grub_cmdlines_none():
    grub1 = Grub1Config(context_wrap(GRUB1_TEMPLATE))
    grub2 = Grub2Config(context_wrap(GRUB2_TEMPLATE))
    cmdline = CmdLine(context_wrap(CMDLINE_V2))
    sys_firmware = LsSysFirmware(context_wrap(SYS_FIRMWARE_DIR_EFI))
    with pytest.raises(ParseException) as pe:
        GrubConf(grub1, grub2, None, None, None, cmdline, sys_firmware)
    assert "No valid grub configuration is found." in str(pe)

    grub1e = Grub1EFIConfig(context_wrap(GRUB1_TEMPLATE))
    grub2e = Grub2EFIConfig(context_wrap(GRUB2_TEMPLATE))
    rpms = InstalledRpms(context_wrap(INSTALLED_RPMS_V2))
    with pytest.raises(ParseException) as pe:
        GrubConf(None, None, grub1e, grub2e, rpms, None, None)
    assert "No valid grub configuration is found." in str(pe)

    grub2e = Grub2EFIConfig(context_wrap(GRUB2_EFI_CFG))
    rpms = InstalledRpms(context_wrap(INSTALLED_RPMS_V2))
    with pytest.raises(ParseException) as pe:
        GrubConf(grub1, None, grub1e, None, rpms, None, None)
    assert "No valid grub configuration is found." in str(pe)
def test_grub2_rpms():
    grub1 = Grub1Config(context_wrap(GRUB1_TEMPLATE))
    grub2 = Grub2Config(context_wrap(GRUB2_TEMPLATE))
    grub1e = Grub1EFIConfig(context_wrap(GRUB1_EFI_CFG))
    grub2e = Grub2EFIConfig(context_wrap(GRUB2_EFI_CFG))
    rpms = InstalledRpms(context_wrap(INSTALLED_RPMS_V2))
    cmdline = CmdLine(context_wrap(CMDLINE_V1))
    result = GrubConf(grub1, grub2, grub1e, grub2e, rpms, cmdline, None)
    assert result.kernel_initrds['grub_kernels'][
        0] == 'vmlinuz-3.10.0-327.el7.x86_64'
    assert result.kernel_initrds['grub_initrds'][
        0] == 'initramfs-3.10.0-327.el7.x86_64.img'
    assert result.is_kdump_iommu_enabled is False
    assert result.get_grub_cmdlines(
        '/vmlinuz-3.10.0'
    )[0].name == "'Red Hat Enterprise Linux Server (3.10.0-327.el7.x86_64) 7.2 (Maipo)' --class red --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-327.el7.x86_64-advanced-4f80b3d4-90ba-4545-869c-febdecc586ce'"
    assert result.get_grub_cmdlines('test') == []
    assert result.get_grub_cmdlines('') == []
    assert len(result.get_grub_cmdlines()) == 2
    assert result.version == 2
    assert result.is_efi is False
Beispiel #10
0
def test_doc_examples():
    env = {
        'cmd': CmdLine(context_wrap(CMDLINE_GRUB2)),
    }
    failed, total = doctest.testmod(cmdline, globs=env)
    assert failed == 0
Beispiel #11
0
def test_cmdline_v2():
    cmd_line = CmdLine(context_wrap(CMDLINE_V2))
    assert cmd_line.get('audit') == ['1', '0', True, True]
    assert cmd_line.cmdline == CMDLINE_V2