Do not recompress PXE image if compressed flag is true
This commit is two fold: * Refactor PXE builder to make use of the ArchiveTar instead of directly calling tar command. * Do not compress PXE tarball if the contained image is already compressed according the type's compressed attribute. Related to #1039
This commit is contained in:
parent
65422eaca6
commit
c86efdcd99
@ -20,7 +20,6 @@ import platform
|
||||
|
||||
# project
|
||||
from kiwi.defaults import Defaults
|
||||
from kiwi.command import Command
|
||||
from kiwi.boot.image import BootImage
|
||||
from kiwi.builder.filesystem import FileSystemBuilder
|
||||
from kiwi.utils.compress import Compress
|
||||
@ -30,6 +29,7 @@ from kiwi.system.kernel import Kernel
|
||||
from kiwi.logger import log
|
||||
from kiwi.system.result import Result
|
||||
from kiwi.runtime_config import RuntimeConfig
|
||||
from kiwi.archive.tar import ArchiveTar
|
||||
|
||||
from kiwi.exceptions import (
|
||||
KiwiPxeBootImageError
|
||||
@ -75,7 +75,7 @@ class PxeBuilder(object):
|
||||
'-' + xml_state.get_image_version()
|
||||
]
|
||||
)
|
||||
self.archive_name = ''.join([self.image_name, '.tar.xz'])
|
||||
self.archive_name = ''.join([self.image_name, '.tar'])
|
||||
self.checksum_name = ''.join([self.image_name, '.md5'])
|
||||
self.kernel_filename = None
|
||||
self.hypervisor_filename = None
|
||||
@ -172,19 +172,25 @@ class PxeBuilder(object):
|
||||
# put results into a tarball
|
||||
if not self.xz_options:
|
||||
self.xz_options = Defaults.get_xz_compression_options()
|
||||
bash_command = [
|
||||
'tar', '-C', self.target_dir, '-c', '--to-stdout'
|
||||
] + [
|
||||
|
||||
pxe_tarball_files = [
|
||||
self.kernel_filename,
|
||||
os.path.basename(self.boot_image_task.initrd_filename),
|
||||
os.path.basename(self.image),
|
||||
os.path.basename(self.checksum_name)
|
||||
] + [
|
||||
'|', 'xz', '-f'
|
||||
] + self.xz_options + [
|
||||
'>', self.archive_name
|
||||
]
|
||||
Command.run(['bash', '-c', ' '.join(bash_command)])
|
||||
pxe_tarball = ArchiveTar(
|
||||
self.archive_name,
|
||||
create_from_file_list=True,
|
||||
file_list=pxe_tarball_files
|
||||
)
|
||||
|
||||
if self.compressed:
|
||||
self.archive_name = pxe_tarball.create(self.target_dir)
|
||||
else:
|
||||
self.archive_name = pxe_tarball.create_xz_compressed(
|
||||
self.target_dir, xz_options=self.xz_options
|
||||
)
|
||||
|
||||
self.result.verify_image_size(
|
||||
self.runtime_config.get_max_size_constraint(),
|
||||
|
||||
@ -55,16 +55,19 @@ class TestPxeBuilder(object):
|
||||
custom_args={'signing_keys': ['key_file_a', 'key_file_b']}
|
||||
)
|
||||
self.pxe.image_name = 'myimage'
|
||||
self.pxe.compressed = True
|
||||
|
||||
@patch('kiwi.builder.pxe.Checksum')
|
||||
@patch('kiwi.builder.pxe.Compress')
|
||||
@patch('kiwi.logger.log.warning')
|
||||
@patch('kiwi.builder.pxe.Command.run')
|
||||
@patch('kiwi.builder.pxe.ArchiveTar')
|
||||
@patch('os.rename')
|
||||
def test_create(
|
||||
self, mock_rename, mock_command, mock_log_warn,
|
||||
self, mock_rename, mock_tar, mock_log_warn,
|
||||
mock_compress, mock_checksum
|
||||
):
|
||||
tar = mock.Mock()
|
||||
mock_tar.return_value = tar
|
||||
compress = mock.Mock()
|
||||
mock_compress.return_value = compress
|
||||
compress.compressed_filename = 'compressed-file-name'
|
||||
@ -93,17 +96,14 @@ class TestPxeBuilder(object):
|
||||
self.setup.export_package_verification.assert_called_once_with(
|
||||
'target_dir'
|
||||
)
|
||||
mock_command.assert_called_once_with(
|
||||
[
|
||||
'bash', '-c',
|
||||
'tar -C target_dir -c --to-stdout '
|
||||
'myimage-42.kernel '
|
||||
'initrd_file_name '
|
||||
'compressed-file-name '
|
||||
'some-image.x86_64-1.2.3.md5 '
|
||||
'| xz -f --threads=0 > '
|
||||
'target_dir/some-image.x86_64-1.2.3.tar.xz'
|
||||
]
|
||||
|
||||
tar.create.assert_called_once_with('target_dir')
|
||||
|
||||
self.pxe.compressed = False
|
||||
self.pxe.create()
|
||||
|
||||
tar.create_xz_compressed.assert_called_once_with(
|
||||
'target_dir', xz_options=['--threads=0']
|
||||
)
|
||||
|
||||
@patch('kiwi.builder.pxe.Checksum')
|
||||
|
||||
Loading…
Reference in New Issue
Block a user