Exemple #1
0
    def test_create_isolinux_image_for_uefi(self, gen_cfg_mock,
                                   tempdir_mock, mount_mock, execute_mock,
                                   write_to_file_mock,
                                   create_root_fs_mock, umount_mock):

        files_info = {
                'path/to/kernel': 'vmlinuz',
                'path/to/ramdisk': 'initrd',
                CONF.isolinux_bin: 'isolinux/isolinux.bin',
                'path/to/grub': 'relpath/to/grub.cfg',
                'sourceabspath/to/efiboot.img': 'path/to/efiboot.img'
                }
        cfg = "cfg"
        cfg_file = 'tmpdir/isolinux/isolinux.cfg'
        grubcfg = "grubcfg"
        grub_file = 'tmpdir/relpath/to/grub.cfg'
        gen_cfg_mock.side_effect = iter([cfg, grubcfg])

        params = ['a=b', 'c']
        isolinux_options = {'kernel': '/vmlinuz',
                            'ramdisk': '/initrd'}
        grub_options = {'linux': '/vmlinuz',
                        'initrd': '/initrd'}

        uefi_path_info = {
            'sourceabspath/to/efiboot.img': 'path/to/efiboot.img',
            'path/to/grub': 'relpath/to/grub.cfg'}
        grub_rel_path = 'relpath/to/grub.cfg'
        e_img_rel_path = 'path/to/efiboot.img'
        mock_file_handle = mock.MagicMock(spec=file)
        mock_file_handle.__enter__.return_value = 'tmpdir'
        mock_file_handle1 = mock.MagicMock(spec=file)
        mock_file_handle1.__enter__.return_value = 'mountdir'
        tempdir_mock.side_effect = iter(
            [mock_file_handle, mock_file_handle1])
        mount_mock.return_value = (uefi_path_info,
                                   e_img_rel_path, grub_rel_path)

        images.create_isolinux_image_for_uefi('tgt_file', 'path/to/deploy_iso',
                                              'path/to/kernel',
                                              'path/to/ramdisk',
                                              kernel_params=params)
        mount_mock.assert_called_once_with('path/to/deploy_iso', 'mountdir')
        create_root_fs_mock.assert_called_once_with('tmpdir', files_info)
        gen_cfg_mock.assert_any_call(params, CONF.isolinux_config_template,
                                     isolinux_options)
        write_to_file_mock.assert_any_call(cfg_file, cfg)
        gen_cfg_mock.assert_any_call(params, CONF.grub_config_template,
                                     grub_options)
        write_to_file_mock.assert_any_call(grub_file, grubcfg)
        execute_mock.assert_called_once_with('mkisofs', '-r', '-V',
                 "VMEDIA_BOOT_ISO", '-cache-inodes', '-J', '-l',
                 '-no-emul-boot', '-boot-load-size',
                 '4', '-boot-info-table', '-b', 'isolinux/isolinux.bin',
                 '-eltorito-alt-boot', '-e', 'path/to/efiboot.img',
                 '-no-emul-boot', '-o', 'tgt_file', 'tmpdir')
        umount_mock.assert_called_once_with('mountdir')
