Пример #1
0
    def test_redhat_install(self):
        self.m_os_release.return_value = {'ID': 'rhel'}
        distroinfo = install_grub.distro.get_distroinfo()
        grub_name = 'grub2-efi-x64'
        grub_target = 'x86_64-efi'
        grub_cmd = 'grub2-install'
        update_nvram = True
        devices = ['/dev/disk-a-part1']
        disk = '/dev/disk-a'
        part = '1'
        self.m_get_disk_part.return_value = (disk, part)

        expected_install = [
            ['efibootmgr', '-v'],
            [
                grub_cmd,
                '--target=%s' % grub_target, '--efi-directory=/boot/efi',
                '--bootloader-id=redhat', '--recheck'
            ],
        ]
        expected_post = [['grub2-mkconfig', '-o', '/boot/grub2/grub.cfg'],
                         ['efibootmgr', '-v']]
        self.assertEqual(
            (expected_install, expected_post),
            install_grub.gen_uefi_install_commands(grub_name, grub_target,
                                                   grub_cmd, update_nvram,
                                                   distroinfo, devices,
                                                   self.target))
Пример #2
0
    def test_ubuntu_install(self):
        distroinfo = install_grub.distro.get_distroinfo()
        grub_name = 'grub-efi-amd64'
        grub_target = 'x86_64-efi'
        grub_cmd = 'grub-install'
        update_nvram = True
        devices = ['/dev/disk-a-part1']
        disk = '/dev/disk-a'
        part = '1'
        self.m_get_disk_part.return_value = (disk, part)

        expected_install = [
            ['efibootmgr', '-v'],
            ['dpkg-reconfigure', grub_name],
            ['update-grub'],
            [
                grub_cmd,
                '--target=%s' % grub_target, '--efi-directory=/boot/efi',
                '--bootloader-id=%s' % distroinfo.variant, '--recheck'
            ],
        ]
        expected_post = [['efibootmgr', '-v']]
        self.assertEqual(
            (expected_install, expected_post),
            install_grub.gen_uefi_install_commands(grub_name, grub_target,
                                                   grub_cmd, update_nvram,
                                                   distroinfo, devices,
                                                   self.target))
Пример #3
0
    def test_unsupported_distro_family_raises_valueerror(self):
        self.m_os_release.return_value = {'ID': 'arch'}
        distroinfo = install_grub.distro.get_distroinfo()
        grub_name = 'grub-efi-amd64'
        grub_target = 'x86_64-efi'
        grub_cmd = 'grub-install'
        update_nvram = True
        devices = ['/dev/disk-a-part1']
        disk = '/dev/disk-a'
        part = '1'
        self.m_get_disk_part.return_value = (disk, part)

        with self.assertRaises(ValueError):
            install_grub.gen_uefi_install_commands(grub_name, grub_target,
                                                   grub_cmd, update_nvram,
                                                   distroinfo, devices,
                                                   self.target)
Пример #4
0
    def test_redhat_install_existing(self):
        # simulate existing bootloaders already installed in target system
        # by touching the files grub would have installed, including shim
        def _enable_loaders(bootid):
            efi_path = 'boot/efi/EFI'
            target_efi_path = os.path.join(self.target, efi_path)
            loaders = [
                os.path.join(target_efi_path, bootid, 'shimx64.efi'),
                os.path.join(target_efi_path, 'BOOT', 'BOOTX64.EFI'),
                os.path.join(target_efi_path, bootid, 'grubx64.efi'),
            ]
            for loader in loaders:
                util.ensure_dir(os.path.dirname(loader))
                with open(loader, 'w+') as fh:
                    fh.write('\n')

        self.m_os_release.return_value = {'ID': 'redhat'}
        distroinfo = install_grub.distro.get_distroinfo()
        bootid = distroinfo.variant
        _enable_loaders(bootid)
        grub_name = 'grub2-efi-x64'
        grub_target = 'x86_64-efi'
        grub_cmd = 'grub2-install'
        update_nvram = True
        devices = ['/dev/disk-a-part1']
        disk = '/dev/disk-a'
        part = '1'
        self.m_get_disk_part.return_value = (disk, part)

        expected_loader = '/boot/efi/EFI/%s/shimx64.efi' % bootid
        expected_install = [
            ['efibootmgr', '-v'],
            [
                'efibootmgr', '--create', '--write-signature', '--label',
                bootid, '--disk', disk, '--part', part, '--loader',
                expected_loader
            ],
        ]
        expected_post = [[
            'grub2-mkconfig', '-o',
            '/boot/efi/EFI/%s/grub.cfg' % bootid
        ], ['efibootmgr', '-v']]

        self.assertEqual(
            (expected_install, expected_post),
            install_grub.gen_uefi_install_commands(grub_name, grub_target,
                                                   grub_cmd, update_nvram,
                                                   distroinfo, devices,
                                                   self.target))
Пример #5
0
    def test_redhat_install_existing_no_nvram(self):
        # verify grub install command is not executed if update_nvram is False
        # on redhat.
        def _enable_loaders(bootid):
            efi_path = 'boot/efi/EFI'
            target_efi_path = os.path.join(self.target, efi_path)
            loaders = [
                os.path.join(target_efi_path, bootid, 'shimx64.efi'),
                os.path.join(target_efi_path, 'BOOT', 'BOOTX64.EFI'),
                os.path.join(target_efi_path, bootid, 'grubx64.efi'),
            ]
            for loader in loaders:
                util.write_file(loader, content="")

        self.m_os_release.return_value = {'ID': 'redhat'}
        distroinfo = install_grub.distro.get_distroinfo()
        bootid = distroinfo.variant
        _enable_loaders(bootid)
        grub_name = 'grub2-efi-x64'
        grub_target = 'x86_64-efi'
        grub_cmd = 'grub2-install'
        update_nvram = False
        devices = ['/dev/disk-a-part1']
        disk = '/dev/disk-a'
        part = '1'
        self.m_get_disk_part.return_value = (disk, part)

        expected_install = [
            ['efibootmgr', '-v'],
        ]
        expected_post = [[
            'grub2-mkconfig', '-o',
            '/boot/efi/EFI/%s/grub.cfg' % bootid
        ], ['efibootmgr', '-v']]

        self.assertEqual(
            (expected_install, expected_post),
            install_grub.gen_uefi_install_commands(grub_name, grub_target,
                                                   grub_cmd, update_nvram,
                                                   distroinfo, devices,
                                                   self.target))
Пример #6
0
    def test_ubuntu_install_multiple_esp(self):
        distroinfo = install_grub.distro.get_distroinfo()
        grub_name = 'grub-efi-amd64'
        grub_cmd = install_grub.GRUB_MULTI_INSTALL
        grub_target = 'x86_64-efi'
        update_nvram = True
        devices = ['/dev/disk-a-part1']
        disk = '/dev/disk-a'
        part = '1'
        self.m_get_disk_part.return_value = (disk, part)

        expected_install = [
            ['efibootmgr', '-v'],
            ['dpkg-reconfigure', grub_name],
            ['update-grub'],
            [install_grub.GRUB_MULTI_INSTALL],
        ]
        expected_post = [['efibootmgr', '-v']]
        self.assertEqual(
            (expected_install, expected_post),
            install_grub.gen_uefi_install_commands(grub_name, grub_target,
                                                   grub_cmd, update_nvram,
                                                   distroinfo, devices,
                                                   self.target))