| 1 |
import logging |
| 2 |
from unittest.mock import ( |
| 3 |
patch, call |
| 4 |
) |
| 5 |
from pytest import ( |
| 6 |
raises, fixture |
| 7 |
) |
| 8 |
|
| 9 |
from kiwi.defaults import Defaults |
| 10 |
from kiwi.iso_tools.xorriso import IsoToolsXorrIso |
| 11 |
|
| 12 |
from kiwi.exceptions import KiwiIsoToolError |
| 13 |
|
| 14 |
|
| 15 |
class TestIsoToolsXorrIso: |
| 16 |
@fixture(autouse=True) |
| 17 |
def inject_fixtures(self, caplog): |
| 18 |
self._caplog = caplog |
| 19 |
|
| 20 |
def setup(self): |
| 21 |
Defaults.set_platform_name('x86_64') |
| 22 |
self.iso_tool = IsoToolsXorrIso('source-dir') |
| 23 |
|
| 24 |
def setup_method(self, cls): |
| 25 |
self.setup() |
| 26 |
|
| 27 |
@patch('kiwi.iso_tools.xorriso.Path.which') |
| 28 |
def test_get_tool_name(self, mock_which): |
| 29 |
mock_which.return_value = 'tool_found' |
| 30 |
assert self.iso_tool.get_tool_name() == 'tool_found' |
| 31 |
|
| 32 |
@patch('os.path.exists') |
| 33 |
def test_get_tool_name_raises(self, mock_exists): |
| 34 |
mock_exists.return_value = False |
| 35 |
with raises(KiwiIsoToolError): |
| 36 |
self.iso_tool.get_tool_name() |
| 37 |
|
| 38 |
@patch('os.path.exists') |
| 39 |
def test_init_iso_creation_parameters_no_hybrid_mbr( |
| 40 |
self, mock_os_path_exists |
| 41 |
): |
| 42 |
mock_os_path_exists.return_value = False |
| 43 |
with self._caplog.at_level(logging.WARNING): |
| 44 |
self.iso_tool.init_iso_creation_parameters( |
| 45 |
{ |
| 46 |
'mbr_id': 'app_id', |
| 47 |
'publisher': 'org', |
| 48 |
'preparer': 'preparer', |
| 49 |
'volume_id': 'vol_id', |
| 50 |
'efi_mode': 'uefi', |
| 51 |
'legacy_bios_mode': True |
| 52 |
} |
| 53 |
) |
| 54 |
assert 'No hybrid MBR file found' in self._caplog.text |
| 55 |
|
| 56 |
@patch('os.path.exists') |
| 57 |
def test_init_iso_creation_parameters_ppc(self, mock_os_path_exists): |
| 58 |
mock_os_path_exists.return_value = True |
| 59 |
self.iso_tool.arch = 'ppc64le' |
| 60 |
self.iso_tool.init_iso_creation_parameters( |
| 61 |
{ |
| 62 |
'mbr_id': 'app_id', |
| 63 |
'publisher': 'org', |
| 64 |
'preparer': 'preparer', |
| 65 |
'volume_id': 'vol_id', |
| 66 |
'efi_mode': 'ofw', |
| 67 |
'legacy_bios_mode': False |
| 68 |
} |
| 69 |
) |
| 70 |
assert self.iso_tool.iso_parameters == [ |
| 71 |
'-application_id', 'app_id', |
| 72 |
'-publisher', 'org', |
| 73 |
'-preparer_id', 'preparer', |
| 74 |
'-volid', 'vol_id', |
| 75 |
'-joliet', 'on', |
| 76 |
'-padding', '0', |
| 77 |
'-compliance', 'untranslated_names' |
| 78 |
] |
| 79 |
|
| 80 |
@patch('os.path.exists') |
| 81 |
def test_init_iso_creation_parameters_efi(self, mock_os_path_exists): |
| 82 |
mock_os_path_exists.return_value = True |
| 83 |
self.iso_tool.init_iso_creation_parameters( |
| 84 |
{ |
| 85 |
'mbr_id': 'app_id', |
| 86 |
'publisher': 'org', |
| 87 |
'preparer': 'preparer', |
| 88 |
'volume_id': 'vol_id', |
| 89 |
'efi_mode': 'uefi', |
| 90 |
'legacy_bios_mode': True |
| 91 |
} |
| 92 |
) |
| 93 |
assert self.iso_tool.iso_parameters == [ |
| 94 |
'-application_id', 'app_id', |
| 95 |
'-publisher', 'org', |
| 96 |
'-preparer_id', 'preparer', |
| 97 |
'-volid', 'vol_id', |
| 98 |
'-joliet', 'on', |
| 99 |
'-padding', '0', |
| 100 |
'-compliance', 'no_emul_toc' |
| 101 |
] |
| 102 |
assert self.iso_tool.iso_loaders == [ |
| 103 |
'-boot_image', 'grub', |
| 104 |
'bin_path=boot/x86_64/loader/eltorito.img', |
| 105 |
'-boot_image', 'grub', |
| 106 |
'grub2_mbr=source-dir/boot/x86_64/loader/boot_hybrid.img', |
| 107 |
'-boot_image', 'grub', 'grub2_boot_info=on', |
| 108 |
'-boot_image', 'any', 'partition_offset=16', |
| 109 |
'-boot_image', 'any', 'cat_path=boot/x86_64/boot.catalog', |
| 110 |
'-boot_image', 'any', 'cat_hidden=on', |
| 111 |
'-boot_image', 'any', 'boot_info_table=on', |
| 112 |
'-boot_image', 'any', 'platform_id=0x00', |
| 113 |
'-boot_image', 'any', 'emul_type=no_emulation', |
| 114 |
'-boot_image', 'any', 'load_size=2048' |
| 115 |
] |
| 116 |
|
| 117 |
@patch('os.path.exists') |
| 118 |
def test_init_iso_creation_parameters_efi_custom_app_id( |
| 119 |
self, mock_os_path_exists |
| 120 |
): |
| 121 |
mock_os_path_exists.return_value = True |
| 122 |
self.iso_tool.init_iso_creation_parameters( |
| 123 |
{ |
| 124 |
'mbr_id': 'app_id', |
| 125 |
'application_id': 'some_other_app_id', |
| 126 |
'publisher': 'org', |
| 127 |
'preparer': 'preparer', |
| 128 |
'volume_id': 'vol_id', |
| 129 |
'efi_mode': 'uefi', |
| 130 |
'legacy_bios_mode': True |
| 131 |
} |
| 132 |
) |
| 133 |
assert self.iso_tool.iso_parameters == [ |
| 134 |
'-application_id', 'some_other_app_id', |
| 135 |
'-publisher', 'org', |
| 136 |
'-preparer_id', 'preparer', |
| 137 |
'-volid', 'vol_id', |
| 138 |
'-joliet', 'on', |
| 139 |
'-padding', '0', |
| 140 |
'-compliance', 'no_emul_toc' |
| 141 |
] |
| 142 |
|
| 143 |
def test_add_efi_loader_parameters(self): |
| 144 |
self.iso_tool.add_efi_loader_parameters('target_dir/efi-loader') |
| 145 |
assert self.iso_tool.iso_loaders == [ |
| 146 |
'-append_partition', '2', '0xef', 'target_dir/efi-loader', |
| 147 |
'-boot_image', 'any', 'next', |
| 148 |
'-boot_image', 'any', |
| 149 |
'efi_path=--interval:appended_partition_2:all::', |
| 150 |
'-boot_image', 'any', 'platform_id=0xef', |
| 151 |
'-boot_image', 'any', 'emul_type=no_emulation' |
| 152 |
] |
| 153 |
|
| 154 |
def test_add_efi_loader_parameters_gpt(self): |
| 155 |
self.iso_tool.add_efi_loader_parameters( |
| 156 |
'target_dir/efi-loader', |
| 157 |
{'efi_partition_table': 'gpt'} |
| 158 |
) |
| 159 |
assert self.iso_tool.iso_loaders == [ |
| 160 |
'-boot_image', 'any', 'appended_part_as=gpt', |
| 161 |
'-append_partition', '2', '0xef', 'target_dir/efi-loader', |
| 162 |
'-boot_image', 'any', 'next', |
| 163 |
'-boot_image', 'any', |
| 164 |
'efi_path=--interval:appended_partition_2:all::', |
| 165 |
'-boot_image', 'any', 'platform_id=0xef', |
| 166 |
'-boot_image', 'any', 'emul_type=no_emulation' |
| 167 |
] |
| 168 |
|
| 169 |
def test_add_efi_loader_parameters_gpt_hybrid(self): |
| 170 |
self.iso_tool.add_efi_loader_parameters( |
| 171 |
'target_dir/efi-loader', |
| 172 |
{ |
| 173 |
'efi_partition_table': 'gpt', |
| 174 |
'legacy_bios_mode': True, |
| 175 |
'gpt_hybrid_mbr': True |
| 176 |
} |
| 177 |
) |
| 178 |
assert self.iso_tool.iso_loaders == [ |
| 179 |
'-boot_image', 'any', 'appended_part_as=gpt', |
| 180 |
'-boot_image', 'any', 'mbr_force_bootable=on', |
| 181 |
'-append_partition', '2', '0xef', 'target_dir/efi-loader', |
| 182 |
'-boot_image', 'any', 'next', |
| 183 |
'-boot_image', 'any', |
| 184 |
'efi_path=--interval:appended_partition_2:all::', |
| 185 |
'-boot_image', 'any', 'platform_id=0xef', |
| 186 |
'-boot_image', 'any', 'emul_type=no_emulation' |
| 187 |
] |
| 188 |
|
| 189 |
@patch('kiwi.iso_tools.xorriso.Command.run') |
| 190 |
@patch('kiwi.iso_tools.xorriso.Path.wipe') |
| 191 |
@patch('kiwi.iso_tools.xorriso.Path.which') |
| 192 |
def test_create_iso(self, mock_which, mock_wipe, mock_command): |
| 193 |
mock_which.return_value = '/usr/bin/xorriso' |
| 194 |
self.iso_tool.create_iso('myiso', hidden_files=['hide_me']) |
| 195 |
mock_wipe.assert_called_once_with('myiso') |
| 196 |
assert mock_command.call_args_list == [ |
| 197 |
call( |
| 198 |
[ |
| 199 |
'/usr/bin/xorriso', |
| 200 |
'-outdev', 'myiso', |
| 201 |
'-map', 'source-dir', '/', |
| 202 |
'-chmod', '0755', '/', '--', |
| 203 |
'--', '-find', 'hide_me', '-exec', 'hide', 'on' |
| 204 |
] |
| 205 |
), |
| 206 |
call( |
| 207 |
[ |
| 208 |
'/usr/bin/xorriso', '-indev', 'myiso', |
| 209 |
'-report_system_area', 'plain' |
| 210 |
] |
| 211 |
) |
| 212 |
] |
| 213 |
|
| 214 |
def test_has_iso_hybrid_capability(self): |
| 215 |
assert self.iso_tool.has_iso_hybrid_capability() is True |