def test_kdump_iommu_enabled(): assert Grub1Config(context_wrap(IOMMU_OFF)).is_kdump_iommu_enabled is False assert Grub1Config(context_wrap(IOMMU_MISSING)).is_kdump_iommu_enabled is False assert Grub1Config(context_wrap(IOMMU_ON)).is_kdump_iommu_enabled is True assert Grub2Config(context_wrap(IOMMU2_OFF)).is_kdump_iommu_enabled is False assert Grub2Config(context_wrap(IOMMU2_MISSING)).is_kdump_iommu_enabled is False assert Grub2Config(context_wrap(IOMMU2_ON)).is_kdump_iommu_enabled is True
def test_get_grub_kernel_initrd_2(): expected_result = { 'grub_kernels': [ "vmlinuz-3.10.0-123.9.3.el7.x86_64", "vmlinuz-0-rescue-00c2fbfaa85544e48d6ca1d919fa2dd3" ], 'grub_initrds': [ "initramfs-3.10.0-123.9.3.el7.x86_64.img", "initramfs-0-rescue-00c2fbfaa85544e48d6ca1d919fa2dd3.img" ] } assert expected_result == Grub2Config( (context_wrap(GRUB2_CFG_1))).kernel_initrds == expected_result expected_result = { 'grub_kernels': [ "vmlinuz-3.10.0-229.el7.x86_64", "vmlinuz-3.10.0-123.13.2.el7.x86_64", "vmlinuz-3.10.0-123.el7.x86_64", "vmlinuz-0-rescue-13798ffcbc1ed4374f3f2e0fa6c923ad" ], 'grub_initrds': [ "initramfs-3.10.0-229.el7.x86_64.img", "initramfs-3.10.0-123.13.2.el7.x86_64.img", "initramfs-3.10.0-123.el7.x86_64.img", "initramfs-0-rescue-13798ffcbc1ed4374f3f2e0fa6c923ad.img" ] } assert expected_result == Grub2Config( context_wrap(GRUB2_CFG_2)).kernel_initrds # Simulate grub.conf not containing any kernel or initrd entries expected_result = {'grub_kernels': [], 'grub_initrds': []} assert expected_result == Grub2Config( context_wrap(LS_BOOT_1)).kernel_initrds assert expected_result, Grub2Config(context_wrap(LS_BOOT_2)).kernel_initrds
def test_grub_conf_doc(): env = { 'grub1_config': Grub1Config(context_wrap(GRUB1_CFG_1_DOC)), 'grub2_config': Grub2Config(context_wrap(GRUB2_CFG_1_DOC)), } failed, total = doctest.testmod(grub_conf, globs=env) assert failed == 0
def test_grub2_config(self): config = Grub2Config(context_wrap(GRUB2_CONFIG)) assert config assert 'configs' in config assert 'title' not in config assert 'menuentry' in config # Current parsing code is near useless for pulling information out of # GRUB2 config, as the file is actually a bash script. So here we # don't do any testing of the junk in 'configs'. assert len(config['configs']) > 0 assert len(config['menuentry']) == 4 """ menuentry 'Red Hat Enterprise Linux Workstation (3.10.0-327.36.3.el7.x86_64) 7.2 (Maipo)' --class red --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-123.13.2.el7.x86_64-advanced-fbff9f50-62c3-484e-bca5-d53f672cda7c' { load_video set gfxpayload=keep insmod gzio insmod part_msdos insmod ext2 set root='hd0,msdos1' if [ x$feature_platform_search_hint = xy ]; then search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1' 1184ab74-77b5-4cfa-81d3-fb87b0457577 else search --no-floppy --fs-uuid --set=root 1184ab74-77b5-4cfa-81d3-fb87b0457577 fi linux16 /vmlinuz-3.10.0-327.36.3.el7.x86_64 root=/dev/RHEL7CSB/Root ro rd.lvm.lv=RHEL7CSB/Root rd.luks.uuid=luks-96c66446-77fd-4431-9508-f6912bd84194 crashkernel=auto vconsole.keymap=us rd.lvm.lv=RHEL7CSB/Swap vconsole.font=latarcyrheb-sun16 rhgb quiet LANG=en_GB.utf8 initrd16 /initramfs-3.10.0-327.36.3.el7.x86_64.img } """ # The current parsing code does a very bad job of reading menu # entry configuration. Test a few things but we hope for better. assert len(config['menuentry'][0]) == 9 assert config['menuentry'][0][0] == ( 'menuentry_name', "'Red Hat Enterprise Linux Workstation (3.10.0-327.36.3.el7.x86_64) 7.2 (Maipo)' --class red --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-123.13.2.el7.x86_64-advanced-fbff9f50-62c3-484e-bca5-d53f672cda7c'" ) assert config['menuentry'][0][1] == ('load_video', None) # assert config['menuentry'][0][-2] == ('linux16', '/vmlinuz-3.10.0-327.36.3.el7.x86_64 root=/dev/RHEL7CSB/Root ro rd.lvm.lv=RHEL7CSB/Root rd.luks.uuid=luks-96c66446-77fd-4431-9508-f6912bd84194 crashkernel=auto vconsole.keymap=us rd.lvm.lv=RHEL7CSB/Swap vconsole.font=latarcyrheb-sun16 rhgb quiet LANG=en_GB.utf8') assert config['menuentry'][0][-1] == ( 'initrd16', '/initramfs-3.10.0-327.36.3.el7.x86_64.img') assert type(config.kernel_initrds) == dict # Why is this two separate lists and not a list of dicts? assert 'grub_initrds' in config.kernel_initrds assert config.kernel_initrds['grub_initrds'] == [ 'initramfs-3.10.0-327.36.3.el7.x86_64.img', 'initramfs-3.10.0-267.el7.x86_64.img', 'initramfs-3.10.0-230.el7synaptics.1186112.1186106.2.x86_64.img', 'initramfs-0-rescue-71483baa33934d94a7804a398fed6241.img' ] assert 'grub_kernels' in config.kernel_initrds assert config.kernel_initrds['grub_kernels'] == [ 'vmlinuz-3.10.0-327.36.3.el7.x86_64', 'vmlinuz-3.10.0-267.el7.x86_64', 'vmlinuz-3.10.0-230.el7synaptics.1186112.1186106.2.x86_64', 'vmlinuz-0-rescue-71483baa33934d94a7804a398fed6241' ]
def test_mod_internal(): config = Grub2Config(context_wrap(MODULE_TEST)) assert config assert type(config.kernel_initrds) == dict # Why is this two separate lists and not a list of dicts? assert 'grub_initrds' in config.kernel_initrds assert config.kernel_initrds['grub_initrds'] == ['initramfs-3.10.0-327.36.3.el7.x86_64.img'] assert 'grub_kernels' in config.kernel_initrds assert config.kernel_initrds['grub_kernels'] == ['vmlinuz-3.10.0-327.36.3.el7.x86_64']
def test_grub2(): config = Grub2Config(context_wrap(GRUB2_TEMPLATE)) result = GrubConf(None, config, None, 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 result.get_grub_cmdlines() == result.get_grub_cmdlines('/vmlinuz') assert result.version == 2 assert result.is_efi is False
def test_grub2_grubenv(): grub2 = Grub2Config(context_wrap(GRUB2_TEMPLATE)) grub2env = Grub2Grubenv(context_wrap(GRUBENV)) rhel8 = RedhatRelease(context_wrap(RHEL8)) rhel = RedHatRelease(None, rhel8) rpms = InstalledRpms(context_wrap(INSTALLED_RPMS_V2)) sys_firmware = LsSysFirmware(context_wrap(SYS_FIRMWARE_DIR_NOEFI)) result = GrubConf(None, grub2, None, None, grub2env, None, rpms, None, sys_firmware, rhel) assert len(result.get_grub_cmdlines()) == 1 assert 'noapic' not in result.get_grub_cmdlines()[0]['cmdline'] assert result.version == 2 assert not result.is_efi
def test_grub2_boot_loader_entries(): grub2 = Grub2Config(context_wrap(GRUB2_TEMPLATE)) grub_ble1 = BLE(context_wrap(BOOT_LOADER_ENTRIES_1)) grub_ble2 = BLE(context_wrap(BOOT_LOADER_ENTRIES_2)) grub_bles = BootLoaderEntries([grub_ble1, grub_ble2], None, None) rhel8 = RedhatRelease(context_wrap(RHEL8)) rhel = RedHatRelease(None, rhel8) rpms = InstalledRpms(context_wrap(INSTALLED_RPMS_V2)) sys_firmware = LsSysFirmware(context_wrap(SYS_FIRMWARE_DIR_EFI)) result = GrubConf(None, grub2, None, None, grub_bles, rpms, None, sys_firmware, rhel) assert len(result.get_grub_cmdlines()) == 2 assert 'noapic' in result.get_grub_cmdlines()[0]['cmdline'] assert result.version == 2 assert result.is_efi
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
def test_grub2_grubenv_with_kernelopts(): grub2 = Grub2Config(context_wrap(GRUB2_TEMPLATE)) grub_ble3 = BLE(context_wrap(BOOT_LOADER_ENTRIES_3)) grub_bles = BootLoaderEntries([grub_ble3], None, None) rhel8 = RedhatRelease(context_wrap(RHEL8)) rhel = RedHatRelease(None, rhel8) rpms = InstalledRpms(context_wrap(INSTALLED_RPMS_V2)) sys_firmware = LsSysFirmware(context_wrap(SYS_FIRMWARE_DIR_NOEFI)) result = GrubConf(None, grub2, None, None, grub_bles, rpms, None, sys_firmware, rhel) assert len(result.get_grub_cmdlines()) == 1 assert 'noapic' not in result.get_grub_cmdlines()[0]['cmdline'] assert 'transparent_hugepages' not in result.get_grub_cmdlines( )[0]['cmdline'] assert result.version == 2 assert not result.is_efi
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
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
def test_grub_conf_raise(): with pytest.raises(Exception) as e: Grub2Config(context_wrap(GRUB2_CFG_4)) assert "Cannot parse menuentry line: menuentry {" in str(e)
def test_grub_conf(): expected_result = {'grub_kernels': ["vmlinuz-2.6.18-194.8.1.el5", "vmlinuz-2.6.18-194.17.1.el5"], 'grub_initrds': ["initrd-2.6.18-194.8.1.el5.img", "initramfs-2.6.18-194.8.1.el5.img"]} assert expected_result == Grub1Config(context_wrap(GRUB1_CONF_3)).kernel_initrds expected_result = {'grub_kernels': ["vmlinuz-2.6.18-194.8.1.el5"], 'grub_initrds': []} grub1 = Grub1Config(context_wrap(GRUB1_CONF_4)) assert grub1.is_kdump_iommu_enabled is False assert expected_result == grub1.kernel_initrds assert grub1.get_current_title() is None grub1 = Grub1Config(context_wrap(GRUB1_CONF_5)) assert grub1.is_kdump_iommu_enabled is False assert grub1.get_current_title() == [ ('title_name', '(2.6.18-194.8.1.el5)'), ('kernel', None), ('module', '/2.6.18-194.8.1.el5.img')] grub1 = Grub1Config(context_wrap(GRUB1_CONF_6)) assert grub1.is_kdump_iommu_enabled is False assert grub1.get_current_title() == [ ('title_name', 'Red Hat Enterprise Linux Server'), ('kernel', 'test'), ('module', '/2.6.18-194.8.1.el5.img')] grub1 = Grub1Config(context_wrap(GRUB1_CONF_7)) assert grub1.is_kdump_iommu_enabled is False assert grub1.get_current_title() is None grub1 = Grub1Config(context_wrap(GRUB1_CONF_8)) assert grub1.is_kdump_iommu_enabled is False grub1efi = Grub1EFIConfig(context_wrap(GRUB1_CONF_4)) assert grub1efi.get_current_title() is None grub1efi = Grub1EFIConfig(context_wrap(GRUB1_CONF_5)) assert grub1efi.get_current_title() == [ ('title_name', '(2.6.18-194.8.1.el5)'), ('kernel', None), ('module', '/2.6.18-194.8.1.el5.img')] grub1efi = Grub1EFIConfig(context_wrap(GRUB1_CONF_6)) assert grub1efi.get_current_title() == [ ('title_name', 'Red Hat Enterprise Linux Server'), ('kernel', 'test'), ('module', '/2.6.18-194.8.1.el5.img')] grub1efi = Grub1EFIConfig(context_wrap(GRUB1_CONF_7)) assert grub1efi.get_current_title() is None grub_conf = Grub2Config(context_wrap(GRUB2_CFG_1))['menuentry'] assert ('load_video', None) in grub_conf[0] assert ('load_env', None) not in grub_conf[0] assert ('insmod', 'gzio') in grub_conf[0] expected_result = {'grub_kernels': ["vmlinuz-3.10.0-229.el7.x86_64", "vmlinuz-3.10.0-123.13.2.el7.x86_64", "vmlinuz-3.10.0-123.el7.x86_64", "vmlinuz-0-rescue-13798ffcbc1ed4374f3f2e0fa6c923ad"], 'grub_initrds': ["initramfs-3.10.0-229.el7.x86_64.img", "initramfs-3.10.0-123.13.2.el7.x86_64.img", "initramfs-3.10.0-123.el7.x86_64.img", "initramfs-0-rescue-13798ffcbc1ed4374f3f2e0fa6c923ad.img"]} assert expected_result == Grub2Config(context_wrap(GRUB2_CFG_2)).kernel_initrds grub_conf = Grub2Config(context_wrap(GRUB2_CFG_3)) assert ('load_video', None) in grub_conf['menuentry'][0] assert grub_conf.is_kdump_iommu_enabled is False