| 1 |
import os |
| 2 |
import sys |
| 3 |
import logging |
| 4 |
from unittest.mock import ( |
| 5 |
patch, call, Mock, mock_open |
| 6 |
) |
| 7 |
from pytest import ( |
| 8 |
raises, fixture |
| 9 |
) |
| 10 |
|
| 11 |
from ..test_helper import argv_kiwi_tests |
| 12 |
|
| 13 |
import kiwi |
| 14 |
from kiwi.tasks.result_bundle import ResultBundleTask |
| 15 |
from kiwi.system.result import Result |
| 16 |
|
| 17 |
from kiwi.exceptions import KiwiBundleError |
| 18 |
|
| 19 |
|
| 20 |
class TestResultBundleTask: |
| 21 |
@fixture(autouse=True) |
| 22 |
def inject_fixtures(self, caplog): |
| 23 |
self._caplog = caplog |
| 24 |
|
| 25 |
def setup(self): |
| 26 |
sys.argv = [ |
| 27 |
sys.argv[0], 'result', 'bundle', '--target-dir', 'target_dir', |
| 28 |
'--bundle-dir', 'bundle_dir', '--id', 'Build_42' |
| 29 |
] |
| 30 |
self.abs_target_dir = os.path.abspath('target_dir') |
| 31 |
self.abs_bundle_dir = os.path.abspath('bundle_dir') |
| 32 |
|
| 33 |
self.xml_state = Mock() |
| 34 |
self.xml_state.get_image_version = Mock( |
| 35 |
return_value='1.2.3' |
| 36 |
) |
| 37 |
self.xml_state.xml_data.get_name = Mock( |
| 38 |
return_value='test-image' |
| 39 |
) |
| 40 |
|
| 41 |
self.result = Result(self.xml_state) |
| 42 |
self.result.add( |
| 43 |
key='keyname', filename='test-image-1.2.3', |
| 44 |
use_for_bundle=True, compress=True, shasum=True |
| 45 |
) |
| 46 |
|
| 47 |
kiwi.tasks.result_bundle.Help = Mock( |
| 48 |
return_value=Mock() |
| 49 |
) |
| 50 |
self.task = ResultBundleTask() |
| 51 |
|
| 52 |
runtime_config = Mock() |
| 53 |
runtime_config.is_bundle_compression_requested = Mock( |
| 54 |
return_value=True |
| 55 |
) |
| 56 |
self.task.runtime_config = runtime_config |
| 57 |
|
| 58 |
def setup_method(self, cls): |
| 59 |
self.setup() |
| 60 |
|
| 61 |
def teardown(self): |
| 62 |
sys.argv = argv_kiwi_tests |
| 63 |
|
| 64 |
def teardown_method(self, cls): |
| 65 |
self.teardown() |
| 66 |
|
| 67 |
def _init_command_args(self): |
| 68 |
self.task.command_args = {} |
| 69 |
self.task.command_args['help'] = False |
| 70 |
self.task.command_args['bundle'] = False |
| 71 |
self.task.command_args['--target-dir'] = 'target_dir' |
| 72 |
self.task.command_args['--bundle-dir'] = 'bundle_dir' |
| 73 |
self.task.command_args['--id'] = 'Build_42' |
| 74 |
self.task.command_args['--zsync-source'] = None |
| 75 |
self.task.command_args['--package-as-rpm'] = None |
| 76 |
self.task.command_args['--bundle-format'] = None |
| 77 |
self.task.command_args['--no-compress'] = None |
| 78 |
|
| 79 |
def test_process_invalid_bundle_directory(self): |
| 80 |
self._init_command_args() |
| 81 |
self.task.command_args['--bundle-dir'] = \ |
| 82 |
self.task.command_args['--target-dir'] |
| 83 |
self.task.command_args['bundle'] = True |
| 84 |
with raises(KiwiBundleError): |
| 85 |
self.task.process() |
| 86 |
|
| 87 |
@patch('kiwi.tasks.result_bundle.Result.load') |
| 88 |
@patch('kiwi.tasks.result_bundle.Command.run') |
| 89 |
@patch('kiwi.tasks.result_bundle.Path.create') |
| 90 |
@patch('kiwi.tasks.result_bundle.Path.which') |
| 91 |
@patch('kiwi.tasks.result_bundle.Compress') |
| 92 |
@patch('os.path.exists') |
| 93 |
@patch('os.path.islink') |
| 94 |
@patch('os.unlink') |
| 95 |
@patch('os.symlink') |
| 96 |
@patch('os.readlink') |
| 97 |
def test_process_result_bundle( |
| 98 |
self, mock_os_readlink, mock_os_symlink, mock_os_unlink, |
| 99 |
mock_os_path_islink, mock_exists, mock_compress, |
| 100 |
mock_path_which, mock_path_create, mock_command, mock_load |
| 101 |
): |
| 102 |
# This file won't be copied with build id |
| 103 |
self.result.add( |
| 104 |
key='noversion', filename='test-image-noversion', |
| 105 |
use_for_bundle=True, compress=False, shasum=False |
| 106 |
) |
| 107 |
|
| 108 |
compress = Mock() |
| 109 |
mock_path_which.return_value = 'zsyncmake' |
| 110 |
compress.xz.return_value = 'compressed_filename' |
| 111 |
mock_compress.return_value = compress |
| 112 |
mock_exists.return_value = False |
| 113 |
mock_load.return_value = self.result |
| 114 |
self._init_command_args() |
| 115 |
self.task.command_args['bundle'] = True |
| 116 |
self.task.command_args['--zsync-source'] = 'http://example.com/zsync' |
| 117 |
|
| 118 |
command_result = Mock() |
| 119 |
command_result.output = "some mime is text" |
| 120 |
mock_command.return_value = command_result |
| 121 |
|
| 122 |
mock_os_readlink.return_value = 'readlinked' |
| 123 |
|
| 124 |
m_open = mock_open() |
| 125 |
with patch('builtins.open', m_open, create=True): |
| 126 |
self.task.process() |
| 127 |
|
| 128 |
mock_load.assert_called_once_with( |
| 129 |
os.sep.join([self.abs_target_dir, 'kiwi.result']) |
| 130 |
) |
| 131 |
mock_path_create.assert_called_once_with(self.abs_bundle_dir) |
| 132 |
assert mock_command.call_args_list == [ |
| 133 |
call([ |
| 134 |
'cp', 'test-image-1.2.3', |
| 135 |
os.sep.join([self.abs_bundle_dir, 'test-image-1.2.3-Build_42']) |
| 136 |
]), |
| 137 |
call([ |
| 138 |
'cp', 'test-image-noversion', |
| 139 |
os.sep.join([self.abs_bundle_dir, 'test-image-noversion']) |
| 140 |
]), |
| 141 |
call([ |
| 142 |
'file', |
| 143 |
os.sep.join([self.abs_bundle_dir, 'test-image-1.2.3-Build_42']) |
| 144 |
]), |
| 145 |
call([ |
| 146 |
'sed', '-ie', 's/test-image-1.2.3/readlinked/g', |
| 147 |
os.sep.join([self.abs_bundle_dir, 'test-image-1.2.3-Build_42']) |
| 148 |
]), |
| 149 |
call([ |
| 150 |
'file', |
| 151 |
os.sep.join([self.abs_bundle_dir, 'test-image-noversion']) |
| 152 |
]), |
| 153 |
call([ |
| 154 |
'sed', '-ie', 's/test-image-1.2.3/readlinked/g', |
| 155 |
os.sep.join([self.abs_bundle_dir, 'test-image-noversion']) |
| 156 |
]), |
| 157 |
call([ |
| 158 |
'zsyncmake', '-e', |
| 159 |
'-u', 'http://example.com/zsync/compressed_filename', |
| 160 |
'-o', 'compressed_filename.zsync', |
| 161 |
'compressed_filename' |
| 162 |
]) |
| 163 |
] |
| 164 |
mock_compress.assert_called_once_with( |
| 165 |
os.sep.join([self.abs_bundle_dir, 'test-image-1.2.3-Build_42']) |
| 166 |
) |
| 167 |
m_open.return_value.write.assert_called_once_with( |
| 168 |
'{0} compressed_filename{1}'.format( |
| 169 |
self.task.runtime_config.get_checksum_handler.return_value.digest.return_value, os.linesep |
| 170 |
) |
| 171 |
) |
| 172 |
|
| 173 |
@patch('kiwi.tasks.result_bundle.Privileges.check_for_root_permissions') |
| 174 |
@patch('kiwi.tasks.result_bundle.Result.load') |
| 175 |
@patch('kiwi.tasks.result_bundle.Command.run') |
| 176 |
@patch('kiwi.tasks.result_bundle.Path.create') |
| 177 |
@patch('kiwi.tasks.result_bundle.Path.which') |
| 178 |
@patch('kiwi.tasks.result_bundle.Path.wipe') |
| 179 |
@patch('kiwi.tasks.result_bundle.Compress') |
| 180 |
@patch('os.path.exists') |
| 181 |
@patch('os.chdir') |
| 182 |
@patch('os.unlink') |
| 183 |
@patch('glob.iglob') |
| 184 |
@patch('os.path.islink') |
| 185 |
@patch('os.symlink') |
| 186 |
@patch('os.readlink') |
| 187 |
@patch('os.path.realpath') |
| 188 |
@patch('os.path.abspath') |
| 189 |
def test_process_result_bundle_as_rpm( |
| 190 |
self, mock_os_path_abspath, mock_os_path_realpath, mock_os_readlink, |
| 191 |
mock_os_symlink, mock_os_path_islink, mock_iglob, mock_unlink, |
| 192 |
mock_chdir, mock_exists, mock_compress, |
| 193 |
mock_path_wipe, mock_path_which, mock_path_create, mock_command, |
| 194 |
mock_load, mock_Privileges_check_for_root_permissions |
| 195 |
): |
| 196 |
def abspath(path): |
| 197 |
if path == 'target_dir': |
| 198 |
return 'target-dir' |
| 199 |
else: |
| 200 |
return 'bundle-dir' |
| 201 |
|
| 202 |
compress = Mock() |
| 203 |
mock_os_readlink.return_value = 'readlink' |
| 204 |
mock_os_path_abspath.side_effect = abspath |
| 205 |
mock_path_which.return_value = 'zsyncmake' |
| 206 |
compress.xz.return_value = 'compressed_filename' |
| 207 |
mock_compress.return_value = compress |
| 208 |
mock_exists.return_value = False |
| 209 |
mock_load.return_value = self.result |
| 210 |
self._init_command_args() |
| 211 |
self.task.command_args['bundle'] = True |
| 212 |
self.task.command_args['--package-as-rpm'] = True |
| 213 |
mock_iglob.return_value = [ |
| 214 |
os.sep.join([self.abs_bundle_dir, 'test-image-1.2.3-Build_42']) |
| 215 |
] |
| 216 |
|
| 217 |
m_open = mock_open() |
| 218 |
with patch('builtins.open', m_open, create=True): |
| 219 |
self.task.process() |
| 220 |
|
| 221 |
mock_path_wipe.assert_called_once_with('bundle-dir') |
| 222 |
mock_Privileges_check_for_root_permissions.assert_called_once_with() |
| 223 |
assert mock_command.call_args_list == [ |
| 224 |
call( |
| 225 |
[ |
| 226 |
'cp', 'test-image-1.2.3', |
| 227 |
os.sep.join( |
| 228 |
['bundle-dir', 'test-image-1.2.3-Build_42'] |
| 229 |
) |
| 230 |
] |
| 231 |
), |
| 232 |
call( |
| 233 |
[ |
| 234 |
'file', |
| 235 |
os.sep.join( |
| 236 |
['bundle-dir', 'test-image-1.2.3-Build_42'] |
| 237 |
) |
| 238 |
] |
| 239 |
), |
| 240 |
call( |
| 241 |
[ |
| 242 |
'rpmbuild', '--nodeps', '--nocheck', '--rmspec', '-bb', |
| 243 |
os.sep.join(['bundle-dir', 'test-image.spec']) |
| 244 |
] |
| 245 |
), |
| 246 |
call( |
| 247 |
['bash', '-c', 'mv noarch/*.rpm . && rmdir noarch'] |
| 248 |
) |
| 249 |
] |
| 250 |
mock_chdir.assert_called_once_with('bundle-dir') |
| 251 |
assert mock_unlink.called |
| 252 |
|
| 253 |
@patch('kiwi.tasks.result_bundle.Result.load') |
| 254 |
@patch('kiwi.tasks.result_bundle.Command.run') |
| 255 |
@patch('kiwi.tasks.result_bundle.Path.create') |
| 256 |
@patch('os.path.exists') |
| 257 |
@patch('os.path.islink') |
| 258 |
@patch('os.unlink') |
| 259 |
@patch('os.symlink') |
| 260 |
@patch('os.readlink') |
| 261 |
def test_process_result_bundle_with_bundle_format( |
| 262 |
self, mock_os_readlink, mock_os_symlink, mock_os_unlink, |
| 263 |
mock_os_path_islink, mock_exists, mock_path_create, mock_command, |
| 264 |
mock_load |
| 265 |
): |
| 266 |
self.xml_state.profiles = None |
| 267 |
self.xml_state.host_architecture = 'x86_64' |
| 268 |
self.xml_state.get_build_type_name = Mock( |
| 269 |
return_value='oem' |
| 270 |
) |
| 271 |
self.xml_state.xml_data.get_name = Mock( |
| 272 |
return_value='Leap-15.2' |
| 273 |
) |
| 274 |
|
| 275 |
result = Result(self.xml_state) |
| 276 |
result.add_bundle_format('%N-%T:%M') |
| 277 |
result.add( |
| 278 |
key='disk_image', |
| 279 |
filename='/tmp/mytest/Leap-15.2.x86_64-1.15.2.raw', |
| 280 |
use_for_bundle=True, compress=False, shasum=False |
| 281 |
) |
| 282 |
|
| 283 |
mock_exists.return_value = False |
| 284 |
mock_load.return_value = result |
| 285 |
self._init_command_args() |
| 286 |
|
| 287 |
self.task.process() |
| 288 |
|
| 289 |
assert mock_command.call_args_list == [ |
| 290 |
call( |
| 291 |
[ |
| 292 |
'cp', |
| 293 |
'/tmp/mytest/Leap-15.2.x86_64-1.15.2.raw', |
| 294 |
os.sep.join( |
| 295 |
[self.abs_bundle_dir, 'Leap-15.2-oem:1.raw'] |
| 296 |
) |
| 297 |
] |
| 298 |
), |
| 299 |
call( |
| 300 |
[ |
| 301 |
'file', |
| 302 |
os.sep.join( |
| 303 |
[self.abs_bundle_dir, 'Leap-15.2-oem:1.raw'] |
| 304 |
) |
| 305 |
] |
| 306 |
) |
| 307 |
] |
| 308 |
|
| 309 |
@patch('kiwi.tasks.result_bundle.Result.load') |
| 310 |
@patch('kiwi.tasks.result_bundle.Command.run') |
| 311 |
@patch('kiwi.tasks.result_bundle.Path.create') |
| 312 |
@patch('os.path.exists') |
| 313 |
@patch('os.path.islink') |
| 314 |
@patch('os.unlink') |
| 315 |
@patch('os.symlink') |
| 316 |
@patch('os.readlink') |
| 317 |
def test_process_result_bundle_with_bundle_format_for_vagrant_types( |
| 318 |
self, mock_os_readlink, mock_os_symlink, mock_os_unlink, |
| 319 |
mock_os_path_islink, mock_exists, mock_path_create, mock_command, |
| 320 |
mock_load |
| 321 |
): |
| 322 |
self.xml_state.profiles = None |
| 323 |
self.xml_state.host_architecture = 'x86_64' |
| 324 |
self.xml_state.get_build_type_name = Mock( |
| 325 |
return_value='oem' |
| 326 |
) |
| 327 |
self.xml_state.xml_data.get_name = Mock( |
| 328 |
return_value='Leap-15.2' |
| 329 |
) |
| 330 |
|
| 331 |
result = Result(self.xml_state) |
| 332 |
result.add_bundle_format('%N-%T:%M') |
| 333 |
result.add( |
| 334 |
key='disk_image', |
| 335 |
filename='/tmp/mytest/Leap-15.2.x86_64-1.15.2.vagrant.virtualbox.box', |
| 336 |
use_for_bundle=True, compress=False, shasum=False |
| 337 |
) |
| 338 |
|
| 339 |
mock_exists.return_value = False |
| 340 |
mock_load.return_value = result |
| 341 |
self._init_command_args() |
| 342 |
|
| 343 |
self.task.process() |
| 344 |
|
| 345 |
assert mock_command.call_args_list == [ |
| 346 |
call( |
| 347 |
[ |
| 348 |
'cp', |
| 349 |
'/tmp/mytest/Leap-15.2.x86_64-1.15.2.vagrant.virtualbox.box', |
| 350 |
os.sep.join( |
| 351 |
[self.abs_bundle_dir, 'Leap-15.2-oem:1.vagrant.virtualbox.box'] |
| 352 |
) |
| 353 |
] |
| 354 |
), |
| 355 |
call( |
| 356 |
[ |
| 357 |
'file', |
| 358 |
os.sep.join( |
| 359 |
[self.abs_bundle_dir, 'Leap-15.2-oem:1.vagrant.virtualbox.box'] |
| 360 |
) |
| 361 |
] |
| 362 |
) |
| 363 |
] |
| 364 |
|
| 365 |
@patch('kiwi.tasks.result_bundle.Result.load') |
| 366 |
@patch('kiwi.tasks.result_bundle.Command.run') |
| 367 |
@patch('kiwi.tasks.result_bundle.Path.create') |
| 368 |
@patch('os.path.exists') |
| 369 |
@patch('os.path.islink') |
| 370 |
@patch('os.unlink') |
| 371 |
@patch('os.symlink') |
| 372 |
@patch('os.readlink') |
| 373 |
def test_process_result_bundle_with_bundle_format_for_archive_types( |
| 374 |
self, mock_os_readlink, mock_os_symlink, mock_os_unlink, |
| 375 |
mock_os_path_islink, mock_exists, mock_path_create, mock_command, |
| 376 |
mock_load |
| 377 |
): |
| 378 |
self.xml_state.profiles = None |
| 379 |
self.xml_state.host_architecture = 'x86_64' |
| 380 |
self.xml_state.get_build_type_name = Mock( |
| 381 |
return_value='oem' |
| 382 |
) |
| 383 |
self.xml_state.xml_data.get_name = Mock( |
| 384 |
return_value='Leap-15.2' |
| 385 |
) |
| 386 |
|
| 387 |
result = Result(self.xml_state) |
| 388 |
result.add_bundle_format('%N-%T:%M') |
| 389 |
result.add( |
| 390 |
key='disk_image', |
| 391 |
filename='/tmp/mytest/Leap-15.2.x86_64-1.15.2.tar.xz', |
| 392 |
use_for_bundle=True, compress=False, shasum=False |
| 393 |
) |
| 394 |
|
| 395 |
mock_exists.return_value = False |
| 396 |
mock_load.return_value = result |
| 397 |
self._init_command_args() |
| 398 |
|
| 399 |
self.task.process() |
| 400 |
|
| 401 |
assert mock_command.call_args_list == [ |
| 402 |
call( |
| 403 |
[ |
| 404 |
'cp', |
| 405 |
'/tmp/mytest/Leap-15.2.x86_64-1.15.2.tar.xz', |
| 406 |
os.sep.join( |
| 407 |
[self.abs_bundle_dir, 'Leap-15.2-oem:1.tar.xz'] |
| 408 |
) |
| 409 |
] |
| 410 |
), |
| 411 |
call( |
| 412 |
[ |
| 413 |
'file', |
| 414 |
os.sep.join( |
| 415 |
[self.abs_bundle_dir, 'Leap-15.2-oem:1.tar.xz'] |
| 416 |
) |
| 417 |
] |
| 418 |
) |
| 419 |
] |
| 420 |
|
| 421 |
@patch('kiwi.tasks.result_bundle.Result.load') |
| 422 |
@patch('kiwi.tasks.result_bundle.Command.run') |
| 423 |
@patch('kiwi.tasks.result_bundle.Path.create') |
| 424 |
@patch('os.path.exists') |
| 425 |
@patch('os.path.islink') |
| 426 |
@patch('os.unlink') |
| 427 |
@patch('os.symlink') |
| 428 |
@patch('os.readlink') |
| 429 |
def test_process_result_bundle_with_bundle_format_for_oci_types( |
| 430 |
self, mock_os_readlink, mock_os_symlink, mock_os_unlink, |
| 431 |
mock_os_path_islink, mock_exists, mock_path_create, mock_command, |
| 432 |
mock_load |
| 433 |
): |
| 434 |
self.xml_state.profiles = None |
| 435 |
self.xml_state.host_architecture = 'x86_64' |
| 436 |
self.xml_state.get_build_type_name = Mock( |
| 437 |
return_value='oci' |
| 438 |
) |
| 439 |
self.xml_state.xml_data.get_name = Mock( |
| 440 |
return_value='Leap-15.2' |
| 441 |
) |
| 442 |
|
| 443 |
result = Result(self.xml_state) |
| 444 |
result.add_bundle_format('%N-%T:%M') |
| 445 |
result.add( |
| 446 |
key='container', |
| 447 |
filename='/tmp/mytest/Leap-15.2.x86_64-1.15.2.oci.tar.xz', |
| 448 |
use_for_bundle=True, compress=False, shasum=False |
| 449 |
) |
| 450 |
|
| 451 |
mock_exists.return_value = False |
| 452 |
mock_load.return_value = result |
| 453 |
self._init_command_args() |
| 454 |
|
| 455 |
self.task.process() |
| 456 |
|
| 457 |
assert mock_command.call_args_list == [ |
| 458 |
call( |
| 459 |
[ |
| 460 |
'cp', |
| 461 |
'/tmp/mytest/Leap-15.2.x86_64-1.15.2.oci.tar.xz', |
| 462 |
os.sep.join( |
| 463 |
[self.abs_bundle_dir, 'Leap-15.2-oci:1.oci.tar.xz'] |
| 464 |
) |
| 465 |
] |
| 466 |
), |
| 467 |
call( |
| 468 |
[ |
| 469 |
'file', |
| 470 |
os.sep.join( |
| 471 |
[self.abs_bundle_dir, 'Leap-15.2-oci:1.oci.tar.xz'] |
| 472 |
) |
| 473 |
] |
| 474 |
) |
| 475 |
] |
| 476 |
|
| 477 |
@patch('kiwi.tasks.result_bundle.Result.load') |
| 478 |
@patch('kiwi.tasks.result_bundle.Command.run') |
| 479 |
@patch('kiwi.tasks.result_bundle.Path.create') |
| 480 |
@patch('os.path.exists') |
| 481 |
@patch('os.path.islink') |
| 482 |
@patch('os.unlink') |
| 483 |
@patch('os.symlink') |
| 484 |
@patch('os.readlink') |
| 485 |
def test_process_result_bundle_with_bundle_format_for_docker_type( |
| 486 |
self, mock_os_readlink, mock_os_symlink, mock_os_unlink, |
| 487 |
mock_os_path_islink, mock_exists, mock_path_create, mock_command, |
| 488 |
mock_load |
| 489 |
): |
| 490 |
self.xml_state.profiles = None |
| 491 |
self.xml_state.host_architecture = 'x86_64' |
| 492 |
self.xml_state.get_build_type_name = Mock( |
| 493 |
return_value='docker' |
| 494 |
) |
| 495 |
self.xml_state.xml_data.get_name = Mock( |
| 496 |
return_value='Leap-15.2' |
| 497 |
) |
| 498 |
|
| 499 |
result = Result(self.xml_state) |
| 500 |
result.add_bundle_format('%N-%T:%M') |
| 501 |
result.add( |
| 502 |
key='container', |
| 503 |
filename='/tmp/mytest/Leap-15.2.x86_64-1.15.2.docker.tar', |
| 504 |
use_for_bundle=True, compress=False, shasum=False |
| 505 |
) |
| 506 |
|
| 507 |
mock_exists.return_value = False |
| 508 |
mock_load.return_value = result |
| 509 |
self._init_command_args() |
| 510 |
|
| 511 |
self.task.process() |
| 512 |
|
| 513 |
assert mock_command.call_args_list == [ |
| 514 |
call( |
| 515 |
[ |
| 516 |
'cp', |
| 517 |
'/tmp/mytest/Leap-15.2.x86_64-1.15.2.docker.tar', |
| 518 |
os.sep.join( |
| 519 |
[self.abs_bundle_dir, 'Leap-15.2-docker:1.docker.tar'] |
| 520 |
) |
| 521 |
] |
| 522 |
), |
| 523 |
call( |
| 524 |
[ |
| 525 |
'file', |
| 526 |
os.sep.join( |
| 527 |
[self.abs_bundle_dir, 'Leap-15.2-docker:1.docker.tar'] |
| 528 |
) |
| 529 |
] |
| 530 |
) |
| 531 |
] |
| 532 |
|
| 533 |
@patch('kiwi.tasks.result_bundle.Result.load') |
| 534 |
@patch('kiwi.tasks.result_bundle.Command.run') |
| 535 |
@patch('kiwi.tasks.result_bundle.Path.create') |
| 536 |
@patch('os.path.exists') |
| 537 |
@patch('os.path.islink') |
| 538 |
@patch('os.unlink') |
| 539 |
@patch('os.symlink') |
| 540 |
@patch('os.readlink') |
| 541 |
def test_process_result_bundle_with_bundle_format_for_compressed_docker_type( |
| 542 |
self, mock_os_readlink, mock_os_symlink, mock_os_unlink, |
| 543 |
mock_os_path_islink, mock_exists, mock_path_create, mock_command, |
| 544 |
mock_load |
| 545 |
): |
| 546 |
self.xml_state.profiles = None |
| 547 |
self.xml_state.host_architecture = 'x86_64' |
| 548 |
self.xml_state.get_build_type_name = Mock( |
| 549 |
return_value='docker' |
| 550 |
) |
| 551 |
self.xml_state.xml_data.get_name = Mock( |
| 552 |
return_value='Leap-15.2' |
| 553 |
) |
| 554 |
|
| 555 |
result = Result(self.xml_state) |
| 556 |
result.add_bundle_format('%N-%T:%M') |
| 557 |
result.add( |
| 558 |
key='container', |
| 559 |
filename='/tmp/mytest/Leap-15.2.x86_64-1.15.2.docker.tar.xz', |
| 560 |
use_for_bundle=True, compress=False, shasum=False |
| 561 |
) |
| 562 |
|
| 563 |
mock_exists.return_value = False |
| 564 |
mock_load.return_value = result |
| 565 |
self._init_command_args() |
| 566 |
|
| 567 |
self.task.process() |
| 568 |
|
| 569 |
assert mock_command.call_args_list == [ |
| 570 |
call( |
| 571 |
[ |
| 572 |
'cp', |
| 573 |
'/tmp/mytest/Leap-15.2.x86_64-1.15.2.docker.tar.xz', |
| 574 |
os.sep.join( |
| 575 |
[self.abs_bundle_dir, 'Leap-15.2-docker:1.docker.tar.xz'] |
| 576 |
) |
| 577 |
] |
| 578 |
), |
| 579 |
call( |
| 580 |
[ |
| 581 |
'file', |
| 582 |
os.sep.join( |
| 583 |
[self.abs_bundle_dir, 'Leap-15.2-docker:1.docker.tar.xz'] |
| 584 |
) |
| 585 |
] |
| 586 |
) |
| 587 |
] |
| 588 |
|
| 589 |
@patch('kiwi.tasks.result_bundle.Result.load') |
| 590 |
@patch('kiwi.tasks.result_bundle.Command.run') |
| 591 |
@patch('kiwi.tasks.result_bundle.Path.create') |
| 592 |
@patch('os.path.exists') |
| 593 |
@patch('os.path.islink') |
| 594 |
@patch('os.unlink') |
| 595 |
@patch('os.symlink') |
| 596 |
@patch('os.readlink') |
| 597 |
def test_process_result_bundle_with_bundle_format_from_commandline( |
| 598 |
self, mock_os_readlink, mock_os_symlink, mock_os_unlink, |
| 599 |
mock_os_path_islink, mock_exists, mock_path_create, mock_command, |
| 600 |
mock_load |
| 601 |
): |
| 602 |
self.xml_state.profiles = None |
| 603 |
self.xml_state.host_architecture = 'x86_64' |
| 604 |
self.xml_state.get_build_type_name = Mock( |
| 605 |
return_value='oem' |
| 606 |
) |
| 607 |
self.xml_state.xml_data.get_name = Mock( |
| 608 |
return_value='Leap-15.2' |
| 609 |
) |
| 610 |
|
| 611 |
result = Result(self.xml_state) |
| 612 |
result.add( |
| 613 |
key='disk_image', |
| 614 |
filename='/tmp/mytest/Leap-15.2.x86_64-1.15.2.raw', |
| 615 |
use_for_bundle=True, compress=False, shasum=False |
| 616 |
) |
| 617 |
|
| 618 |
mock_exists.return_value = False |
| 619 |
mock_load.return_value = result |
| 620 |
self._init_command_args() |
| 621 |
|
| 622 |
self.task.command_args['--bundle-format'] = '%N-%T:%M' |
| 623 |
|
| 624 |
self.task.process() |
| 625 |
|
| 626 |
assert mock_command.call_args_list == [ |
| 627 |
call( |
| 628 |
[ |
| 629 |
'cp', |
| 630 |
'/tmp/mytest/Leap-15.2.x86_64-1.15.2.raw', |
| 631 |
os.sep.join( |
| 632 |
[self.abs_bundle_dir, 'Leap-15.2-oem:1.raw'] |
| 633 |
) |
| 634 |
] |
| 635 |
), |
| 636 |
call( |
| 637 |
[ |
| 638 |
'file', |
| 639 |
os.sep.join( |
| 640 |
[self.abs_bundle_dir, 'Leap-15.2-oem:1.raw'] |
| 641 |
) |
| 642 |
] |
| 643 |
) |
| 644 |
] |
| 645 |
|
| 646 |
@patch('kiwi.tasks.result_bundle.Result.load') |
| 647 |
@patch('kiwi.tasks.result_bundle.Command.run') |
| 648 |
@patch('kiwi.tasks.result_bundle.Path.create') |
| 649 |
@patch('os.path.exists') |
| 650 |
@patch('os.path.islink') |
| 651 |
@patch('os.unlink') |
| 652 |
@patch('os.symlink') |
| 653 |
@patch('os.readlink') |
| 654 |
def test_process_result_bundle_name_includes_version( |
| 655 |
self, mock_os_readlink, mock_os_symlink, mock_os_unlink, |
| 656 |
mock_os_path_islink, mock_exists, mock_path_create, mock_command, |
| 657 |
mock_load |
| 658 |
): |
| 659 |
result = Result(self.xml_state) |
| 660 |
result.add( |
| 661 |
key='nameincludesversion', filename='test-1.2.3-image-1.2.3', |
| 662 |
use_for_bundle=True, compress=False, shasum=False |
| 663 |
) |
| 664 |
|
| 665 |
self.xml_state.xml_data.get_name = Mock( |
| 666 |
return_value='test-1.2.3-image' |
| 667 |
) |
| 668 |
|
| 669 |
mock_exists.return_value = False |
| 670 |
mock_load.return_value = result |
| 671 |
self._init_command_args() |
| 672 |
|
| 673 |
self.task.process() |
| 674 |
|
| 675 |
mock_load.assert_called_once_with( |
| 676 |
os.sep.join([self.abs_target_dir, 'kiwi.result']) |
| 677 |
) |
| 678 |
mock_path_create.assert_called_once_with(self.abs_bundle_dir) |
| 679 |
assert mock_command.call_args_list == [ |
| 680 |
call( |
| 681 |
[ |
| 682 |
'cp', 'test-1.2.3-image-1.2.3', |
| 683 |
os.sep.join( |
| 684 |
[self.abs_bundle_dir, 'test-1.2.3-image-1.2.3-Build_42'] |
| 685 |
) |
| 686 |
] |
| 687 |
), |
| 688 |
call( |
| 689 |
[ |
| 690 |
'file', |
| 691 |
os.sep.join( |
| 692 |
[self.abs_bundle_dir, 'test-1.2.3-image-1.2.3-Build_42'] |
| 693 |
) |
| 694 |
] |
| 695 |
) |
| 696 |
] |
| 697 |
|
| 698 |
@patch('kiwi.tasks.result_bundle.Result.load') |
| 699 |
@patch('kiwi.tasks.result_bundle.Command.run') |
| 700 |
@patch('kiwi.tasks.result_bundle.Path.create') |
| 701 |
@patch('kiwi.tasks.result_bundle.Path.which') |
| 702 |
@patch('kiwi.tasks.result_bundle.Compress') |
| 703 |
@patch('os.path.exists') |
| 704 |
@patch('os.path.islink') |
| 705 |
@patch('os.unlink') |
| 706 |
@patch('os.symlink') |
| 707 |
@patch('os.readlink') |
| 708 |
def test_process_result_bundle_zsyncmake_missing( |
| 709 |
self, mock_os_readlink, mock_os_symlink, mock_os_unlink, |
| 710 |
mock_os_path_islink, mock_exists, mock_compress, |
| 711 |
mock_path_which, mock_path_create, mock_command, mock_load |
| 712 |
): |
| 713 |
compress = Mock() |
| 714 |
mock_path_which.return_value = None |
| 715 |
compress.xz.return_value = 'compressed_filename' |
| 716 |
mock_compress.return_value = compress |
| 717 |
mock_exists.return_value = False |
| 718 |
mock_load.return_value = self.result |
| 719 |
self._init_command_args() |
| 720 |
self.task.command_args['bundle'] = True |
| 721 |
self.task.command_args['--zsync-source'] = 'http://example.com/zsync' |
| 722 |
|
| 723 |
with patch('builtins.open'): |
| 724 |
with self._caplog.at_level(logging.WARNING): |
| 725 |
self.task.process() |
| 726 |
assert '--> zsyncmake missing, zsync setup skipped' in \ |
| 727 |
self._caplog.text |
| 728 |
|
| 729 |
def test_process_result_bundle_help(self): |
| 730 |
self._init_command_args() |
| 731 |
self.task.command_args['help'] = True |
| 732 |
self.task.command_args['bundle'] = True |
| 733 |
self.task.process() |
| 734 |
self.task.manual.show.assert_called_once_with( |
| 735 |
'kiwi::result::bundle' |
| 736 |
) |