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_grub1_config(): config = Grub1Config(context_wrap(GOOD_OFFSET_1)) assert config assert 'configs' in config assert 'title' in config assert 'menuentry' not in config assert len(config['configs']) == 4 assert config['configs']['default'] == ['0'] assert config['configs']['timeout'] == ['0'] assert config['configs']['splashimage'] == ['(hd0,0)/grub/splash.xpm.gz'] assert config['configs']['hiddenmenu'] == [''] assert len(config['title']) == 2 assert len(config['title'][0]) == 2 assert config['title'][0]['title'] == 'Red Hat Enterprise Linux Server (2.6.32-431.17.1.el6.x86_64)' assert config['title'][0]['kernel'][0] == '/vmlinuz-2.6.32-431.17.1.el6.x86_64 crashkernel=128M rhgb quiet' assert len(config['title'][1]) == 2 assert config['title'][1]['title'] == 'Red Hat Enterprise Linux Server (2.6.32-431.11.2.el6.x86_64)' assert config['title'][1]['kernel'][-1] == '/vmlinuz-2.6.32-431.11.2.el6.x86_64 crashkernel=128M rhgb quiet' assert config.is_kdump_iommu_enabled is False assert type(config.kernel_initrds) == dict # Why is this two separate lists and not a list of dicts? # Because this config has been deliberately cut down and is not a # real GRUB configuration, it can't find the initrds. assert 'grub_initrds' in config.kernel_initrds assert config.kernel_initrds['grub_initrds'] == [] assert 'grub_kernels' in config.kernel_initrds assert config.kernel_initrds['grub_kernels'] == [ 'vmlinuz-2.6.32-431.17.1.el6.x86_64', 'vmlinuz-2.6.32-431.11.2.el6.x86_64' ]
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_grub1(): config = Grub1Config(context_wrap(GRUB1_TEMPLATE)) result = GrubConf(config, None, None, None) assert config 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_kernel_initrd_1(): 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", "initrd-2.6.18-194.17.1.el5.img"] } assert expected_result == Grub1Config( context_wrap(GRUB_CONF_3)).kernel_initrds # Process grub.conf where kernel and initrd are softlinks expected_result = {'grub_kernels': ['vmlinuz'], 'grub_initrds': ['initrd']} assert expected_result == Grub1Config( context_wrap(GRUB_CONF_LINKS)).kernel_initrds # Process grub.conf from a Xen hypervisor expected_result = { 'grub_kernels': ['vmlinuz-2.6.18-398.el5xen'], 'grub_initrds': ['initrd-2.6.18-398.el5xen.img'] } assert expected_result == Grub1Config( context_wrap(GRUB_CONF_XEN)).kernel_initrds # Simulate grub.conf not containing any kernel or initrd entries expected_result = {'grub_kernels': [], 'grub_initrds': []} assert expected_result == Grub1Config( context_wrap(LS_BOOT_1)).kernel_initrds assert expected_result, Grub1Config(context_wrap(LS_BOOT_2)).kernel_initrds # Ignore grub.conf from machines that have PXE boot entries because we can't know if they are ok or not assert Grub1Config(context_wrap(GRUB_CONF_IPXE)).kernel_initrds == {}
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_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(): 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