Exemple #2
0
    def test_create_isolinux_image_for_uefi(self, gen_cfg_mock, tempdir_mock,
                                            mount_mock, execute_mock,
                                            write_to_file_mock,
                                            create_root_fs_mock, umount_mock):

        files_info = {
            'path/to/kernel': 'vmlinuz',
            'path/to/ramdisk': 'initrd',
            CONF.isolinux_bin: 'isolinux/isolinux.bin',
            'path/to/grub': 'relpath/to/grub.cfg',
            'sourceabspath/to/efiboot.img': 'path/to/efiboot.img'
        }
        cfg = "cfg"
        cfg_file = 'tmpdir/isolinux/isolinux.cfg'
        grubcfg = "grubcfg"
        grub_file = 'tmpdir/relpath/to/grub.cfg'
        gen_cfg_mock.side_effect = iter([cfg, grubcfg])

        params = ['a=b', 'c']
        isolinux_options = {'kernel': '/vmlinuz', 'ramdisk': '/initrd'}
        grub_options = {'linux': '/vmlinuz', 'initrd': '/initrd'}

        uefi_path_info = {
            'sourceabspath/to/efiboot.img': 'path/to/efiboot.img',
            'path/to/grub': 'relpath/to/grub.cfg'
        }
        grub_rel_path = 'relpath/to/grub.cfg'
        e_img_rel_path = 'path/to/efiboot.img'
        mock_file_handle = mock.MagicMock(spec=file)
        mock_file_handle.__enter__.return_value = 'tmpdir'
        mock_file_handle1 = mock.MagicMock(spec=file)
        mock_file_handle1.__enter__.return_value = 'mountdir'
        tempdir_mock.side_effect = iter([mock_file_handle, mock_file_handle1])
        mount_mock.return_value = (uefi_path_info, e_img_rel_path,
                                   grub_rel_path)

        images.create_isolinux_image_for_uefi('tgt_file',
                                              'path/to/deploy_iso',
                                              'path/to/kernel',
                                              'path/to/ramdisk',
                                              kernel_params=params)
        mount_mock.assert_called_once_with('path/to/deploy_iso', 'mountdir')
        create_root_fs_mock.assert_called_once_with('tmpdir', files_info)
        gen_cfg_mock.assert_any_call(params, CONF.isolinux_config_template,
                                     isolinux_options)
        write_to_file_mock.assert_any_call(cfg_file, cfg)
        gen_cfg_mock.assert_any_call(params, CONF.grub_config_template,
                                     grub_options)
        write_to_file_mock.assert_any_call(grub_file, grubcfg)
        execute_mock.assert_called_once_with(
            'mkisofs', '-r', '-V', "VMEDIA_BOOT_ISO", '-cache-inodes', '-J',
            '-l', '-no-emul-boot', '-boot-load-size', '4', '-boot-info-table',
            '-b', 'isolinux/isolinux.bin', '-eltorito-alt-boot', '-e',
            'path/to/efiboot.img', '-no-emul-boot', '-o', 'tgt_file', 'tmpdir')
        umount_mock.assert_called_once_with('mountdir')
Exemple #3
0
    def test_create_isolinux_image_for_uefi_with_deploy_iso(
            self, gen_cfg_mock, tempdir_mock, mount_mock, execute_mock,
            write_to_file_mock, create_root_fs_mock, umount_mock):

        files_info = {
            'path/to/kernel': 'vmlinuz',
            'path/to/ramdisk': 'initrd',
            'sourceabspath/to/efiboot.img': 'path/to/efiboot.img',
            'path/to/grub': 'relpath/to/grub.cfg'
        }

        grubcfg = "grubcfg"
        grub_file = 'tmpdir/relpath/to/grub.cfg'
        gen_cfg_mock.side_effect = (grubcfg, )

        params = ['a=b', 'c']
        grub_options = {'linux': '/vmlinuz', 'initrd': '/initrd'}

        uefi_path_info = {
            'sourceabspath/to/efiboot.img': 'path/to/efiboot.img',
            'path/to/grub': 'relpath/to/grub.cfg'
        }
        grub_rel_path = 'relpath/to/grub.cfg'
        e_img_rel_path = 'path/to/efiboot.img'
        mock_file_handle = mock.MagicMock(spec=file)
        mock_file_handle.__enter__.return_value = 'tmpdir'
        mock_file_handle1 = mock.MagicMock(spec=file)
        mock_file_handle1.__enter__.return_value = 'mountdir'
        tempdir_mock.side_effect = mock_file_handle, mock_file_handle1
        mount_mock.return_value = (uefi_path_info, e_img_rel_path,
                                   grub_rel_path)

        images.create_isolinux_image_for_uefi('tgt_file',
                                              'path/to/kernel',
                                              'path/to/ramdisk',
                                              deploy_iso='path/to/deploy_iso',
                                              kernel_params=params)
        mount_mock.assert_called_once_with('path/to/deploy_iso', 'mountdir')
        create_root_fs_mock.assert_called_once_with('tmpdir', files_info)
        gen_cfg_mock.assert_any_call(params, CONF.grub_config_template,
                                     grub_options)
        write_to_file_mock.assert_any_call(grub_file, grubcfg)
        execute_mock.assert_called_once_with('mkisofs', '-r', '-V',
                                             'VMEDIA_BOOT_ISO', '-l', '-e',
                                             'path/to/efiboot.img',
                                             '-no-emul-boot', '-o', 'tgt_file',
                                             'tmpdir')
        umount_mock.assert_called_once_with('mountdir')
