From b40e5c127c547bf8dda307bea40c1f87ce7cbbc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20Sch=C3=A4fer?= Date: Tue, 30 Jul 2024 12:50:54 +0200 Subject: [PATCH] Get rid of debootstrap Replace debootstrap with an apt-get based pre-download of packages followed by a dpkg-deb extraction. This Fixes #2599 --- kiwi/exceptions.py | 6 +- kiwi/package_manager/apt.py | 156 ++++++------------ kiwi/repository/apt.py | 12 +- kiwi/repository/base.py | 3 +- kiwi/repository/dnf.py | 3 +- kiwi/repository/dnf4.py | 4 +- kiwi/repository/dnf5.py | 4 +- kiwi/repository/pacman.py | 4 +- kiwi/repository/zypper.py | 4 +- kiwi/schema/kiwi.rnc | 26 +-- kiwi/schema/kiwi.rng | 25 +-- kiwi/system/prepare.py | 5 +- kiwi/system/setup.py | 4 +- kiwi/tasks/system_prepare.py | 29 +--- kiwi/xml_parse.py | 17 +- kiwi/xsl/convert81to82.xsl | 47 ++++++ kiwi/xsl/master.xsl | 7 +- package/python-kiwi-spec-template | 3 - .../description.buildservice/appliance.kiwi | 2 +- test/data/description/config.xml | 2 +- test/data/example_apt_config.xml | 2 +- test/data/example_arm_disk_size_config.xml | 2 +- test/data/example_btrfs_config.xml | 2 +- test/data/example_config.xml | 2 +- test/data/example_config_target_dir.xml | 2 +- test/data/example_disk_config.xml | 2 +- test/data/example_disk_size_config.xml | 2 +- .../example_disk_size_empty_vol_config.xml | 2 +- .../example_disk_size_oem_volume_config.xml | 2 +- ...e_disk_size_partition_too_small_config.xml | 2 +- .../example_disk_size_partitions_config.xml | 2 +- .../example_disk_size_vol_root_config.xml | 2 +- test/data/example_disk_size_volume_config.xml | 2 +- ...mple_disk_size_volume_too_small_config.xml | 2 +- test/data/example_dot_profile_config.xml | 2 +- test/data/example_dot_profile_live_config.xml | 2 +- test/data/example_include_config.xml | 2 +- ...le_include_config_from_description_dir.xml | 2 +- ...ample_include_config_missing_reference.xml | 2 +- test/data/example_lvm_arch_config.xml | 2 +- .../example_lvm_custom_rootvol_config.xml | 2 +- test/data/example_lvm_default_config.xml | 2 +- test/data/example_lvm_no_root_config.xml | 2 +- .../example_lvm_no_root_full_usr_config.xml | 2 +- test/data/example_lvm_preferred_config.xml | 2 +- test/data/example_multiple_users_config.xml | 2 +- test/data/example_no_default_type.xml | 2 +- .../data/example_no_image_packages_config.xml | 2 +- test/data/example_no_imageinclude_config.xml | 2 +- test/data/example_partitions_config.xml | 2 +- test/data/example_ppc_disk_size_config.xml | 2 +- test/data/example_pxe_config.xml | 2 +- ...le_runtime_checker_boot_desc_not_found.xml | 2 +- test/data/example_runtime_checker_config.xml | 2 +- ...mple_runtime_checker_conflicting_types.xml | 2 +- ...ntime_checker_include_nested_reference.xml | 2 +- ...mple_runtime_checker_no_boot_reference.xml | 2 +- ...ime_checker_no_initrd_system_reference.xml | 2 +- test/data/example_this_path_config.xml | 2 +- test/data/image_info/config.xml | 2 +- .../config.xml | 2 +- .../isoboot/example-distribution/config.xml | 2 +- .../oemboot/example-distribution/config.xml | 2 +- test/data/root-dir/image/config.xml | 2 +- test/unit/package_manager/apt_test.py | 147 +++++------------ test/unit/system/prepare_test.py | 4 +- test/unit/system/setup_test.py | 2 +- test/unit/tasks/system_prepare_test.py | 29 ---- 68 files changed, 220 insertions(+), 413 deletions(-) create mode 100644 kiwi/xsl/convert81to82.xsl diff --git a/kiwi/exceptions.py b/kiwi/exceptions.py index 31891727213..8c2d1e31bd1 100644 --- a/kiwi/exceptions.py +++ b/kiwi/exceptions.py @@ -208,10 +208,10 @@ class KiwiDataStructureError(KiwiError): """ -class KiwiDebootstrapError(KiwiError): +class KiwiDebianBootstrapError(KiwiError): """ - Exception raised if not enough user data to call debootstrap - were provided or the debootstrap has failed. + Exception raised if the bootstrap installation for Debian + based systems has failed """ diff --git a/kiwi/package_manager/apt.py b/kiwi/package_manager/apt.py index a87abf3fea5..a82378fcd21 100644 --- a/kiwi/package_manager/apt.py +++ b/kiwi/package_manager/apt.py @@ -30,11 +30,12 @@ from kiwi.package_manager.base import PackageManagerBase from kiwi.system.root_bind import RootBind from kiwi.repository.apt import RepositoryApt +from kiwi.utils.temporary import Temporary import kiwi.defaults as defaults from kiwi.exceptions import ( - KiwiDebootstrapError, + KiwiDebianBootstrapError, KiwiRequestError, KiwiFileNotFound ) @@ -131,12 +132,11 @@ def process_install_requests_bootstrap( ) -> CommandCallT: """ Process package install requests for bootstrap phase (no chroot) - Either debootstrap or a prebuilt bootstrap package can be used - to bootstrap a new system. + Either a manual unpacking strategy or a prebuilt bootstrap + package can be used to bootstrap a new system. :param object root_bind: - instance of RootBind to manage kernel file systems before - debootstrap call + unused :param str bootstrap_package: package name of a bootstrap package @@ -149,9 +149,7 @@ def process_install_requests_bootstrap( bootstrap_package ) else: - return self._process_install_requests_bootstrap_debootstrap( - root_bind - ) + return self._process_install_requests_bootstrap() def _process_install_requests_bootstrap_prebuild_root( self, bootstrap_package: str @@ -205,117 +203,69 @@ def _process_install_requests_bootstrap_prebuild_root( # Install eventual bootstrap packages as standard system install return self.process_install_requests() - def _process_install_requests_bootstrap_debootstrap( - self, root_bind: RootBind = None - ) -> CommandCallT: + def _process_install_requests_bootstrap(self) -> CommandCallT: """ - Process package install requests for bootstrap phase (no chroot) - The debootstrap program is used to bootstrap a new system + Process package install requests for bootstrap phase (no chroot). - :param object root_bind: instance of RootBind to manage kernel - file systems before debootstrap call - - :raises KiwiDebootstrapError: if no main distribution repository - is configured, if the debootstrap script is not found or if the - debootstrap script execution fails + :raises KiwiDebianBootstrapError :return: process results in command type - :rtype: namedtuple + :rtype: CommandCallT """ - if not self.distribution: - raise KiwiDebootstrapError( - 'No main distribution repository is configured' + # we invoke apt-get install to download all the essential packages. + # With DPkg::Pre-Install-Pkgs, we specify a shell command that will + # receive the list of packages that will be installed on stdin. + # By configuring Debug::pkgDpkgPm=1, apt-get install will not + # actually execute any dpkg commands, so all it does is download + # the essential debs and tell us their full in the apt cache without + # actually installing them. + try: + if 'apt' not in self.package_requests: + self.package_requests.append('apt') + update_cache = [ + 'apt-get' + ] + self.apt_get_args + self.custom_args + [ + 'update' + ] + Command.run( + update_cache, self.command_env ) - bootstrap_script = '/usr/share/debootstrap/scripts/' + \ - self.distribution - if not os.path.exists(bootstrap_script): - raise KiwiDebootstrapError( - 'debootstrap script for %s distribution not found' % - self.distribution + package_names = Temporary(prefix='kiwi_debs_').new_file() + package_extract = Temporary(prefix='kiwi_bootstrap_').new_file() + download_bootstrap = [ + 'apt-get' + ] + self.apt_get_args + self.custom_args + [ + 'install', + '-oDebug::pkgDPkgPm=1', + f'-oDPkg::Pre-Install-Pkgs::=cat >{package_names.name}', + '?essential', + '?exact-name(usr-is-merged)' + ] + self.package_requests + Command.run( + download_bootstrap, self.command_env ) - - # APT package manager does not support bootstrapping. To circumvent - # this limitation there is the debootstrap tool for APT based distros. - # Because of that there is a little overlap between KIWI and - # debootstrap. Debootstrap manages itself the kernel file systems for - # chroot environment, thus we need to umount the kernel file systems - # before calling debootstrap and remount them afterwards. - if root_bind: - root_bind.umount_kernel_file_systems() - - # debootsrap will create its own dev/fd devices - debootstrap_device_node_conflicts = [ - 'dev/fd', - 'dev/pts' - ] - for node in debootstrap_device_node_conflicts: - Path.wipe(os.path.normpath(os.sep.join([self.root_dir, node]))) - - if 'apt' in self.package_requests: - # debootstrap takes care to install apt - self.package_requests.remove('apt') - try: - cmd = ['debootstrap'] - if self.repository.unauthenticated == 'false' and \ - os.path.exists(self.repository.keyring): - cmd.append('--keyring={}'.format(self.repository.keyring)) - else: - cmd.append('--no-check-gpg') - if self.deboostrap_minbase: - cmd.append('--variant=minbase') - if self.package_requests: - cmd.append( - '--include={}'.format(','.join(self.package_requests)) - ) - if self.repository.components: - cmd.append( - '--components={0}'.format( - ','.join(self.repository.components) + with open(package_extract.name, 'w') as install: + install.write( + 'while read -r deb;do echo "{0}";{1}|{2};done <{3}'.format( + 'Unpacking $deb', + 'dpkg-deb --fsys-tarfile $deb', + f'tar -C {self.root_dir} -x', + package_names.name ) ) + Command.run( + ['bash', package_extract.name], self.command_env + ) self.cleanup_requests() - cmd.extend( - [self.distribution, self.root_dir, self.distribution_path] + return Command.call( + update_cache, self.command_env ) - - return Command.call(cmd, self.command_env) except Exception as e: - raise KiwiDebootstrapError( + raise KiwiDebianBootstrapError( '%s: %s' % (type(e).__name__, format(e)) ) - def get_error_details(self) -> str: - """ - Provide further error details - - Read the debootstrap log if available - - :rtype: str - """ - debootstrap_log_file = os.path.join( - self.root_dir, 'debootstrap/debootstrap.log' - ) - if os.path.exists(debootstrap_log_file): - with open(debootstrap_log_file) as log_fd: - return log_fd.read() or 'logfile is empty' - return f'logfile {debootstrap_log_file!r} does not exist' - - def post_process_install_requests_bootstrap( - self, root_bind: RootBind = None, delta_root: bool = False - ) -> None: - """ - Mounts the kernel file systems to the chroot environment is - ready after the bootstrap procedure - - :param object root_bind: - instance of RootBind to manage kernel file systems - :param bool delta_root: - root is derived from a base system - """ - if root_bind: - root_bind.mount_kernel_file_systems(delta_root) - def process_install_requests(self) -> CommandCallT: """ Process package install requests for image phase (chroot) diff --git a/kiwi/repository/apt.py b/kiwi/repository/apt.py index 294dc6ba168..f981d53ffa8 100644 --- a/kiwi/repository/apt.py +++ b/kiwi/repository/apt.py @@ -72,7 +72,6 @@ def post_init(self, custom_args: List = []) -> None: self.distribution: str = '' self.distribution_path: str = '' - self.debootstrap_repo_set = False self.repo_names: List = [] self.components: List = [] @@ -139,8 +138,7 @@ def add_repo( prio: int = None, dist: str = None, components: str = None, user: str = None, secret: str = None, credentials_file: str = None, repo_gpgcheck: bool = None, pkg_gpgcheck: bool = None, - sourcetype: str = None, use_for_bootstrap: bool = False, - customization_script: str = None + sourcetype: str = None, customization_script: str = None ) -> None: """ Add apt_get repository @@ -157,8 +155,6 @@ def add_repo( :param bool repo_gpgcheck: enable repository signature validation :param bool pkg_gpgcheck: unused :param str sourcetype: unused - :param bool use_for_bootstrap: use this repository for the - debootstrap call :param str customization_script: custom script called after the repo file was created """ @@ -190,10 +186,8 @@ def add_repo( else: # create a debian distributon repository setup for the # specified distributon name and components - if not self.debootstrap_repo_set: - self.distribution = dist - self.distribution_path = uri - self.debootstrap_repo_set = use_for_bootstrap + self.distribution = dist + self.distribution_path = uri repo_details += 'Suites: ' + dist + os.linesep repo_details += 'Components: ' + components + os.linesep if repo_gpgcheck is False: diff --git a/kiwi/repository/base.py b/kiwi/repository/base.py index e7dbdfda7c7..3af266aee1c 100644 --- a/kiwi/repository/base.py +++ b/kiwi/repository/base.py @@ -77,7 +77,7 @@ def add_repo( self, name: str, uri: str, repo_type: str, prio: int, dist: str, components: str, user: str, secret: str, credentials_file: str, repo_gpgcheck: bool, pkg_gpgcheck: bool, sourcetype: str, - use_for_bootstrap: bool = False, customization_script: str = None + customization_script: str = None ) -> None: """ Add repository @@ -96,7 +96,6 @@ def add_repo( :param bool repo_gpgcheck: unused :param bool pkg_gpgcheck: unused :param str sourcetype: unused - :param bool use_for_bootstrap: unused :param str customization_script: unused """ raise NotImplementedError diff --git a/kiwi/repository/dnf.py b/kiwi/repository/dnf.py index bd0d17bc8d5..f7f2c84ce76 100644 --- a/kiwi/repository/dnf.py +++ b/kiwi/repository/dnf.py @@ -51,8 +51,7 @@ def add_repo( prio: int = None, dist: str = None, components: str = None, user: str = None, secret: str = None, credentials_file: str = None, repo_gpgcheck: bool = False, pkg_gpgcheck: bool = False, - sourcetype: str = None, use_for_bootstrap: bool = False, - customization_script: str = None + sourcetype: str = None, customization_script: str = None ) -> None: pass # pragma: no cover diff --git a/kiwi/repository/dnf4.py b/kiwi/repository/dnf4.py index c2eed578579..542d8e10921 100644 --- a/kiwi/repository/dnf4.py +++ b/kiwi/repository/dnf4.py @@ -192,8 +192,7 @@ def add_repo( prio: int = None, dist: str = None, components: str = None, user: str = None, secret: str = None, credentials_file: str = None, repo_gpgcheck: bool = False, pkg_gpgcheck: bool = False, - sourcetype: str = None, use_for_bootstrap: bool = False, - customization_script: str = None + sourcetype: str = None, customization_script: str = None ) -> None: """ Add dnf repository @@ -211,7 +210,6 @@ def add_repo( :param bool pkg_gpgcheck: enable package signature validation :param str sourcetype: source type, one of 'baseurl', 'metalink' or 'mirrorlist' - :param bool use_for_bootstrap: unused :param str customization_script: custom script called after the repo file was created """ diff --git a/kiwi/repository/dnf5.py b/kiwi/repository/dnf5.py index d6734ac43fc..a02b6f55544 100644 --- a/kiwi/repository/dnf5.py +++ b/kiwi/repository/dnf5.py @@ -192,8 +192,7 @@ def add_repo( prio: int = None, dist: str = None, components: str = None, user: str = None, secret: str = None, credentials_file: str = None, repo_gpgcheck: bool = False, pkg_gpgcheck: bool = False, - sourcetype: str = None, use_for_bootstrap: bool = False, - customization_script: str = None + sourcetype: str = None, customization_script: str = None ) -> None: """ Add dnf repository @@ -211,7 +210,6 @@ def add_repo( :param bool pkg_gpgcheck: enable package signature validation :param str sourcetype: source type, one of 'baseurl', 'metalink' or 'mirrorlist' - :param bool use_for_bootstrap: unused :param str customization_script: custom script called after the repo file was created """ diff --git a/kiwi/repository/pacman.py b/kiwi/repository/pacman.py index edc6a50e8a4..85eb4bed3bc 100644 --- a/kiwi/repository/pacman.py +++ b/kiwi/repository/pacman.py @@ -115,8 +115,7 @@ def add_repo( prio: int = None, dist: str = None, components: str = None, user: str = None, secret: str = None, credentials_file: str = None, repo_gpgcheck: bool = False, pkg_gpgcheck: bool = False, - sourcetype: str = None, use_for_bootstrap: bool = False, - customization_script: str = None + sourcetype: str = None, customization_script: str = None ) -> None: """ Add pacman repository @@ -133,7 +132,6 @@ def add_repo( :param bool repo_gpgcheck: enable database signature validation :param bool pkg_gpgcheck: enable package signature validation :param str sourcetype: unused - :param bool use_for_bootstrap: unused :param str customization_script: custom script called after the repo file was created """ diff --git a/kiwi/repository/zypper.py b/kiwi/repository/zypper.py index 7f53bebcb4c..93a80b86c5a 100644 --- a/kiwi/repository/zypper.py +++ b/kiwi/repository/zypper.py @@ -252,8 +252,7 @@ def add_repo( prio: int = None, dist: str = None, components: str = None, user: str = None, secret: str = None, credentials_file: str = None, repo_gpgcheck: bool = False, pkg_gpgcheck: bool = False, - sourcetype: str = None, use_for_bootstrap: bool = False, - customization_script: str = None + sourcetype: str = None, customization_script: str = None ) -> None: """ Add zypper repository @@ -270,7 +269,6 @@ def add_repo( :param bool repo_gpgcheck: enable repository signature validation :param bool pkg_gpgcheck: enable package signature validation :param str sourcetype: unused - :param boot use_for_bootstrap: unused :param str customization_script: custom script called after the repo file was created """ diff --git a/kiwi/schema/kiwi.rnc b/kiwi/schema/kiwi.rnc index 3185e28448b..a6ddae0285f 100644 --- a/kiwi/schema/kiwi.rnc +++ b/kiwi/schema/kiwi.rnc @@ -66,7 +66,7 @@ div { attribute xsi:schemaLocation { xsd:anyURI } k.image.schemaversion.attribute = ## The allowed Schema version (fixed value) - attribute schemaversion { "8.1" } + attribute schemaversion { "8.2" } k.image.id = ## An identification number which is represented in a file ## named /etc/ImageID @@ -1135,25 +1135,6 @@ div { attribute sourcetype { "baseurl" | "metalink" | "mirrorlist" } - k.repository.use_for_bootstrap.attribute = - ## Specify whether this repository should be the one used for - ## bootstrapping or not. False by default. Only a single repository - ## is allowed to be used for bootstrapping. If none is set the - ## last one is picked. - attribute use_for_bootstrap { xsd:boolean } - >> sch:pattern [ id = "use_for_bootstrap" is-a = "repo_type" - sch:param [ name = "attr" value = "use_for_bootstrap" ] - sch:param [ name = "types" value = "apt-deb" ] - ] - >> sch:pattern [ id = "single_deboostrap_repo" - sch:rule [ context = "image" - sch:assert [ - test = "count(repository[@use_for_bootstrap='true'])<=1" - "There can only be a single repository set for " - "bootstrap ('use_for_bootstrap' attribute)" - ] - ] - ] k.repository.attlist = k.repository.type.attribute? & k.repository.profiles.attribute? & @@ -1171,8 +1152,7 @@ div { k.repository.package_gpgcheck.attribute? & k.repository.priority.attribute? & k.repository.password.attribute? & - k.repository.username.attribute? & - k.repository.use_for_bootstrap.attribute? + k.repository.username.attribute? k.repository = ## The Name of the Repository element repository { @@ -3545,7 +3525,7 @@ div { ## The tarball will be unpacked and used as the bootstrap ## rootfs to begin with. The feature is currently only ## available with the apt package manager to allow an - ## alternative bootstrap method for debootstrap + ## alternative bootstrap method attribute bootstrap_package { text } >> sch:pattern [ id = "bootstrap_package" is-a = "packages_type" sch:param [ name = "attr" value = "bootstrap_package" ] diff --git a/kiwi/schema/kiwi.rng b/kiwi/schema/kiwi.rng index d9f451f312c..b50bf6f7903 100644 --- a/kiwi/schema/kiwi.rng +++ b/kiwi/schema/kiwi.rng @@ -150,7 +150,7 @@ second the location of the XSD Schema The allowed Schema version (fixed value) - 8.1 + 8.2 @@ -1728,24 +1728,6 @@ be a simple repository url - - - Specify whether this repository should be the one used for -bootstrapping or not. False by default. Only a single repository -is allowed to be used for bootstrapping. If none is set the -last one is picked. - - - - - - - - - There can only be a single repository set for bootstrap ('use_for_bootstrap' attribute) - - - @@ -1793,9 +1775,6 @@ last one is picked. - - - @@ -5354,7 +5333,7 @@ in /var/cache/kiwi/bootstrap/PACKAGE_NAME.ARCH.tar.xz The tarball will be unpacked and used as the bootstrap rootfs to begin with. The feature is currently only available with the apt package manager to allow an -alternative bootstrap method for debootstrap +alternative bootstrap method diff --git a/kiwi/system/prepare.py b/kiwi/system/prepare.py index 3fd007b2006..50f7aa635be 100644 --- a/kiwi/system/prepare.py +++ b/kiwi/system/prepare.py @@ -170,8 +170,6 @@ def setup_repositories( xml_repo ) repo_sourcetype = xml_repo.get_sourcetype() - repo_use_for_bootstrap = \ - True if xml_repo.get_use_for_bootstrap() else False log.info( 'Setting up repository %s', Uri.print_sensitive(repo_source) ) @@ -211,8 +209,7 @@ def setup_repositories( repo_type, repo_priority, repo_dist, repo_components, repo_user, repo_secret, uri.credentials_file_name(), repo_repository_gpgcheck, repo_package_gpgcheck, - repo_sourcetype, repo_use_for_bootstrap, - repo_customization_script + repo_sourcetype, repo_customization_script ) if clear_cache: repo.delete_repo_cache(repo_alias) diff --git a/kiwi/system/setup.py b/kiwi/system/setup.py index 741500711f9..6098fd3bb4f 100644 --- a/kiwi/system/setup.py +++ b/kiwi/system/setup.py @@ -161,7 +161,6 @@ def import_repositories_marked_as_imageinclude(self) -> None: xml_repo ) repo_sourcetype = xml_repo.get_sourcetype() - repo_use_for_bootstrap = False uri = Uri(repo_source, repo_type) repo_source_translated = uri.translate( check_build_environment=False @@ -185,8 +184,7 @@ def import_repositories_marked_as_imageinclude(self) -> None: repo_type, repo_priority, repo_dist, repo_components, repo_user, repo_secret, uri.credentials_file_name(), repo_repository_gpgcheck, repo_package_gpgcheck, - repo_sourcetype, repo_use_for_bootstrap, - repo_customization_script + repo_sourcetype, repo_customization_script ) def import_cdroot_files(self, target_dir: str) -> None: diff --git a/kiwi/tasks/system_prepare.py b/kiwi/tasks/system_prepare.py index 87151a42642..829a458a71b 100644 --- a/kiwi/tasks/system_prepare.py +++ b/kiwi/tasks/system_prepare.py @@ -128,9 +128,6 @@ from kiwi.system.setup import SystemSetup from kiwi.defaults import Defaults from kiwi.system.profile import Profile -from kiwi.command import Command - -from kiwi.exceptions import KiwiCommandError log = logging.getLogger('kiwi') @@ -252,29 +249,9 @@ def process(self): ] + self.xml_state.get_repositories_signing_keys(), self.global_args['--target-arch'] ) as manager: - run_bootstrap = True - if self.xml_state.get_package_manager() == 'apt' and \ - self.command_args['--allow-existing-root']: - # try to call apt-get inside of the existing root. - # If the call succeeds we skip calling debootstrap again - # and assume the root to be ok to proceed with apt-get - # if it fails, treat the root as dirty and give the - # bootstrap a try - try: - Command.run( - ['chroot', abs_root_path, 'apt-get', '--version'] - ) - run_bootstrap = False - log.warning( - 'debootstrap will only be called once, skipped' - ) - except KiwiCommandError: - run_bootstrap = True - - if run_bootstrap: - system.install_bootstrap( - manager, self.command_args['--add-bootstrap-package'] - ) + system.install_bootstrap( + manager, self.command_args['--add-bootstrap-package'] + ) setup = SystemSetup( self.xml_state, abs_root_path diff --git a/kiwi/xml_parse.py b/kiwi/xml_parse.py index b3ec3e3b1a6..d6168ed8383 100644 --- a/kiwi/xml_parse.py +++ b/kiwi/xml_parse.py @@ -2442,7 +2442,7 @@ class repository(k_source): """The Name of the Repository""" subclass = None superclass = k_source - def __init__(self, source=None, type_=None, profiles=None, arch=None, alias=None, sourcetype=None, components=None, distribution=None, imageinclude=None, imageonly=None, repository_gpgcheck=None, customize=None, package_gpgcheck=None, priority=None, password=None, username=None, use_for_bootstrap=None): + def __init__(self, source=None, type_=None, profiles=None, arch=None, alias=None, sourcetype=None, components=None, distribution=None, imageinclude=None, imageonly=None, repository_gpgcheck=None, customize=None, package_gpgcheck=None, priority=None, password=None, username=None): self.original_tagname_ = None super(repository, self).__init__(source, ) self.type_ = _cast(None, type_) @@ -2460,7 +2460,6 @@ def __init__(self, source=None, type_=None, profiles=None, arch=None, alias=None self.priority = _cast(int, priority) self.password = _cast(None, password) self.username = _cast(None, username) - self.use_for_bootstrap = _cast(bool, use_for_bootstrap) def factory(*args_, **kwargs_): if CurrentSubclassModule_ is not None: subclass = getSubclassFromModule_( @@ -2502,8 +2501,6 @@ def get_password(self): return self.password def set_password(self, password): self.password = password def get_username(self): return self.username def set_username(self, username): self.username = username - def get_use_for_bootstrap(self): return self.use_for_bootstrap - def set_use_for_bootstrap(self, use_for_bootstrap): self.use_for_bootstrap = use_for_bootstrap def validate_arch_name(self, value): # Validate type arch-name, a restriction on xs:token. if value is not None and Validate_simpletypes_: @@ -2593,9 +2590,6 @@ def exportAttributes(self, outfile, level, already_processed, namespaceprefix_=' if self.username is not None and 'username' not in already_processed: already_processed.add('username') outfile.write(' username=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.username), input_name='username')), )) - if self.use_for_bootstrap is not None and 'use_for_bootstrap' not in already_processed: - already_processed.add('use_for_bootstrap') - outfile.write(' use_for_bootstrap="%s"' % self.gds_format_boolean(self.use_for_bootstrap, input_name='use_for_bootstrap')) def exportChildren(self, outfile, level, namespaceprefix_='', name_='repository', fromsubclass_=False, pretty_print=True): super(repository, self).exportChildren(outfile, level, namespaceprefix_, name_, True, pretty_print=pretty_print) def build(self, node): @@ -2695,15 +2689,6 @@ def buildAttributes(self, node, attrs, already_processed): if value is not None and 'username' not in already_processed: already_processed.add('username') self.username = value - value = find_attr_value_('use_for_bootstrap', node) - if value is not None and 'use_for_bootstrap' not in already_processed: - already_processed.add('use_for_bootstrap') - if value in ('true', '1'): - self.use_for_bootstrap = True - elif value in ('false', '0'): - self.use_for_bootstrap = False - else: - raise_parse_error(node, 'Bad boolean attribute') super(repository, self).buildAttributes(node, attrs, already_processed) def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): super(repository, self).buildChildren(child_, node, nodeName_, True) diff --git a/kiwi/xsl/convert81to82.xsl b/kiwi/xsl/convert81to82.xsl new file mode 100644 index 00000000000..7f964fd695b --- /dev/null +++ b/kiwi/xsl/convert81to82.xsl @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + Changed attribute schemaversion + to schemaversion from + 8.1 to 8.2. + + + + + + + + + + + + + + + + + + + + Delete obsolete use_for_bootstrap attribute from repository + + + + + + + + + diff --git a/kiwi/xsl/master.xsl b/kiwi/xsl/master.xsl index ed59bf4bf6a..3c492e84bfc 100644 --- a/kiwi/xsl/master.xsl +++ b/kiwi/xsl/master.xsl @@ -10,6 +10,7 @@ + @@ -35,8 +36,12 @@ + + + + diff --git a/package/python-kiwi-spec-template b/package/python-kiwi-spec-template index 8031c89b933..91dd4e26035 100644 --- a/package/python-kiwi-spec-template +++ b/package/python-kiwi-spec-template @@ -125,12 +125,10 @@ Provides: kiwi-image:tbz # tools conditionally used by kiwi %if 0%{?fedora} || 0%{?rhel} >= 8 Recommends: gnupg2 -Recommends: debootstrap Recommends: dpkg %endif %if 0%{?suse_version} Recommends: gpg2 -Recommends: debootstrap Recommends: dpkg %if 0%{?suse_version} >= 1650 Recommends: dnf @@ -158,7 +156,6 @@ Requires: zypper Provides: kiwi-packagemanager:zypper %endif %if 0%{?debian} || 0%{?ubuntu} -Requires: debootstrap Requires: dpkg Requires: gnupg %endif diff --git a/test/data/description.buildservice/appliance.kiwi b/test/data/description.buildservice/appliance.kiwi index f6f3e2602ec..a3923214b1d 100644 --- a/test/data/description.buildservice/appliance.kiwi +++ b/test/data/description.buildservice/appliance.kiwi @@ -1,6 +1,6 @@ - + diff --git a/test/data/description/config.xml b/test/data/description/config.xml index f6f3e2602ec..a3923214b1d 100644 --- a/test/data/description/config.xml +++ b/test/data/description/config.xml @@ -1,6 +1,6 @@ - + diff --git a/test/data/example_apt_config.xml b/test/data/example_apt_config.xml index b0f0b6f5238..559c5a43f6d 100644 --- a/test/data/example_apt_config.xml +++ b/test/data/example_apt_config.xml @@ -1,6 +1,6 @@ - + Bob user@example.com diff --git a/test/data/example_arm_disk_size_config.xml b/test/data/example_arm_disk_size_config.xml index 07e69b89019..ccf04075023 100644 --- a/test/data/example_arm_disk_size_config.xml +++ b/test/data/example_arm_disk_size_config.xml @@ -1,6 +1,6 @@ - + Marcus Schäfer ms@suse.com diff --git a/test/data/example_btrfs_config.xml b/test/data/example_btrfs_config.xml index fae55a0d3a4..04a11a0c704 100644 --- a/test/data/example_btrfs_config.xml +++ b/test/data/example_btrfs_config.xml @@ -1,6 +1,6 @@ - + Marcus Schäfer ms@suse.com diff --git a/test/data/example_config.xml b/test/data/example_config.xml index d678faeafe9..ee96011c621 100644 --- a/test/data/example_config.xml +++ b/test/data/example_config.xml @@ -1,6 +1,6 @@ - + diff --git a/test/data/example_config_target_dir.xml b/test/data/example_config_target_dir.xml index 193b45c0d63..ba7c660bf01 100644 --- a/test/data/example_config_target_dir.xml +++ b/test/data/example_config_target_dir.xml @@ -1,6 +1,6 @@ - + diff --git a/test/data/example_disk_config.xml b/test/data/example_disk_config.xml index d31e8b08bf8..474c2e0e9fb 100644 --- a/test/data/example_disk_config.xml +++ b/test/data/example_disk_config.xml @@ -1,6 +1,6 @@ - + Marcus Schäfer ms@suse.com diff --git a/test/data/example_disk_size_config.xml b/test/data/example_disk_size_config.xml index b71df422988..debda2c04ad 100644 --- a/test/data/example_disk_size_config.xml +++ b/test/data/example_disk_size_config.xml @@ -1,6 +1,6 @@ - + Marcus Schäfer ms@suse.com diff --git a/test/data/example_disk_size_empty_vol_config.xml b/test/data/example_disk_size_empty_vol_config.xml index 1a6c537ca90..ccfb63f5f14 100644 --- a/test/data/example_disk_size_empty_vol_config.xml +++ b/test/data/example_disk_size_empty_vol_config.xml @@ -1,6 +1,6 @@ - + Marcus Schäfer ms@suse.com diff --git a/test/data/example_disk_size_oem_volume_config.xml b/test/data/example_disk_size_oem_volume_config.xml index f848749afa0..66d50d9b481 100644 --- a/test/data/example_disk_size_oem_volume_config.xml +++ b/test/data/example_disk_size_oem_volume_config.xml @@ -1,6 +1,6 @@ - + Marcus Schäfer ms@suse.com diff --git a/test/data/example_disk_size_partition_too_small_config.xml b/test/data/example_disk_size_partition_too_small_config.xml index e7aa1bbadab..186a5056fa1 100644 --- a/test/data/example_disk_size_partition_too_small_config.xml +++ b/test/data/example_disk_size_partition_too_small_config.xml @@ -1,6 +1,6 @@ - + Marcus Schäfer ms@suse.com diff --git a/test/data/example_disk_size_partitions_config.xml b/test/data/example_disk_size_partitions_config.xml index 816d1b1c4a1..601909c65a6 100644 --- a/test/data/example_disk_size_partitions_config.xml +++ b/test/data/example_disk_size_partitions_config.xml @@ -1,6 +1,6 @@ - + Marcus Schäfer ms@suse.com diff --git a/test/data/example_disk_size_vol_root_config.xml b/test/data/example_disk_size_vol_root_config.xml index 75e235f3628..bf663aae9ee 100644 --- a/test/data/example_disk_size_vol_root_config.xml +++ b/test/data/example_disk_size_vol_root_config.xml @@ -1,6 +1,6 @@ - + Marcus Schäfer ms@suse.com diff --git a/test/data/example_disk_size_volume_config.xml b/test/data/example_disk_size_volume_config.xml index 955738a73c2..ee94b005084 100644 --- a/test/data/example_disk_size_volume_config.xml +++ b/test/data/example_disk_size_volume_config.xml @@ -1,6 +1,6 @@ - + Marcus Schäfer ms@suse.com diff --git a/test/data/example_disk_size_volume_too_small_config.xml b/test/data/example_disk_size_volume_too_small_config.xml index a7845f432ec..693290b04ce 100644 --- a/test/data/example_disk_size_volume_too_small_config.xml +++ b/test/data/example_disk_size_volume_too_small_config.xml @@ -1,6 +1,6 @@ - + Marcus Schäfer ms@suse.com diff --git a/test/data/example_dot_profile_config.xml b/test/data/example_dot_profile_config.xml index 22c4d835bc1..8ec726ed4d6 100644 --- a/test/data/example_dot_profile_config.xml +++ b/test/data/example_dot_profile_config.xml @@ -1,6 +1,6 @@ - + Marcus Schäfer ms@suse.com diff --git a/test/data/example_dot_profile_live_config.xml b/test/data/example_dot_profile_live_config.xml index fd98949caaf..77301a023b0 100644 --- a/test/data/example_dot_profile_live_config.xml +++ b/test/data/example_dot_profile_live_config.xml @@ -1,6 +1,6 @@ - + Marcus Schäfer bob@example.com diff --git a/test/data/example_include_config.xml b/test/data/example_include_config.xml index ca3229f3ab9..bc8ba4c20ba 100644 --- a/test/data/example_include_config.xml +++ b/test/data/example_include_config.xml @@ -1,6 +1,6 @@ - + Marcus ms@suse.com diff --git a/test/data/example_include_config_from_description_dir.xml b/test/data/example_include_config_from_description_dir.xml index 778fd0e882e..98da6b7a404 100644 --- a/test/data/example_include_config_from_description_dir.xml +++ b/test/data/example_include_config_from_description_dir.xml @@ -1,6 +1,6 @@ - + Marcus ms@suse.com diff --git a/test/data/example_include_config_missing_reference.xml b/test/data/example_include_config_missing_reference.xml index b2792c288ba..f878f7cd135 100644 --- a/test/data/example_include_config_missing_reference.xml +++ b/test/data/example_include_config_missing_reference.xml @@ -1,6 +1,6 @@ - + Marcus Schäfer ms@suse.com diff --git a/test/data/example_lvm_arch_config.xml b/test/data/example_lvm_arch_config.xml index c0769a1261d..b73ba357b31 100644 --- a/test/data/example_lvm_arch_config.xml +++ b/test/data/example_lvm_arch_config.xml @@ -1,6 +1,6 @@ - + Marcus Schäfer some@some.com diff --git a/test/data/example_lvm_custom_rootvol_config.xml b/test/data/example_lvm_custom_rootvol_config.xml index 331b5945d63..aaf072ab3ba 100644 --- a/test/data/example_lvm_custom_rootvol_config.xml +++ b/test/data/example_lvm_custom_rootvol_config.xml @@ -1,6 +1,6 @@ - + Marcus Schäfer ms@suse.com diff --git a/test/data/example_lvm_default_config.xml b/test/data/example_lvm_default_config.xml index d0a717d582a..ec016d67f13 100644 --- a/test/data/example_lvm_default_config.xml +++ b/test/data/example_lvm_default_config.xml @@ -1,6 +1,6 @@ - + Marcus Schäfer ms@suse.com diff --git a/test/data/example_lvm_no_root_config.xml b/test/data/example_lvm_no_root_config.xml index 4c4efeb011e..f72ff71ec1b 100644 --- a/test/data/example_lvm_no_root_config.xml +++ b/test/data/example_lvm_no_root_config.xml @@ -1,6 +1,6 @@ - + Marcus Schäfer ms@suse.com diff --git a/test/data/example_lvm_no_root_full_usr_config.xml b/test/data/example_lvm_no_root_full_usr_config.xml index bdfa81dd355..9e932325a75 100644 --- a/test/data/example_lvm_no_root_full_usr_config.xml +++ b/test/data/example_lvm_no_root_full_usr_config.xml @@ -1,6 +1,6 @@ - + Marcus Schäfer ms@suse.com diff --git a/test/data/example_lvm_preferred_config.xml b/test/data/example_lvm_preferred_config.xml index 4ee650a9d7f..7f81a6102d4 100644 --- a/test/data/example_lvm_preferred_config.xml +++ b/test/data/example_lvm_preferred_config.xml @@ -1,6 +1,6 @@ - + Marcus Schäfer ms@suse.com diff --git a/test/data/example_multiple_users_config.xml b/test/data/example_multiple_users_config.xml index eff76a83d8e..5a622a1d9a7 100644 --- a/test/data/example_multiple_users_config.xml +++ b/test/data/example_multiple_users_config.xml @@ -1,6 +1,6 @@ - + Marcus Schäfer ms@suse.com diff --git a/test/data/example_no_default_type.xml b/test/data/example_no_default_type.xml index 165b1d921de..e226ab24cea 100644 --- a/test/data/example_no_default_type.xml +++ b/test/data/example_no_default_type.xml @@ -1,6 +1,6 @@ - + Marcus Schäfer ms@suse.com diff --git a/test/data/example_no_image_packages_config.xml b/test/data/example_no_image_packages_config.xml index 40625c950ec..b57aeeabb50 100644 --- a/test/data/example_no_image_packages_config.xml +++ b/test/data/example_no_image_packages_config.xml @@ -1,6 +1,6 @@ - + Marcus Schäfer ms@suse.com diff --git a/test/data/example_no_imageinclude_config.xml b/test/data/example_no_imageinclude_config.xml index 76951b181fc..b7148b52d11 100644 --- a/test/data/example_no_imageinclude_config.xml +++ b/test/data/example_no_imageinclude_config.xml @@ -1,6 +1,6 @@ - + Marcus Schäfer ms@suse.com diff --git a/test/data/example_partitions_config.xml b/test/data/example_partitions_config.xml index ffe2fdaf1b1..7595248094a 100644 --- a/test/data/example_partitions_config.xml +++ b/test/data/example_partitions_config.xml @@ -1,6 +1,6 @@ - + Marcus Schäfer ms@suse.com diff --git a/test/data/example_ppc_disk_size_config.xml b/test/data/example_ppc_disk_size_config.xml index 423610b410c..01badb05e07 100644 --- a/test/data/example_ppc_disk_size_config.xml +++ b/test/data/example_ppc_disk_size_config.xml @@ -1,6 +1,6 @@ - + Marcus Schäfer ms@suse.com diff --git a/test/data/example_pxe_config.xml b/test/data/example_pxe_config.xml index 185ee8840a6..bb281221f3c 100644 --- a/test/data/example_pxe_config.xml +++ b/test/data/example_pxe_config.xml @@ -1,6 +1,6 @@ - + Marcus Schäfer ms@suse.com diff --git a/test/data/example_runtime_checker_boot_desc_not_found.xml b/test/data/example_runtime_checker_boot_desc_not_found.xml index c38a72c511e..7b637d91a5c 100644 --- a/test/data/example_runtime_checker_boot_desc_not_found.xml +++ b/test/data/example_runtime_checker_boot_desc_not_found.xml @@ -1,6 +1,6 @@ - + Marcus Schäfer ms@suse.com diff --git a/test/data/example_runtime_checker_config.xml b/test/data/example_runtime_checker_config.xml index bade09c3d8b..fd292c97fca 100644 --- a/test/data/example_runtime_checker_config.xml +++ b/test/data/example_runtime_checker_config.xml @@ -1,6 +1,6 @@ - + diff --git a/test/data/example_runtime_checker_conflicting_types.xml b/test/data/example_runtime_checker_conflicting_types.xml index 20cfffbcad2..3de1aae13f8 100644 --- a/test/data/example_runtime_checker_conflicting_types.xml +++ b/test/data/example_runtime_checker_conflicting_types.xml @@ -1,6 +1,6 @@ - + Marcus Schäfer ms@suse.de diff --git a/test/data/example_runtime_checker_include_nested_reference.xml b/test/data/example_runtime_checker_include_nested_reference.xml index 8db6c5f613f..db52f38e70e 100644 --- a/test/data/example_runtime_checker_include_nested_reference.xml +++ b/test/data/example_runtime_checker_include_nested_reference.xml @@ -1,6 +1,6 @@ - + Marcus Schäfer ms@suse.com diff --git a/test/data/example_runtime_checker_no_boot_reference.xml b/test/data/example_runtime_checker_no_boot_reference.xml index 014902f7173..27c5bb613e5 100644 --- a/test/data/example_runtime_checker_no_boot_reference.xml +++ b/test/data/example_runtime_checker_no_boot_reference.xml @@ -1,6 +1,6 @@ - + Marcus Schäfer ms@suse.com diff --git a/test/data/example_runtime_checker_no_initrd_system_reference.xml b/test/data/example_runtime_checker_no_initrd_system_reference.xml index e0052ab2738..9d87e3e282d 100644 --- a/test/data/example_runtime_checker_no_initrd_system_reference.xml +++ b/test/data/example_runtime_checker_no_initrd_system_reference.xml @@ -1,6 +1,6 @@ - + Marcus Schäfer ms@suse.com diff --git a/test/data/example_this_path_config.xml b/test/data/example_this_path_config.xml index 8cf28f90274..004fb739042 100644 --- a/test/data/example_this_path_config.xml +++ b/test/data/example_this_path_config.xml @@ -1,6 +1,6 @@ - + Marcus Schäfer ms@suse.com diff --git a/test/data/image_info/config.xml b/test/data/image_info/config.xml index 7b84acd842e..356cf474974 100644 --- a/test/data/image_info/config.xml +++ b/test/data/image_info/config.xml @@ -1,6 +1,6 @@ - + Marcus ms@suse.com diff --git a/test/data/isoboot/example-distribution-no-delete-section/config.xml b/test/data/isoboot/example-distribution-no-delete-section/config.xml index 2f81d8597e3..17ac605c830 100644 --- a/test/data/isoboot/example-distribution-no-delete-section/config.xml +++ b/test/data/isoboot/example-distribution-no-delete-section/config.xml @@ -1,6 +1,6 @@ - + Marcus Schaefer ms@novell.com diff --git a/test/data/isoboot/example-distribution/config.xml b/test/data/isoboot/example-distribution/config.xml index 4e7bf2f8c5f..b4cce21d3a1 100644 --- a/test/data/isoboot/example-distribution/config.xml +++ b/test/data/isoboot/example-distribution/config.xml @@ -1,6 +1,6 @@ - + Marcus Schaefer ms@novell.com diff --git a/test/data/oemboot/example-distribution/config.xml b/test/data/oemboot/example-distribution/config.xml index 8b367b54a28..1f293564893 100644 --- a/test/data/oemboot/example-distribution/config.xml +++ b/test/data/oemboot/example-distribution/config.xml @@ -1,6 +1,6 @@ - + Marcus Schaefer ms@novell.com diff --git a/test/data/root-dir/image/config.xml b/test/data/root-dir/image/config.xml index f6f3e2602ec..a3923214b1d 100644 --- a/test/data/root-dir/image/config.xml +++ b/test/data/root-dir/image/config.xml @@ -1,6 +1,6 @@ - + diff --git a/test/unit/package_manager/apt_test.py b/test/unit/package_manager/apt_test.py index ad95343bfd5..1f78e508e68 100644 --- a/test/unit/package_manager/apt_test.py +++ b/test/unit/package_manager/apt_test.py @@ -1,6 +1,7 @@ import logging +import io from unittest.mock import ( - patch, call, Mock + patch, call, Mock, MagicMock ) from pytest import ( raises, fixture @@ -11,7 +12,7 @@ import kiwi.defaults as defaults from kiwi.exceptions import ( - KiwiDebootstrapError, + KiwiDebianBootstrapError, KiwiRequestError, KiwiFileNotFound ) @@ -100,119 +101,55 @@ def test_process_install_requests_bootstrap_prebuild_root( bootstrap_package='bootstrap-package' ) - def test_process_install_requests_bootstrap_debootstrap_no_dist(self): - self.manager.distribution = None - with raises(KiwiDebootstrapError): - self.manager.process_install_requests_bootstrap() - - @patch('os.path.exists') - def test_process_install_requests_bootstrap_debootstrap_no_script( - self, mock_exists - ): - mock_exists.return_value = False - with raises(KiwiDebootstrapError): - self.manager.process_install_requests_bootstrap() - @patch('kiwi.command.Command.call') - @patch('kiwi.package_manager.apt.os.path.exists') - @patch('kiwi.package_manager.apt.Path.wipe') - def test_process_install_requests_bootstrap_debootstrap_failed( - self, mock_wipe, mock_exists, mock_call + @patch('kiwi.command.Command.run') + def test_process_install_requests_bootstrap_failed( + self, mock_Command_run, mock_Command_call ): self.manager.request_package('apt') - mock_call.side_effect = Exception - mock_exists.return_value = True - mock_root_bind = Mock() - with raises(KiwiDebootstrapError): - self.manager.process_install_requests_bootstrap(mock_root_bind) - - @patch('kiwi.package_manager.apt.os.path.exists') - def test_get_error_details(self, mock_exists): - mock_exists.return_value = True - with patch('builtins.open', create=True) as mock_open: - file_handle = mock_open.return_value.__enter__.return_value - file_handle.read.return_value = 'log-data' - assert self.manager.get_error_details() == \ - file_handle.read.return_value - mock_open.assert_called_once_with( - 'root-dir/debootstrap/debootstrap.log' - ) - - @patch('kiwi.package_manager.apt.os.path.exists') - def test_get_error_details_no_log_file(self, mock_exists): - mock_exists.return_value = False - assert self.manager.get_error_details() == \ - "logfile 'root-dir/debootstrap/debootstrap.log' does not exist" - - @patch('kiwi.package_manager.apt.os.path.exists') - def test_get_error_details_logfile_is_empty(self, mock_exists): - mock_exists.return_value = True - with patch('builtins.open', create=True) as mock_open: - file_handle = mock_open.return_value.__enter__.return_value - file_handle.read.return_value = '' - assert self.manager.get_error_details() == \ - 'logfile is empty' - - @patch('kiwi.command.Command.call') - @patch('kiwi.package_manager.apt.Path.wipe') - @patch('kiwi.package_manager.apt.os.path.exists') - def test_process_install_requests_bootstrap_debootstrap( - self, mock_exists, mock_wipe, mock_call - ): - self.manager.request_package('apt') - self.manager.request_package('vim') - call_result = Mock() - call_result.process.communicate.return_value = ('stdout', 'stderr') - mock_call.return_value = call_result - mock_root_bind = Mock() - mock_exists.return_value = True - self.manager.process_install_requests_bootstrap(mock_root_bind) - mock_call.assert_called_once_with( - [ - 'debootstrap', '--keyring=trusted.gpg', - '--variant=minbase', '--include=vim', - '--components=main,restricted', 'xenial', - 'root-dir', 'xenial_path' - ], ['env'] - ) - assert mock_wipe.call_args_list == [ - call('root-dir/dev/fd'), - call('root-dir/dev/pts') - ] - mock_root_bind.umount_kernel_file_systems.assert_called_once_with() - - def test_post_process_install_requests_bootstrap(self): - mock_root_bind = Mock() - self.manager.post_process_install_requests_bootstrap(mock_root_bind) - mock_root_bind.mount_kernel_file_systems.assert_called_once_with(False) + mock_Command_call.side_effect = Exception + with patch('builtins.open', create=True): + with raises(KiwiDebianBootstrapError): + self.manager.process_install_requests_bootstrap() + @patch('kiwi.command.Command.run') @patch('kiwi.command.Command.call') - @patch('kiwi.package_manager.apt.Path.wipe') - @patch('kiwi.package_manager.apt.os.path.exists') - def test_process_install_requests_bootstrap_debootstrap_no_gpg_check( - self, mock_exists, mock_wipe, mock_call + @patch('kiwi.package_manager.apt.Temporary.new_file') + def test_process_install_requests_bootstrap( + self, mock_Temporary_new_file, mock_Command_call, mock_Command_run ): - self.manager.request_package('apt') + mock_Temporary_new_file.return_value.name = 'temporary' self.manager.request_package('vim') call_result = Mock() call_result.process.communicate.return_value = ('stdout', 'stderr') - mock_root_bind = Mock() - mock_call.return_value = call_result - mock_exists.side_effect = lambda x: True if 'xenial' in x else False - self.manager.process_install_requests_bootstrap(mock_root_bind) - mock_call.assert_called_once_with( - [ - 'debootstrap', '--no-check-gpg', - '--variant=minbase', '--include=vim', - '--components=main,restricted', 'xenial', - 'root-dir', 'xenial_path' - ], ['env'] - ) - assert mock_wipe.call_args_list == [ - call('root-dir/dev/fd'), - call('root-dir/dev/pts') + mock_Command_call.return_value = call_result + with patch('builtins.open', create=True) as mock_open: + mock_open.return_value = MagicMock(spec=io.IOBase) + file_handle = mock_open.return_value.__enter__.return_value + self.manager.process_install_requests_bootstrap() + file_handle.write.assert_called_once_with( + 'while read -r deb;do echo "Unpacking $deb";dpkg-deb' + ' --fsys-tarfile $deb|tar -C root-dir -x;done temporary', + '?essential', + '?exact-name(usr-is-merged)', + 'vim', + 'apt' + ], ['env'] + ), + call( + ['bash', 'temporary'], ['env'] + ) ] - mock_root_bind.umount_kernel_file_systems.assert_called_once_with() @patch('kiwi.command.Command.call') @patch('kiwi.command.Command.run') diff --git a/test/unit/system/prepare_test.py b/test/unit/system/prepare_test.py index 15dc32de13c..d1aa572c199 100644 --- a/test/unit/system/prepare_test.py +++ b/test/unit/system/prepare_test.py @@ -287,12 +287,12 @@ def test_setup_repositories( call( 'uri-alias', 'uri', None, 42, None, None, None, None, 'credentials-file', None, None, - 'baseurl', False, None + 'baseurl', None ), call( 'uri-alias', 'uri', 'rpm-md', None, None, None, None, None, 'credentials-file', None, None, - None, False, '../data/script' + None, '../data/script' ) ] assert repo.delete_repo_cache.call_args_list == [ diff --git a/test/unit/system/setup_test.py b/test/unit/system/setup_test.py index 7799bcb2043..4fe2d43e077 100644 --- a/test/unit/system/setup_test.py +++ b/test/unit/system/setup_test.py @@ -1678,7 +1678,7 @@ def test_import_repositories_marked_as_imageinclude( self.setup_with_real_xml.import_repositories_marked_as_imageinclude() assert repo.add_repo.call_args_list[0] == call( 'uri-alias', 'uri', 'rpm-md', None, None, None, None, None, - 'kiwiRepoCredentials', None, None, None, False, '../data/script' + 'kiwiRepoCredentials', None, None, None, '../data/script' ) @patch('os.path.exists') diff --git a/test/unit/tasks/system_prepare_test.py b/test/unit/tasks/system_prepare_test.py index 11b17537ef9..37e03665919 100644 --- a/test/unit/tasks/system_prepare_test.py +++ b/test/unit/tasks/system_prepare_test.py @@ -10,8 +10,6 @@ from ..test_helper import argv_kiwi_tests -from kiwi.exceptions import KiwiCommandError - from kiwi.tasks.system_prepare import SystemPrepareTask @@ -181,33 +179,6 @@ def test_process_system_prepare(self, mock_SystemPrepare, mock_keys): ) assert system_prepare.clean_package_manager_leftovers.called - @patch('kiwi.xml_state.XMLState.get_package_manager') - @patch('kiwi.tasks.system_prepare.SystemPrepare') - def test_process_system_prepare_run_debootstrap_only_once( - self, mock_SystemPrepare, mock_get_package_manager - ): - manager = MagicMock() - system_prepare = Mock() - system_prepare.setup_repositories = Mock( - return_value=manager - ) - mock_SystemPrepare.return_value.__enter__.return_value = system_prepare - self._init_command_args() - mock_get_package_manager.return_value = 'apt' - self.task.command_args['--allow-existing-root'] = True - - # debootstrap must be called if chroot with apt-get failed - self.command.run.side_effect = KiwiCommandError('error') - self.task.process() - assert system_prepare.install_bootstrap.called - - # debootstrap must not be called if chroot looks good - self.command.run.side_effect = None - system_prepare.install_bootstrap.reset_mock() - with self._caplog.at_level(logging.WARNING): - self.task.process() - assert not system_prepare.install_bootstrap.called - @patch('kiwi.xml_state.XMLState.get_repositories_signing_keys') @patch('kiwi.tasks.system_prepare.SystemPrepare') def test_process_system_prepare_add_package(