def prepare(self): """ Prepare new root system suitable to create a kiwi initrd from it """ self.load_boot_xml_description() boot_image_name = self.boot_xml_state.xml_data.get_name() self.import_system_description_elements() log.info('Preparing boot image') system = SystemPrepare(xml_state=self.boot_xml_state, root_dir=self.boot_root_directory, allow_existing=True) manager = system.setup_repositories(signing_keys=self.signing_keys) system.install_bootstrap(manager) system.install_system(manager) profile = Profile(self.boot_xml_state) profile.add('kiwi_initrdname', boot_image_name) defaults = Defaults() defaults.to_profile(profile) self.setup = SystemSetup(self.boot_xml_state, self.boot_root_directory) self.setup.import_shell_environment(profile) self.setup.import_description() self.setup.import_overlay_files(follow_links=True) self.setup.call_config_script() system.pinch_system(manager=manager, force=True) # make sure system instance is cleaned up before setting up del system self.setup.call_image_script() self.setup.create_init_link_from_linuxrc()
def setup(self): self.tmpfile = mock.Mock() self.tmpfile.name = 'tmpfile' description = XMLDescription('../data/example_dot_profile_config.xml') self.profile = Profile( XMLState(description.load()) )
def _call_script(self, name, option_list=None): script_path = os.path.join(self.root_dir, 'image', name) if os.path.exists(script_path): options = option_list or [] if log.getLogFlags().get('run-scripts-in-screen'): # Run scripts in a screen session if requested command = ['screen', '-t', '-X', 'chroot', self.root_dir] else: # In standard mode run scripts without a terminal # associated to them command = ['chroot', self.root_dir] if not Path.access(script_path, os.X_OK): command.append('bash') command.append( os.path.join(defaults.IMAGE_METADATA_DIR, name) ) command.extend(options) profile = Profile(self.xml_state) caller_environment = copy.deepcopy(os.environ) caller_environment.update(profile.get_settings()) config_script = Command.call(command, caller_environment) process = CommandProcess( command=config_script, log_topic='Calling ' + name + ' script' ) result = process.poll_and_watch() if result.returncode != 0: raise KiwiScriptFailed( '{0} failed: {1}'.format(name, result.stderr) )
def test_create_cpio(self, mock_temp): mock_temp.return_value = self.tmpfile description = XMLDescription('../data/example_dot_profile_config.xml') profile = Profile(XMLState(description.load(), None, 'cpio')) profile.create() os.remove(self.tmpfile.name) assert profile.dot_profile[ 'kiwi_cpio_name'] == 'LimeJeOS-openSUSE-13.2'
def test_create_displayname_is_image_name(self, mock_which): mock_which.return_value = 'cp' description = XMLDescription('../data/example_pxe_config.xml') profile = Profile(XMLState(description.load())) profile.create(self.profile_file) os.remove(self.profile_file) assert profile.dot_profile['kiwi_displayname'] == \ 'LimeJeOS-openSUSE-13.2'
def test_create_cpio(self, mock_shell_quote, mock_open, mock_temp): mock_temp.return_value = self.tmpfile description = XMLDescription('../data/example_dot_profile_config.xml') profile = Profile( XMLState(description.load(), None, 'cpio') ) profile.create() assert profile.dot_profile['kiwi_cpio_name'] == 'LimeJeOS-openSUSE-13.2'
def test_create_displayname_is_image_name(self, mock_which, mock_temp): mock_which.return_value = 'cp' mock_temp.return_value = self.tmpfile description = XMLDescription('../data/example_pxe_config.xml') profile = Profile( XMLState(description.load()) ) profile.create() os.remove(self.tmpfile.name) assert profile.dot_profile['kiwi_displayname'] == 'LimeJeOS-openSUSE-13.2'
def test_create_displayname_is_image_name(self, mock_which, mock_temp): mock_which.return_value = 'cp' mock_temp.return_value = self.tmpfile description = XMLDescription('../data/example_pxe_config.xml') profile = Profile(XMLState(description.load())) profile.create(self.profile_file) os.remove(self.tmpfile.name) os.remove(self.profile_file) assert profile.dot_profile['kiwi_displayname'] == \ 'openSUSE-13.2_appliance'
def _call_script(self, name, option_list=None): script_path = os.path.join(self.root_dir, 'image', name) if os.path.exists(script_path): options = option_list or [] command = ['chroot', self.root_dir] if not Path.access(script_path, os.X_OK): command.append('bash') command.append(os.path.join(defaults.IMAGE_METADATA_DIR, name)) command.extend(options) profile = Profile(self.xml_state) caller_environment = copy.deepcopy(os.environ) caller_environment.update(profile.get_settings()) config_script = Command.call(command, caller_environment) process = CommandProcess(command=config_script, log_topic='Calling ' + name + ' script') result = process.poll_and_watch() if result.returncode != 0: raise KiwiScriptFailed('{0} failed: {1}'.format( name, result.stderr))
def prepare(self): """ Prepare kiwi profile environment to be included in dracut initrd """ profile = Profile(self.xml_state) defaults = Defaults() defaults.to_profile(profile) setup = SystemSetup(self.xml_state, self.boot_root_directory) setup.import_shell_environment(profile) self.dracut_options.append('--install') self.dracut_options.append('/.profile')
def prepare(self): """ Prepare dracut caller environment * Create kiwi .profile environment to be included in dracut initrd * Setup machine_id(s) to be generic and rebuild by dracut on boot """ profile = Profile(self.xml_state) defaults = Defaults() defaults.to_profile(profile) setup = SystemSetup(self.xml_state, self.boot_root_directory) setup.import_shell_environment(profile) setup.setup_machine_id() self.dracut_options.append('--install') self.dracut_options.append('/.profile')
def prepare(self) -> None: """ Prepare new root system suitable to create a kiwi initrd from it """ if self.boot_xml_state: self.boot_root_directory_temporary = Temporary( prefix='kiwi_boot_root.', path=self.target_dir).new_dir() self.boot_root_directory = self.boot_root_directory_temporary.name self.temp_directories.append(self.boot_root_directory) boot_image_name = self.boot_xml_state.xml_data.get_name() self.import_system_description_elements() log.info('Preparing boot image') system = SystemPrepare(xml_state=self.boot_xml_state, root_dir=self.boot_root_directory, allow_existing=True) manager = system.setup_repositories(signing_keys=self.signing_keys, target_arch=self.target_arch) system.install_bootstrap(manager) system.install_system(manager) profile = Profile(self.boot_xml_state) profile.add('kiwi_initrdname', boot_image_name) defaults = Defaults() defaults.to_profile(profile) self.setup = SystemSetup(self.boot_xml_state, self.boot_root_directory) profile.create(Defaults.get_profile_file(self.boot_root_directory)) self.setup.import_description() self.setup.import_overlay_files(follow_links=True) self.setup.call_config_script() system.pinch_system(manager=manager, force=True) # make sure system instance is cleaned up before setting up del system self.setup.call_image_script() self.setup.create_init_link_from_linuxrc()
class TestProfile: def setup(self): self.tmpfile = mock.Mock() self.tmpfile.name = 'tmpfile' self.profile_file = 'tmpfile.profile' description = XMLDescription('../data/example_dot_profile_config.xml') self.profile = Profile(XMLState(description.load())) @patch('kiwi.system.profile.NamedTemporaryFile') @patch('kiwi.path.Path.which') def test_create(self, mock_which, mock_temp): mock_which.return_value = 'cp' mock_temp.return_value = self.tmpfile self.profile.create(self.profile_file) os.remove(self.tmpfile.name) os.remove(self.profile_file) assert self.profile.dot_profile == { 'kiwi_Volume_1': 'usr_lib|size:1024|usr/lib', 'kiwi_Volume_2': 'LVRoot|freespace:500|', 'kiwi_Volume_3': 'etc_volume|freespace:30|etc', 'kiwi_Volume_4': 'bin_volume|size:all|/usr/bin', 'kiwi_Volume_5': 'usr_bin|freespace:30|usr/bin', 'kiwi_Volume_6': 'LVSwap|size:128|', 'kiwi_bootkernel': None, 'kiwi_bootloader': 'grub2', 'kiwi_bootprofile': None, 'kiwi_target_removable': None, 'kiwi_boot_timeout': None, 'kiwi_cmdline': 'splash', 'kiwi_compressed': None, 'kiwi_delete': '', 'kiwi_devicepersistency': None, 'kiwi_bootloader_console': None, 'kiwi_displayname': 'schäfer', 'kiwi_drivers': '', 'kiwi_firmware': 'efi', 'kiwi_fsmountoptions': None, 'kiwi_hybridpersistent_filesystem': None, 'kiwi_hybridpersistent': None, 'kiwi_iname': 'LimeJeOS-openSUSE-13.2', 'kiwi_installboot': None, 'kiwi_iversion': '1.13.2', 'kiwi_keytable': 'us.map.gz', 'kiwi_language': 'en_US', 'kiwi_loader_theme': 'openSUSE', 'kiwi_lvm': 'true', 'kiwi_lvmgroup': 'systemVG', 'kiwi_oembootwait': None, 'kiwi_oemdevicefilter': None, 'kiwi_oemnicfilter': None, 'kiwi_oemkboot': None, 'kiwi_oemmultipath_scan': None, 'kiwi_oempartition_install': None, 'kiwi_oemrebootinteractive': None, 'kiwi_oemreboot': None, 'kiwi_oemrecoveryID': None, 'kiwi_oemrecoveryInPlace': None, 'kiwi_oemrecovery': False, 'kiwi_oemrecoveryPartSize': None, 'kiwi_oemrootMB': 2048, 'kiwi_oemshutdowninteractive': None, 'kiwi_oemresizeonce': None, 'kiwi_oemshutdown': None, 'kiwi_oemsilentboot': None, 'kiwi_oemsilentinstall': None, 'kiwi_oemsilentverify': None, 'kiwi_oemskipverify': 'true', 'kiwi_oemswapMB': None, 'kiwi_oemswap': None, 'kiwi_oemtitle': 'schäfer', 'kiwi_oemunattended_id': None, 'kiwi_oemunattended': None, 'kiwi_oemvmcp_parmfile': None, 'kiwi_profiles': '', 'kiwi_ramonly': True, 'kiwi_initrd_system': 'kiwi', 'kiwi_install_volid': 'INSTALL', 'kiwi_btrfs_root_is_snapshot': None, 'kiwi_gpt_hybrid_mbr': None, 'kiwi_showlicense': None, 'kiwi_splash_theme': 'openSUSE', 'kiwi_strip_delete': '', 'kiwi_strip_libs': '', 'kiwi_strip_tools': '', 'kiwi_target_blocksize': None, 'kiwi_timezone': 'Europe/Berlin', 'kiwi_type': 'oem', 'kiwi_vga': None, 'kiwi_startsector': 2048, 'kiwi_wwid_wait_timeout': None, 'kiwi_xendomain': 'dom0', 'kiwi_rootpartuuid': None } @patch('kiwi.system.profile.NamedTemporaryFile') @patch('kiwi.path.Path.which') def test_create_displayname_is_image_name(self, mock_which, mock_temp): mock_which.return_value = 'cp' mock_temp.return_value = self.tmpfile description = XMLDescription('../data/example_pxe_config.xml') profile = Profile(XMLState(description.load())) profile.create(self.profile_file) os.remove(self.tmpfile.name) os.remove(self.profile_file) assert profile.dot_profile['kiwi_displayname'] == \ 'LimeJeOS-openSUSE-13.2' @patch('kiwi.system.profile.NamedTemporaryFile') @patch('kiwi.path.Path.which') def test_create_cpio(self, mock_which, mock_temp): mock_which.return_value = 'cp' mock_temp.return_value = self.tmpfile description = XMLDescription('../data/example_dot_profile_config.xml') profile = Profile(XMLState(description.load(), None, 'cpio')) profile.create(self.profile_file) os.remove(self.tmpfile.name) os.remove(self.profile_file) assert profile.dot_profile['kiwi_cpio_name'] == \ 'LimeJeOS-openSUSE-13.2' def test_add(self): self.profile.add('foo', 'bar') assert self.profile.dot_profile['foo'] == 'bar' def test_delete(self): self.profile.add('foo', 'bar') self.profile.delete('foo') assert 'foo' not in self.profile.dot_profile
def process(self): # noqa: C901 """ Build a system image from the specified description. The build command combines the prepare and create commands """ self.manual = Help() if self._help(): return Privileges.check_for_root_permissions() abs_target_dir_path = os.path.abspath( self.command_args['--target-dir'] ) build_dir = os.sep.join([abs_target_dir_path, 'build']) image_root = os.sep.join([build_dir, 'image-root']) Path.create(build_dir) if not self.global_args['--logfile']: log.set_logfile( os.sep.join([abs_target_dir_path, 'build', 'image-root.log']) ) self.load_xml_description( self.command_args['--description'] ) build_checks = self.checks_before_command_args build_checks.update( { 'check_target_directory_not_in_shared_cache': [abs_target_dir_path] } ) self.run_checks(build_checks) if self.command_args['--ignore-repos']: self.xml_state.delete_repository_sections() elif self.command_args['--ignore-repos-used-for-build']: self.xml_state.delete_repository_sections_used_for_build() if self.command_args['--set-repo']: self.xml_state.set_repository( *self.sextuple_token(self.command_args['--set-repo']) ) if self.command_args['--add-repo']: for add_repo in self.command_args['--add-repo']: self.xml_state.add_repository( *self.sextuple_token(add_repo) ) if self.command_args['--set-container-tag']: self.xml_state.set_container_config_tag( self.command_args['--set-container-tag'] ) if self.command_args['--add-container-label']: for add_label in self.command_args['--add-container-label']: try: (name, value) = add_label.split('=', 1) self.xml_state.add_container_config_label(name, value) except Exception: log.warning( 'Container label {0} ignored. Invalid format: ' 'expected labelname=value'.format(add_label) ) if self.command_args['--set-container-derived-from']: self.xml_state.set_derived_from_image_uri( self.command_args['--set-container-derived-from'] ) self.run_checks(self.checks_after_command_args) log.info('Preparing new root system') system = SystemPrepare( self.xml_state, image_root, self.command_args['--allow-existing-root'] ) manager = system.setup_repositories( self.command_args['--clear-cache'], self.command_args['--signing-key'] ) system.install_bootstrap( manager, self.command_args['--add-bootstrap-package'] ) system.install_system( manager ) if self.command_args['--add-package']: system.install_packages( manager, self.command_args['--add-package'] ) if self.command_args['--delete-package']: system.delete_packages( manager, self.command_args['--delete-package'] ) profile = Profile(self.xml_state) defaults = Defaults() defaults.to_profile(profile) profile.create( Defaults.get_profile_file(image_root) ) setup = SystemSetup( self.xml_state, image_root ) setup.import_description() setup.import_overlay_files() setup.import_image_identifier() setup.setup_groups() setup.setup_users() setup.setup_keyboard_map() setup.setup_locale() setup.setup_plymouth_splash() setup.setup_timezone() setup.setup_permissions() # make sure manager instance is cleaned up now del manager # setup permanent image repositories after cleanup setup.import_repositories_marked_as_imageinclude() setup.call_config_script() # handle uninstall package requests, gracefully uninstall # with dependency cleanup system.pinch_system(force=False) # handle delete package requests, forced uninstall without # any dependency resolution system.pinch_system(force=True) # delete any custom rpm macros created system.clean_package_manager_leftovers() # make sure system instance is cleaned up now del system setup.call_image_script() # make sure setup instance is cleaned up now del setup log.info('Creating system image') image_builder = ImageBuilder.new( self.xml_state, abs_target_dir_path, image_root, custom_args={ 'signing_keys': self.command_args['--signing-key'], 'xz_options': self.runtime_config.get_xz_options() } ) result = image_builder.create() result.print_results() result.dump( os.sep.join([abs_target_dir_path, 'kiwi.result']) )
def _create_profile_environment(self): profile = Profile(self.xml_state) defaults = Defaults() defaults.to_profile(profile) profile.create(Defaults.get_profile_file(self.boot_root_directory))
def process(self): """ Build a system image from the specified description. The build command combines the prepare and create commands """ self.manual = Help() if self._help(): return Privileges.check_for_root_permissions() abs_target_dir_path = os.path.abspath( self.command_args['--target-dir'] ) build_dir = os.sep.join([abs_target_dir_path, 'build']) image_root = os.sep.join([build_dir, 'image-root']) Path.create(build_dir) if not self.global_args['--logfile']: log.set_logfile( os.sep.join([abs_target_dir_path, 'build', 'image-root.log']) ) self.load_xml_description( self.command_args['--description'] ) self.runtime_checker.check_efi_mode_for_disk_overlay_correctly_setup() self.runtime_checker.check_consistent_kernel_in_boot_and_system_image() self.runtime_checker.check_docker_tool_chain_installed() self.runtime_checker.check_volume_setup_has_no_root_definition() self.runtime_checker.check_xen_uniquely_setup_as_server_or_guest() self.runtime_checker.check_target_directory_not_in_shared_cache( abs_target_dir_path ) self.runtime_checker.check_mediacheck_only_for_x86_arch() self.runtime_checker.check_dracut_module_for_live_iso_in_package_list() self.runtime_checker.check_dracut_module_for_disk_overlay_in_package_list() if self.command_args['--ignore-repos']: self.xml_state.delete_repository_sections() elif self.command_args['--ignore-repos-used-for-build']: self.xml_state.delete_repository_sections_used_for_build() if self.command_args['--set-repo']: self.xml_state.set_repository( *self.quintuple_token(self.command_args['--set-repo']) ) if self.command_args['--add-repo']: for add_repo in self.command_args['--add-repo']: self.xml_state.add_repository( *self.quintuple_token(add_repo) ) if self.command_args['--set-container-tag']: self.xml_state.set_container_config_tag( self.command_args['--set-container-tag'] ) if self.command_args['--set-container-derived-from']: self.xml_state.set_derived_from_image_uri( self.command_args['--set-container-derived-from'] ) self.runtime_checker.check_repositories_configured() self.runtime_checker.check_image_include_repos_publicly_resolvable() package_requests = False if self.command_args['--add-package']: package_requests = True if self.command_args['--delete-package']: package_requests = True log.info('Preparing new root system') system = SystemPrepare( self.xml_state, image_root, self.command_args['--allow-existing-root'] ) manager = system.setup_repositories( self.command_args['--clear-cache'], self.command_args['--signing-key'] ) system.install_bootstrap(manager) system.install_system( manager ) if package_requests: if self.command_args['--add-package']: system.install_packages( manager, self.command_args['--add-package'] ) if self.command_args['--delete-package']: system.delete_packages( manager, self.command_args['--delete-package'] ) profile = Profile(self.xml_state) defaults = Defaults() defaults.to_profile(profile) setup = SystemSetup( self.xml_state, image_root ) setup.import_shell_environment(profile) setup.import_description() setup.import_overlay_files() setup.import_image_identifier() setup.setup_groups() setup.setup_users() setup.setup_keyboard_map() setup.setup_locale() setup.setup_plymouth_splash() setup.setup_timezone() system.pinch_system( manager=manager, force=True ) # make sure manager instance is cleaned up now del manager # setup permanent image repositories after cleanup setup.import_repositories_marked_as_imageinclude() setup.call_config_script() # make sure system instance is cleaned up now del system setup.call_image_script() # make sure setup instance is cleaned up now del setup log.info('Creating system image') image_builder = ImageBuilder( self.xml_state, abs_target_dir_path, image_root, custom_args={ 'signing_keys': self.command_args['--signing-key'], 'xz_options': self.runtime_config.get_xz_options() } ) result = image_builder.create() result.print_results() result.dump( os.sep.join([abs_target_dir_path, 'kiwi.result']) )
class TestProfile(object): def setup(self): self.tmpfile = mock.Mock() self.tmpfile.name = 'tmpfile' description = XMLDescription('../data/example_dot_profile_config.xml') self.profile = Profile(XMLState(description.load())) @patch('kiwi.system.profile.NamedTemporaryFile') def test_create(self, mock_temp): mock_temp.return_value = self.tmpfile result = self.profile.create() os.remove(self.tmpfile.name) print(self.profile.dot_profile) assert self.profile.dot_profile == { 'kiwi_allFreeVolume_bin_volume': 'size:all:LVusr_bin', 'kiwi_allFreeVolume_LVusr_bin': 'size:all', 'kiwi_bootkernel': None, 'kiwi_bootloader': 'grub2', 'kiwi_bootprofile': None, 'kiwi_boot_timeout': None, 'kiwi_cmdline': 'splash', 'kiwi_compressed': None, 'kiwi_delete': '', 'kiwi_devicepersistency': None, 'kiwi_bootloader_console': None, 'kiwi_displayname': 'LimeJeOS-openSUSE-13.2', 'kiwi_drivers': '', 'kiwi_firmware': 'efi', 'kiwi_fsmountoptions': None, 'kiwi_hwclock': 'utc', 'kiwi_hybrid': True, 'kiwi_hybridpersistent_filesystem': None, 'kiwi_hybridpersistent': None, 'kiwi_iname': 'LimeJeOS-openSUSE-13.2', 'kiwi_installboot': None, 'kiwi_iversion': '1.13.2', 'kiwi_keytable': 'us.map.gz', 'kiwi_language': 'en_US', 'kiwi_loader_theme': 'openSUSE', 'kiwi_LVM_etc_volume': 'freespace:30:LVetc', 'kiwi_LVM_LVRoot': 'freespace:500', 'kiwi_LVM_LVusr_lib': 'size:1024', 'kiwi_lvm': 'true', 'kiwi_lvmgroup': 'systemVG', 'kiwi_oemataraid_scan': None, 'kiwi_oembootwait': None, 'kiwi_oemdevicefilter': None, 'kiwi_oemkboot': None, 'kiwi_oemmultipath_scan': None, 'kiwi_oempartition_install': None, 'kiwi_oemrebootinteractive': None, 'kiwi_oemreboot': None, 'kiwi_oemrecoveryID': None, 'kiwi_oemrecoveryInPlace': None, 'kiwi_oemrecovery': False, 'kiwi_oemrecoveryPartSize': None, 'kiwi_oemrootMB': 2048, 'kiwi_oemshutdowninteractive': None, 'kiwi_oemshutdown': None, 'kiwi_oemsilentboot': None, 'kiwi_oemsilentinstall': None, 'kiwi_oemsilentverify': None, 'kiwi_oemskipverify': None, 'kiwi_oemswapMB': None, 'kiwi_oemswap': 'true', 'kiwi_oemtitle': None, 'kiwi_oemunattended_id': None, 'kiwi_oemunattended': None, 'kiwi_oemvmcp_parmfile': None, 'kiwi_profiles': '', 'kiwi_ramonly': None, 'kiwi_initrd_system': None, 'kiwi_btrfs_root_is_snapshot': None, 'kiwi_gpt_hybrid_mbr': None, 'kiwi_showlicense': None, 'kiwi_splash_theme': 'openSUSE', 'kiwi_strip_delete': '', 'kiwi_strip_libs': '', 'kiwi_strip_tools': '', 'kiwi_target_blocksize': None, 'kiwi_timezone': 'Europe/Berlin', 'kiwi_type': 'oem', 'kiwi_vga': None, 'kiwi_wwid_wait_timeout': None, 'kiwi_xendomain': None } assert result == [ "kiwi_LVM_LVRoot='freespace:500'", "kiwi_LVM_LVusr_lib='size:1024'", "kiwi_LVM_etc_volume='freespace:30:LVetc'", "kiwi_allFreeVolume_LVusr_bin='size:all'", "kiwi_allFreeVolume_bin_volume='size:all:LVusr_bin'", "kiwi_bootloader='grub2'", "kiwi_cmdline='splash'", "kiwi_displayname='LimeJeOS-openSUSE-13.2'", "kiwi_firmware='efi'", "kiwi_hwclock='utc'", "kiwi_hybrid='true'", "kiwi_iname='LimeJeOS-openSUSE-13.2'", "kiwi_iversion='1.13.2'", "kiwi_keytable='us.map.gz'", "kiwi_language='en_US'", "kiwi_loader_theme='openSUSE'", "kiwi_lvm='true'", "kiwi_lvmgroup='systemVG'", "kiwi_oemrootMB='2048'", "kiwi_oemswap='true'", "kiwi_splash_theme='openSUSE'", "kiwi_timezone='Europe/Berlin'", "kiwi_type='oem'" ] @patch('kiwi.system.profile.NamedTemporaryFile') def test_create_cpio(self, mock_temp): mock_temp.return_value = self.tmpfile description = XMLDescription('../data/example_dot_profile_config.xml') profile = Profile(XMLState(description.load(), None, 'cpio')) profile.create() os.remove(self.tmpfile.name) assert profile.dot_profile[ 'kiwi_cpio_name'] == 'LimeJeOS-openSUSE-13.2' def test_add(self): self.profile.add('foo', 'bar') assert self.profile.dot_profile['foo'] == 'bar' def test_delete(self): self.profile.add('foo', 'bar') self.profile.delete('foo') assert 'foo' not in self.profile.dot_profile
def process(self): """ Build a system image from the specified description. The build command combines the prepare and create commands """ self.manual = Help() if self._help(): return Privileges.check_for_root_permissions() abs_target_dir_path = os.path.abspath( self.command_args['--target-dir'] ) build_dir = os.sep.join([abs_target_dir_path, 'build']) image_root = os.sep.join([build_dir, 'image-root']) Path.create(build_dir) if not self.global_args['--logfile']: log.set_logfile( os.sep.join([abs_target_dir_path, 'build', 'image-root.log']) ) self.load_xml_description( self.command_args['--description'] ) self.runtime_checker.check_consistent_kernel_in_boot_and_system_image() self.runtime_checker.check_boot_image_reference_correctly_setup() self.runtime_checker.check_docker_tool_chain_installed() self.runtime_checker.check_volume_setup_has_no_root_definition() self.runtime_checker.check_image_include_repos_http_resolvable() self.runtime_checker.check_target_directory_not_in_shared_cache( abs_target_dir_path ) if self.command_args['--ignore-repos']: self.xml_state.delete_repository_sections() if self.command_args['--set-repo']: (repo_source, repo_type, repo_alias, repo_prio) = \ self.quadruple_token(self.command_args['--set-repo']) self.xml_state.set_repository( repo_source, repo_type, repo_alias, repo_prio ) if self.command_args['--add-repo']: for add_repo in self.command_args['--add-repo']: (repo_source, repo_type, repo_alias, repo_prio) = \ self.quadruple_token(add_repo) self.xml_state.add_repository( repo_source, repo_type, repo_alias, repo_prio ) Path.create(abs_target_dir_path) if self.command_args['--set-container-tag']: self.xml_state.set_container_config_tag( self.command_args['--set-container-tag'] ) if self.command_args['--set-container-derived-from']: self.xml_state.set_derived_from_image_uri( self.command_args['--set-container-derived-from'] ) self.runtime_checker.check_repositories_configured() if Defaults.is_obs_worker(): # This build runs inside of a buildservice worker. Therefore # the repo defintions is adapted accordingly self.xml_state.translate_obs_to_suse_repositories() elif self.command_args['--obs-repo-internal']: # This build should use the internal SUSE buildservice # Be aware that the buildhost has to provide access self.xml_state.translate_obs_to_ibs_repositories() package_requests = False if self.command_args['--add-package']: package_requests = True if self.command_args['--delete-package']: package_requests = True log.info('Preparing new root system') system = SystemPrepare( self.xml_state, image_root, self.command_args['--allow-existing-root'] ) manager = system.setup_repositories( self.command_args['--clear-cache'], self.command_args['--signing-key'] ) system.install_bootstrap(manager) system.install_system( manager ) if package_requests: if self.command_args['--add-package']: system.install_packages( manager, self.command_args['--add-package'] ) if self.command_args['--delete-package']: system.delete_packages( manager, self.command_args['--delete-package'] ) profile = Profile(self.xml_state) defaults = Defaults() defaults.to_profile(profile) setup = SystemSetup( self.xml_state, image_root ) setup.import_shell_environment(profile) setup.import_description() setup.import_overlay_files() setup.import_image_identifier() setup.setup_groups() setup.setup_users() setup.setup_keyboard_map() setup.setup_locale() setup.setup_timezone() system.pinch_system( manager=manager, force=True ) # make sure manager instance is cleaned up now del manager # setup permanent image repositories after cleanup if self.xml_state.has_repositories_marked_as_imageinclude(): setup.import_repositories_marked_as_imageinclude() setup.call_config_script() # make sure system instance is cleaned up now del system setup.call_image_script() # make sure setup instance is cleaned up now del setup log.info('Creating system image') image_builder = ImageBuilder( self.xml_state, abs_target_dir_path, image_root, {'signing_keys': self.command_args['--signing-key']} ) result = image_builder.create() result.print_results() result.dump( os.sep.join([abs_target_dir_path, 'kiwi.result']) )
def process(self): """ Prepare and install a new system for chroot access """ self.manual = Help() if self._help(): return Privileges.check_for_root_permissions() self.load_xml_description(self.command_args['--description'], self.global_args['--kiwi-file']) abs_root_path = os.path.abspath(self.command_args['--root']) prepare_checks = self.checks_before_command_args prepare_checks.update( {'check_target_directory_not_in_shared_cache': [abs_root_path]}) self.run_checks(prepare_checks) if self.command_args['--ignore-repos']: self.xml_state.delete_repository_sections() elif self.command_args['--ignore-repos-used-for-build']: self.xml_state.delete_repository_sections_used_for_build() if self.command_args['--set-repo']: self.xml_state.set_repository( *self.sextuple_token(self.command_args['--set-repo'])) if self.command_args['--add-repo']: for add_repo in self.command_args['--add-repo']: self.xml_state.add_repository(*self.sextuple_token(add_repo)) if self.command_args['--set-container-tag']: self.xml_state.set_container_config_tag( self.command_args['--set-container-tag']) if self.command_args['--add-container-label']: for add_label in self.command_args['--add-container-label']: try: (name, value) = add_label.split('=', 1) self.xml_state.add_container_config_label(name, value) except Exception: log.warning('Container label {0} ignored. Invalid format: ' 'expected labelname=value'.format(add_label)) if self.command_args['--set-container-derived-from']: self.xml_state.set_derived_from_image_uri( self.command_args['--set-container-derived-from']) self.run_checks(self.checks_after_command_args) log.info('Preparing system') system = SystemPrepare(self.xml_state, abs_root_path, self.command_args['--allow-existing-root']) manager = system.setup_repositories( self.command_args['--clear-cache'], self.command_args['--signing-key'] + self.xml_state.get_repositories_signing_keys(), self.global_args['--target-arch']) 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 Exception: run_bootstrap = True if run_bootstrap: system.install_bootstrap( manager, self.command_args['--add-bootstrap-package']) setup = SystemSetup(self.xml_state, abs_root_path) setup.import_description() # call post_bootstrap.sh script if present setup.call_post_bootstrap_script() system.install_system(manager) if self.command_args['--add-package']: system.install_packages(manager, self.command_args['--add-package']) if self.command_args['--delete-package']: system.delete_packages(manager, self.command_args['--delete-package']) profile = Profile(self.xml_state) defaults = Defaults() defaults.to_profile(profile) profile.create(Defaults.get_profile_file(abs_root_path)) setup.import_overlay_files() setup.import_image_identifier() setup.setup_groups() setup.setup_users() setup.setup_keyboard_map() setup.setup_locale() setup.setup_plymouth_splash() setup.setup_timezone() setup.setup_permissions() # make sure manager instance is cleaned up now del manager # setup permanent image repositories after cleanup setup.import_repositories_marked_as_imageinclude() # call config.sh script if present setup.call_config_script() # handle uninstall package requests, gracefully uninstall # with dependency cleanup system.pinch_system(force=False) # handle delete package requests, forced uninstall without # any dependency resolution system.pinch_system(force=True) # delete any custom rpm macros created system.clean_package_manager_leftovers() # make sure system instance is cleaned up now del system
def process(self): # noqa: C901 """ Prepare and install a new system for chroot access """ self.manual = Help() if self._help(): return Privileges.check_for_root_permissions() self.load_xml_description(self.command_args['--description']) abs_root_path = os.path.abspath(self.command_args['--root']) prepare_checks = self.checks_before_command_args prepare_checks.update( {'check_target_directory_not_in_shared_cache': [abs_root_path]}) self.run_checks(prepare_checks) if self.command_args['--ignore-repos']: self.xml_state.delete_repository_sections() elif self.command_args['--ignore-repos-used-for-build']: self.xml_state.delete_repository_sections_used_for_build() if self.command_args['--set-repo']: self.xml_state.set_repository( *self.sextuple_token(self.command_args['--set-repo'])) if self.command_args['--add-repo']: for add_repo in self.command_args['--add-repo']: self.xml_state.add_repository(*self.sextuple_token(add_repo)) if self.command_args['--set-container-tag']: self.xml_state.set_container_config_tag( self.command_args['--set-container-tag']) if self.command_args['--add-container-label']: for add_label in self.command_args['--add-container-label']: try: (name, value) = add_label.split('=', 1) self.xml_state.add_container_config_label(name, value) except Exception: log.warning('Container label {0} ignored. Invalid format: ' 'expected labelname=value'.format(add_label)) if self.command_args['--set-container-derived-from']: self.xml_state.set_derived_from_image_uri( self.command_args['--set-container-derived-from']) self.run_checks(self.checks_after_command_args) log.info('Preparing system') system = SystemPrepare(self.xml_state, abs_root_path, self.command_args['--allow-existing-root']) manager = system.setup_repositories(self.command_args['--clear-cache'], self.command_args['--signing-key']) system.install_bootstrap(manager, self.command_args['--add-bootstrap-package']) system.install_system(manager) if self.command_args['--add-package']: system.install_packages(manager, self.command_args['--add-package']) if self.command_args['--delete-package']: system.delete_packages(manager, self.command_args['--delete-package']) profile = Profile(self.xml_state) defaults = Defaults() defaults.to_profile(profile) setup = SystemSetup(self.xml_state, abs_root_path) setup.import_shell_environment(profile) setup.import_description() setup.import_overlay_files() setup.import_image_identifier() setup.setup_groups() setup.setup_users() setup.setup_keyboard_map() setup.setup_locale() setup.setup_plymouth_splash() setup.setup_timezone() setup.setup_permissions() # make sure manager instance is cleaned up now del manager # setup permanent image repositories after cleanup setup.import_repositories_marked_as_imageinclude() setup.call_config_script() # handle uninstall package requests, gracefully uninstall # with dependency cleanup system.pinch_system(force=False) # handle delete package requests, forced uninstall without # any dependency resolution system.pinch_system(force=True) # delete any custom rpm macros created Rpm(abs_root_path, Defaults.get_custom_rpm_image_macro_name()).wipe_config() # make sure system instance is cleaned up now del system
class TestProfile(object): def setup(self): self.tmpfile = mock.Mock() self.tmpfile.name = 'tmpfile' description = XMLDescription('../data/example_dot_profile_config.xml') self.profile = Profile( XMLState(description.load()) ) @patch('kiwi.system.profile.NamedTemporaryFile') def test_create(self, mock_temp): mock_temp.return_value = self.tmpfile result = self.profile.create() os.remove(self.tmpfile.name) print(self.profile.dot_profile) assert self.profile.dot_profile == { 'kiwi_allFreeVolume_bin_volume': 'size:all:LVusr_bin', 'kiwi_allFreeVolume_LVusr_bin': 'size:all', 'kiwi_bootkernel': None, 'kiwi_bootloader': 'grub2', 'kiwi_bootprofile': None, 'kiwi_boot_timeout': None, 'kiwi_cmdline': 'splash', 'kiwi_compressed': None, 'kiwi_delete': '', 'kiwi_devicepersistency': None, 'kiwi_displayname': 'LimeJeOS-openSUSE-13.2', 'kiwi_drivers': '', 'kiwi_firmware': 'efi', 'kiwi_fsmountoptions': None, 'kiwi_hwclock': 'utc', 'kiwi_hybrid': True, 'kiwi_hybridpersistent_filesystem': None, 'kiwi_hybridpersistent': None, 'kiwi_iname': 'LimeJeOS-openSUSE-13.2', 'kiwi_installboot': None, 'kiwi_iversion': '1.13.2', 'kiwi_keytable': 'us.map.gz', 'kiwi_language': 'en_US', 'kiwi_loader_theme': 'openSUSE', 'kiwi_LVM_etc_volume': 'freespace:30:LVetc', 'kiwi_lvmgroup': None, 'kiwi_LVM_LVRoot': 'freespace:500', 'kiwi_LVM_LVusr_lib': 'size:1024', 'kiwi_lvm': 'true', 'kiwi_lvmgroup': 'systemVG', 'kiwi_oemataraid_scan': None, 'kiwi_oembootwait': None, 'kiwi_oemdevicefilter': None, 'kiwi_oemkboot': None, 'kiwi_oemmultipath_scan': None, 'kiwi_oempartition_install': None, 'kiwi_oemrebootinteractive': None, 'kiwi_oemreboot': None, 'kiwi_oemrecoveryID': None, 'kiwi_oemrecoveryInPlace': None, 'kiwi_oemrecovery': False, 'kiwi_oemrecoveryPartSize': None, 'kiwi_oemrootMB': 2048, 'kiwi_oemshutdowninteractive': None, 'kiwi_oemshutdown': None, 'kiwi_oemsilentboot': None, 'kiwi_oemsilentinstall': None, 'kiwi_oemsilentverify': None, 'kiwi_oemskipverify': None, 'kiwi_oemswapMB': None, 'kiwi_oemswap': 'true', 'kiwi_oemtitle': None, 'kiwi_oemunattended_id': None, 'kiwi_oemunattended': None, 'kiwi_oemvmcp_parmfile': None, 'kiwi_profiles': '', 'kiwi_ramonly': None, 'kiwi_btrfs_root_is_snapshot': None, 'kiwi_gpt_hybrid_mbr': None, 'kiwi_showlicense': None, 'kiwi_splash_theme': 'openSUSE', 'kiwi_strip_delete': '', 'kiwi_strip_libs': '', 'kiwi_strip_tools': '', 'kiwi_target_blocksize': None, 'kiwi_timezone': 'Europe/Berlin', 'kiwi_type': 'oem', 'kiwi_vga': None, 'kiwi_wwid_wait_timeout': None, 'kiwi_xendomain': None } assert result == [ "kiwi_LVM_LVRoot='freespace:500'", "kiwi_LVM_LVusr_lib='size:1024'", "kiwi_LVM_etc_volume='freespace:30:LVetc'", "kiwi_allFreeVolume_LVusr_bin='size:all'", "kiwi_allFreeVolume_bin_volume='size:all:LVusr_bin'", "kiwi_bootloader='grub2'", "kiwi_cmdline='splash'", "kiwi_displayname='LimeJeOS-openSUSE-13.2'", "kiwi_firmware='efi'", "kiwi_hwclock='utc'", "kiwi_hybrid='true'", "kiwi_iname='LimeJeOS-openSUSE-13.2'", "kiwi_iversion='1.13.2'", "kiwi_keytable='us.map.gz'", "kiwi_language='en_US'", "kiwi_loader_theme='openSUSE'", "kiwi_lvm='true'", "kiwi_lvmgroup='systemVG'", "kiwi_oemrootMB='2048'", "kiwi_oemswap='true'", "kiwi_splash_theme='openSUSE'", "kiwi_timezone='Europe/Berlin'", "kiwi_type='oem'" ] @patch('kiwi.system.profile.NamedTemporaryFile') @patch('builtins.open') @patch('kiwi.system.shell.Shell.quote_key_value_file') def test_create_cpio(self, mock_shell_quote, mock_open, mock_temp): mock_temp.return_value = self.tmpfile description = XMLDescription('../data/example_dot_profile_config.xml') profile = Profile( XMLState(description.load(), None, 'cpio') ) profile.create() assert profile.dot_profile['kiwi_cpio_name'] == 'LimeJeOS-openSUSE-13.2' def test_add(self): self.profile.add('foo', 'bar') assert self.profile.dot_profile['foo'] == 'bar'
class TestProfile(object): def setup(self): self.tmpfile = mock.Mock() self.tmpfile.name = 'tmpfile' description = XMLDescription('../data/example_dot_profile_config.xml') self.profile = Profile( XMLState(description.load()) ) @patch('kiwi.system.profile.NamedTemporaryFile') @patch('kiwi.path.Path.which') def test_create(self, mock_which, mock_temp): mock_which.return_value = 'cp' mock_temp.return_value = self.tmpfile result = self.profile.create() os.remove(self.tmpfile.name) assert self.profile.dot_profile == { 'kiwi_Volume_1': 'usr_lib|size:1024|usr/lib', 'kiwi_Volume_2': 'LVRoot|freespace:500|', 'kiwi_Volume_3': 'etc_volume|freespace:30|etc', 'kiwi_Volume_4': 'bin_volume|size:all|/usr/bin', 'kiwi_Volume_5': 'usr_bin|size:all|usr/bin', 'kiwi_bootkernel': None, 'kiwi_bootloader': 'grub2', 'kiwi_bootprofile': None, 'kiwi_target_removable': None, 'kiwi_boot_timeout': None, 'kiwi_cmdline': 'splash', 'kiwi_compressed': None, 'kiwi_delete': '', 'kiwi_devicepersistency': None, 'kiwi_bootloader_console': None, 'kiwi_displayname': 'schäfer', 'kiwi_drivers': '', 'kiwi_firmware': 'efi', 'kiwi_fsmountoptions': None, 'kiwi_hybridpersistent_filesystem': None, 'kiwi_hybridpersistent': None, 'kiwi_iname': 'LimeJeOS-openSUSE-13.2', 'kiwi_installboot': None, 'kiwi_iversion': '1.13.2', 'kiwi_keytable': 'us.map.gz', 'kiwi_language': 'en_US', 'kiwi_loader_theme': 'openSUSE', 'kiwi_lvm': 'true', 'kiwi_lvmgroup': 'systemVG', 'kiwi_oemataraid_scan': None, 'kiwi_oembootwait': None, 'kiwi_oemdevicefilter': None, 'kiwi_oemnicfilter': None, 'kiwi_oemkboot': None, 'kiwi_oemmultipath_scan': None, 'kiwi_oempartition_install': None, 'kiwi_oemrebootinteractive': None, 'kiwi_oemreboot': None, 'kiwi_oemrecoveryID': None, 'kiwi_oemrecoveryInPlace': None, 'kiwi_oemrecovery': False, 'kiwi_oemrecoveryPartSize': None, 'kiwi_oemrootMB': 2048, 'kiwi_oemshutdowninteractive': None, 'kiwi_oemshutdown': None, 'kiwi_oemsilentboot': None, 'kiwi_oemsilentinstall': None, 'kiwi_oemsilentverify': None, 'kiwi_oemskipverify': None, 'kiwi_oemswapMB': None, 'kiwi_oemswap': 'true', 'kiwi_oemtitle': 'schäfer', 'kiwi_oemunattended_id': None, 'kiwi_oemunattended': None, 'kiwi_oemvmcp_parmfile': None, 'kiwi_profiles': '', 'kiwi_ramonly': True, 'kiwi_initrd_system': 'kiwi', 'kiwi_btrfs_root_is_snapshot': None, 'kiwi_gpt_hybrid_mbr': None, 'kiwi_showlicense': None, 'kiwi_splash_theme': 'openSUSE', 'kiwi_strip_delete': '', 'kiwi_strip_libs': '', 'kiwi_strip_tools': '', 'kiwi_target_blocksize': None, 'kiwi_timezone': 'Europe/Berlin', 'kiwi_type': 'oem', 'kiwi_vga': None, 'kiwi_startsector': 2048, 'kiwi_wwid_wait_timeout': None, 'kiwi_xendomain': 'dom0' } assert result == [ "kiwi_Volume_1='usr_lib|size:1024|usr/lib'", "kiwi_Volume_2='LVRoot|freespace:500|'", "kiwi_Volume_3='etc_volume|freespace:30|etc'", "kiwi_Volume_4='bin_volume|size:all|/usr/bin'", "kiwi_Volume_5='usr_bin|size:all|usr/bin'", "kiwi_bootloader='grub2'", "kiwi_cmdline='splash'", "kiwi_displayname='schäfer'", "kiwi_firmware='efi'", "kiwi_iname='LimeJeOS-openSUSE-13.2'", "kiwi_initrd_system='kiwi'", "kiwi_iversion='1.13.2'", "kiwi_keytable='us.map.gz'", "kiwi_language='en_US'", "kiwi_loader_theme='openSUSE'", "kiwi_lvm='true'", "kiwi_lvmgroup='systemVG'", "kiwi_oemrootMB='2048'", "kiwi_oemswap='true'", "kiwi_oemtitle='schäfer'", "kiwi_ramonly='true'", "kiwi_splash_theme='openSUSE'", "kiwi_startsector='2048'", "kiwi_timezone='Europe/Berlin'", "kiwi_type='oem'", "kiwi_xendomain='dom0'" ] @patch('kiwi.system.profile.NamedTemporaryFile') @patch('kiwi.path.Path.which') def test_create_displayname_is_image_name(self, mock_which, mock_temp): mock_which.return_value = 'cp' mock_temp.return_value = self.tmpfile description = XMLDescription('../data/example_pxe_config.xml') profile = Profile( XMLState(description.load()) ) profile.create() os.remove(self.tmpfile.name) assert profile.dot_profile['kiwi_displayname'] == 'LimeJeOS-openSUSE-13.2' @patch('kiwi.system.profile.NamedTemporaryFile') @patch('kiwi.path.Path.which') def test_create_cpio(self, mock_which, mock_temp): mock_which.return_value = 'cp' mock_temp.return_value = self.tmpfile description = XMLDescription('../data/example_dot_profile_config.xml') profile = Profile( XMLState(description.load(), None, 'cpio') ) profile.create() os.remove(self.tmpfile.name) assert profile.dot_profile['kiwi_cpio_name'] == 'LimeJeOS-openSUSE-13.2' def test_add(self): self.profile.add('foo', 'bar') assert self.profile.dot_profile['foo'] == 'bar' def test_delete(self): self.profile.add('foo', 'bar') self.profile.delete('foo') assert 'foo' not in self.profile.dot_profile
def process(self): # noqa: C901 """ Prepare and install a new system for chroot access """ self.manual = Help() if self._help(): return Privileges.check_for_root_permissions() self.load_xml_description(self.command_args['--description']) abs_root_path = os.path.abspath(self.command_args['--root']) self.runtime_checker.check_efi_mode_for_disk_overlay_correctly_setup() self.runtime_checker.check_grub_efi_installed_for_efi_firmware() self.runtime_checker.check_boot_description_exists() self.runtime_checker.check_consistent_kernel_in_boot_and_system_image() self.runtime_checker.check_docker_tool_chain_installed() self.runtime_checker.check_volume_setup_has_no_root_definition() self.runtime_checker.check_xen_uniquely_setup_as_server_or_guest() self.runtime_checker.check_target_directory_not_in_shared_cache( abs_root_path) self.runtime_checker.check_mediacheck_only_for_x86_arch() self.runtime_checker.check_dracut_module_for_live_iso_in_package_list() self.runtime_checker.check_dracut_module_for_disk_overlay_in_package_list( ) self.runtime_checker.check_dracut_module_for_disk_oem_in_package_list() self.runtime_checker.check_dracut_module_for_oem_install_in_package_list( ) if self.command_args['--ignore-repos']: self.xml_state.delete_repository_sections() elif self.command_args['--ignore-repos-used-for-build']: self.xml_state.delete_repository_sections_used_for_build() if self.command_args['--set-repo']: self.xml_state.set_repository( *self.sextuple_token(self.command_args['--set-repo'])) if self.command_args['--add-repo']: for add_repo in self.command_args['--add-repo']: self.xml_state.add_repository(*self.sextuple_token(add_repo)) if self.command_args['--set-container-tag']: self.xml_state.set_container_config_tag( self.command_args['--set-container-tag']) if self.command_args['--set-container-derived-from']: self.xml_state.set_derived_from_image_uri( self.command_args['--set-container-derived-from']) self.runtime_checker.check_repositories_configured() self.runtime_checker.check_image_include_repos_publicly_resolvable() log.info('Preparing system') system = SystemPrepare(self.xml_state, abs_root_path, self.command_args['--allow-existing-root']) manager = system.setup_repositories(self.command_args['--clear-cache'], self.command_args['--signing-key']) system.install_bootstrap(manager) system.install_system(manager) if self.command_args['--add-package']: system.install_packages(manager, self.command_args['--add-package']) if self.command_args['--delete-package']: system.delete_packages(manager, self.command_args['--delete-package']) profile = Profile(self.xml_state) defaults = Defaults() defaults.to_profile(profile) setup = SystemSetup(self.xml_state, abs_root_path) setup.import_shell_environment(profile) setup.import_description() setup.import_overlay_files() setup.import_image_identifier() setup.setup_groups() setup.setup_users() setup.setup_keyboard_map() setup.setup_locale() setup.setup_plymouth_splash() setup.setup_timezone() # make sure manager instance is cleaned up now del manager # setup permanent image repositories after cleanup setup.import_repositories_marked_as_imageinclude() setup.call_config_script() # handle uninstall package requests, gracefully uninstall # with dependency cleanup system.pinch_system(force=False) # handle delete package requests, forced uninstall without # any dependency resolution system.pinch_system(force=True) # make sure system instance is cleaned up now del system
def process(self): # noqa: C901 """ Build a system image from the specified description. The build command combines the prepare and create commands """ self.manual = Help() if self._help(): return Privileges.check_for_root_permissions() abs_target_dir_path = os.path.abspath( self.command_args['--target-dir'] ) build_dir = os.sep.join([abs_target_dir_path, 'build']) image_root = os.sep.join([build_dir, 'image-root']) Path.create(build_dir) if not self.global_args['--logfile']: log.set_logfile( os.sep.join([abs_target_dir_path, 'build', 'image-root.log']) ) self.load_xml_description( self.command_args['--description'] ) self.runtime_checker.check_minimal_required_preferences() self.runtime_checker.check_efi_mode_for_disk_overlay_correctly_setup() self.runtime_checker.check_boot_description_exists() self.runtime_checker.check_consistent_kernel_in_boot_and_system_image() self.runtime_checker.check_docker_tool_chain_installed() self.runtime_checker.check_volume_setup_defines_multiple_fullsize_volumes() self.runtime_checker.check_volume_setup_has_no_root_definition() self.runtime_checker.check_volume_label_used_with_lvm() self.runtime_checker.check_xen_uniquely_setup_as_server_or_guest() self.runtime_checker.check_target_directory_not_in_shared_cache( abs_target_dir_path ) self.runtime_checker.check_mediacheck_only_for_x86_arch() self.runtime_checker.check_dracut_module_for_live_iso_in_package_list() self.runtime_checker.check_dracut_module_for_disk_overlay_in_package_list() self.runtime_checker.check_dracut_module_for_disk_oem_in_package_list() self.runtime_checker.check_dracut_module_for_oem_install_in_package_list() if self.command_args['--ignore-repos']: self.xml_state.delete_repository_sections() elif self.command_args['--ignore-repos-used-for-build']: self.xml_state.delete_repository_sections_used_for_build() if self.command_args['--set-repo']: self.xml_state.set_repository( *self.sextuple_token(self.command_args['--set-repo']) ) if self.command_args['--add-repo']: for add_repo in self.command_args['--add-repo']: self.xml_state.add_repository( *self.sextuple_token(add_repo) ) if self.command_args['--set-container-tag']: self.xml_state.set_container_config_tag( self.command_args['--set-container-tag'] ) if self.command_args['--add-container-label']: for add_label in self.command_args['--add-container-label']: try: (name, value) = add_label.split('=', 1) self.xml_state.add_container_config_label(name, value) except Exception: log.warning( 'Container label {0} ignored. Invalid format: ' 'expected labelname=value'.format(add_label) ) if self.command_args['--set-container-derived-from']: self.xml_state.set_derived_from_image_uri( self.command_args['--set-container-derived-from'] ) self.runtime_checker.check_repositories_configured() self.runtime_checker.check_image_include_repos_publicly_resolvable() log.info('Preparing new root system') system = SystemPrepare( self.xml_state, image_root, self.command_args['--allow-existing-root'] ) manager = system.setup_repositories( self.command_args['--clear-cache'], self.command_args['--signing-key'] ) system.install_bootstrap(manager) system.install_system( manager ) if self.command_args['--add-package']: system.install_packages( manager, self.command_args['--add-package'] ) if self.command_args['--delete-package']: system.delete_packages( manager, self.command_args['--delete-package'] ) profile = Profile(self.xml_state) defaults = Defaults() defaults.to_profile(profile) setup = SystemSetup( self.xml_state, image_root ) setup.import_shell_environment(profile) setup.import_description() setup.import_overlay_files() setup.import_image_identifier() setup.setup_groups() setup.setup_users() setup.setup_keyboard_map() setup.setup_locale() setup.setup_plymouth_splash() setup.setup_timezone() setup.setup_permissions() # make sure manager instance is cleaned up now del manager # setup permanent image repositories after cleanup setup.import_repositories_marked_as_imageinclude() setup.call_config_script() # handle uninstall package requests, gracefully uninstall # with dependency cleanup system.pinch_system(force=False) # handle delete package requests, forced uninstall without # any dependency resolution system.pinch_system(force=True) # delete any custom rpm macros created Rpm( image_root, Defaults.get_custom_rpm_image_macro_name() ).wipe_config() # make sure system instance is cleaned up now del system setup.call_image_script() # make sure setup instance is cleaned up now del setup log.info('Creating system image') image_builder = ImageBuilder( self.xml_state, abs_target_dir_path, image_root, custom_args={ 'signing_keys': self.command_args['--signing-key'], 'xz_options': self.runtime_config.get_xz_options() } ) result = image_builder.create() result.print_results() result.dump( os.sep.join([abs_target_dir_path, 'kiwi.result']) )