Exemple #4
0
    def test_create_isolinux_image_for_uefi_with_esp_image(
            self, gen_cfg_mock, tempdir_mock, execute_mock,
            create_root_fs_mock, write_to_file_mock):

        files_info = {
            'path/to/kernel': 'vmlinuz',
            'path/to/ramdisk': 'initrd',
            'sourceabspath/to/efiboot.img': 'boot/grub/efiboot.img',
            '/dev/null': 'EFI/MYBOOT/grub.cfg',
        }

        grub_cfg_file = '/EFI/MYBOOT/grub.cfg'
        CONF.set_override('grub_config_path', grub_cfg_file)
        grubcfg = "grubcfg"
        gen_cfg_mock.side_effect = (grubcfg, )

        params = ['a=b', 'c']
        grub_options = {'linux': '/vmlinuz', 'initrd': '/initrd'}

        mock_file_handle = mock.MagicMock(spec=file)
        mock_file_handle.__enter__.return_value = 'tmpdir'
        mock_file_handle1 = mock.MagicMock(spec=file)
        mock_file_handle1.__enter__.return_value = 'mountdir'
        tempdir_mock.side_effect = mock_file_handle, mock_file_handle1
        mountdir_grub_cfg_path = 'tmpdir' + grub_cfg_file

        images.create_isolinux_image_for_uefi(
            'tgt_file',
            'path/to/kernel',
            'path/to/ramdisk',
            esp_image='sourceabspath/to/efiboot.img',
            kernel_params=params)
        create_root_fs_mock.assert_called_once_with('tmpdir', files_info)
        gen_cfg_mock.assert_any_call(params, CONF.grub_config_template,
                                     grub_options)
        write_to_file_mock.assert_any_call(mountdir_grub_cfg_path, grubcfg)
        execute_mock.assert_called_once_with('mkisofs', '-r', '-V',
                                             'VMEDIA_BOOT_ISO', '-l', '-e',
                                             'boot/grub/efiboot.img',
                                             '-no-emul-boot', '-o', 'tgt_file',
                                             'tmpdir')
Exemple #5
0
    def test_create_isolinux_image_for_uefi(
        self, gen_cfg_mock, tempdir_mock, mount_mock, execute_mock, write_to_file_mock, create_root_fs_mock, umount_mock
    ):

        files_info = {
            "path/to/kernel": "vmlinuz",
            "path/to/ramdisk": "initrd",
            CONF.isolinux_bin: "isolinux/isolinux.bin",
            "path/to/grub": "relpath/to/grub.cfg",
            "sourceabspath/to/efiboot.img": "path/to/efiboot.img",
        }
        cfg = "cfg"
        cfg_file = "tmpdir/isolinux/isolinux.cfg"
        grubcfg = "grubcfg"
        grub_file = "tmpdir/relpath/to/grub.cfg"
        gen_cfg_mock.side_effect = iter([cfg, grubcfg])

        params = ["a=b", "c"]
        isolinux_options = {"kernel": "/vmlinuz", "ramdisk": "/initrd"}
        grub_options = {"linux": "/vmlinuz", "initrd": "/initrd"}

        uefi_path_info = {"sourceabspath/to/efiboot.img": "path/to/efiboot.img", "path/to/grub": "relpath/to/grub.cfg"}
        grub_rel_path = "relpath/to/grub.cfg"
        e_img_rel_path = "path/to/efiboot.img"
        mock_file_handle = mock.MagicMock(spec=file)
        mock_file_handle.__enter__.return_value = "tmpdir"
        mock_file_handle1 = mock.MagicMock(spec=file)
        mock_file_handle1.__enter__.return_value = "mountdir"
        tempdir_mock.side_effect = iter([mock_file_handle, mock_file_handle1])
        mount_mock.return_value = (uefi_path_info, e_img_rel_path, grub_rel_path)

        images.create_isolinux_image_for_uefi(
            "tgt_file", "path/to/deploy_iso", "path/to/kernel", "path/to/ramdisk", kernel_params=params
        )
        mount_mock.assert_called_once_with("path/to/deploy_iso", "mountdir")
        create_root_fs_mock.assert_called_once_with("tmpdir", files_info)
        gen_cfg_mock.assert_any_call(params, CONF.isolinux_config_template, isolinux_options)
        write_to_file_mock.assert_any_call(cfg_file, cfg)
        gen_cfg_mock.assert_any_call(params, CONF.grub_config_template, grub_options)
        write_to_file_mock.assert_any_call(grub_file, grubcfg)
        execute_mock.assert_called_once_with(
            "mkisofs",
            "-r",
            "-V",
            "VMEDIA_BOOT_ISO",
            "-cache-inodes",
            "-J",
            "-l",
            "-no-emul-boot",
            "-boot-load-size",
            "4",
            "-boot-info-table",
            "-b",
            "isolinux/isolinux.bin",
            "-eltorito-alt-boot",
            "-e",
            "path/to/efiboot.img",
            "-no-emul-boot",
            "-o",
            "tgt_file",
            "tmpdir",
        )
        umount_mock.assert_called_once_with("mountdir")