def __init__(self, *args, **kwargs): NormalSpoke.__init__(self, *args, **kwargs) LangLocaleHandler.__init__(self) self._selected_locales = set() self._l12_module = LOCALIZATION.get_observer() self._l12_module.connect()
def __init__(self, *args, **kwargs): StandaloneSpoke.__init__(self, *args, **kwargs) LangLocaleHandler.__init__(self, self.payload, self.instclass) self._origStrings = {} self._l12_module = LOCALIZATION.get_observer() self._l12_module.connect()
def __init__(self, *args, **kwargs): NormalSpoke.__init__(self, *args, **kwargs) LangLocaleHandler.__init__(self, self.payload) self._selected_locales = set() self._l12_module = LOCALIZATION.get_observer() self._l12_module.connect()
def __init__(self, *args, **kwargs): StandaloneSpoke.__init__(self, *args, **kwargs) LangLocaleHandler.__init__(self, self.payload) self._origStrings = {} self._l12_module = LOCALIZATION.get_observer() self._l12_module.connect()
def collect_language_requirements_test(self, proxy_getter): """Test the function collect_language_requirements.""" proxy = LOCALIZATION.get_proxy() proxy.Language = "cs_CZ.UTF-8" proxy.LanguageSupport = ["en_GB.UTF-8", "sr_RS@cyrilic"] p1 = self._create_package("langpacks-cs") p2 = self._create_package("langpacks-core-cs") p3 = self._create_package("langpacks-core-font-cs") p4 = self._create_package("langpacks-en") p5 = self._create_package("langpacks-en_GB") p6 = self._create_package("langpacks-core-en") p7 = self._create_package("langpacks-core-en_GB") p8 = self._create_package("langpacks-core-font-en") base = Mock() base.sack.query.return_value.available.return_value.filter.return_value = [ p1, p2, p3, p4, p5, p6, p7, p8 ] with self.assertLogs(level="WARNING") as cm: requirements = collect_language_requirements(base) r1 = self._create_requirement( "langpacks-cs", "Required to support the locale 'cs_CZ.UTF-8'.") r2 = self._create_requirement( "langpacks-en_GB", "Required to support the locale 'en_GB.UTF-8'.") self._compare_requirements(requirements, [r1, r2]) msg = "Selected locale 'sr_RS@cyrilic' does not match any available langpacks." self.assertTrue(any(map(lambda x: msg in x, cm.output)))
def test_collect_language_requirements(self, proxy_getter): """Test the function collect_language_requirements.""" boss = BOSS.get_proxy() boss.GetModules.return_value = [LOCALIZATION.service_name] proxy = LOCALIZATION.get_proxy() proxy.Language = "cs_CZ.UTF-8" proxy.LanguageSupport = ["en_GB.UTF-8", "sr_RS@cyrilic"] dnf_manager = Mock(spec=DNFManager) dnf_manager.match_available_packages.return_value = [ "langpacks-cs", "langpacks-core-cs", "langpacks-core-font-cs", "langpacks-en", "langpacks-en_GB", "langpacks-core-en", "langpacks-core-en_GB", "langpacks-core-font-en" ] with self.assertLogs(level="WARNING") as cm: requirements = collect_language_requirements(dnf_manager) r1 = self._create_requirement( "langpacks-cs", "Required to support the locale 'cs_CZ.UTF-8'.") r2 = self._create_requirement( "langpacks-en_GB", "Required to support the locale 'en_GB.UTF-8'.") self._compare_requirements(requirements, [r1, r2]) msg = "Selected locale 'sr_RS@cyrilic' does not match any available langpacks." assert any(map(lambda x: msg in x, cm.output))
def initialize_locale(opts, text_mode): """Initialize locale. :param opts: the command line/boot options :param text_mode: is the locale being set up for the text mode? """ from pyanaconda import localization locale_option = None localization_proxy = None if is_module_available(LOCALIZATION): localization_proxy = LOCALIZATION.get_proxy() # If the language was set on the command line, copy that to kickstart if opts.lang: localization_proxy.SetLanguage(opts.lang) localization_proxy.SetLanguageKickstarted(True) # Setup the locale environment if localization_proxy.LanguageKickstarted: locale_option = localization_proxy.Language localization.setup_locale_environment(locale_option, text_mode=text_mode) # Now that LANG is set, do something with it localization.setup_locale(os.environ["LANG"], localization_proxy, text_mode=text_mode)
def collect_language_requirements(dnf_base): """Collect requirements for supported languages. :param dnf_base: a DNF base :return: a list of requirements """ requirements = [] localization_proxy = LOCALIZATION.get_proxy() locales = [localization_proxy.Language] + localization_proxy.LanguageSupport # Find all available langpacks. packages = dnf_base.sack.query().available().filter(name__glob="langpacks-*") # Get all valid langcodes. codes = [p.name.split('-', 1)[1] for p in packages] codes = list(filter(is_valid_langcode, codes)) # Find the best langpacks to install. for locale in locales: best_locale = find_best_locale_match(locale, codes) if not best_locale: log.warning("Selected locale '%s' does not match " "any available langpacks.", locale) continue requirements.append(Requirement.for_package( package_name="langpacks-" + best_locale, reason="Required to support the locale '{}'.".format(locale) )) return requirements
def __init__(self, *args, **kwargs): StandaloneSpoke.__init__(self, *args, **kwargs) LangLocaleHandler.__init__(self) self._origStrings = {} self._l12_module = LOCALIZATION.get_proxy() self._only_existing_locales = True
def activate_keyboard(localization_proxy): """ Try to setup VConsole keymap and X11 layouts as specified in kickstart. :param localization_proxy: DBus proxy of the localization module or None """ task_path = localization_proxy.ApplyKeyboardWithTask() task_proxy = LOCALIZATION.get_proxy(task_path) sync_run_task(task_proxy)
def __init__(self, *args, **kwargs): StandaloneSpoke.__init__(self, *args, **kwargs) LangLocaleHandler.__init__(self) self._origStrings = {} self._l12_module = LOCALIZATION.get_proxy() self._tz_module = None if is_module_available(TIMEZONE): self._tz_module = TIMEZONE.get_proxy() self._only_existing_locales = True
def populate_missing_items(localization_proxy=None): """ Function that populates virtual console keymap and X layouts if they are missing. By invoking systemd-localed methods this function READS AND WRITES CONFIGURATION FILES (but tries to keep their content unchanged). :param localization_proxy: DBus proxy of the localization module or None """ task_path = localization_proxy.PopulateMissingKeyboardConfigurationWithTask() task_proxy = LOCALIZATION.get_proxy(task_path) sync_run_task(task_proxy)
def _setup_locale(self): log.debug("setting up locale") localization_proxy = LOCALIZATION.get_proxy() # Normalize the locale environment variables if localization_proxy.Kickstarted: locale_arg = localization_proxy.Language else: locale_arg = None setup_locale_environment(locale_arg, prefer_environment=True) setup_locale(os.environ['LANG'], text_mode=not self.gui_mode)
def languageGroups(self): localization_proxy = LOCALIZATION.get_proxy() locales = [localization_proxy.Language ] + localization_proxy.LanguageSupport match_fn = pyanaconda.localization.langcode_matches_locale gids = set() gl_tuples = ((g.id, g.lang_only) for g in self._base.comps.groups_iter()) for (gid, lang) in gl_tuples: for locale in locales: if match_fn(lang, locale): gids.add(gid) return list(gids)
def __init__(self, *args): super().__init__(*args) self._remove_last_attempt = False self._confirmed = False self._xkl_wrapper = XklWrapper.get_instance() self._add_dialog = None self._ready = False self._upButton = self.builder.get_object("upButton") self._downButton = self.builder.get_object("downButton") self._removeButton = self.builder.get_object("removeLayoutButton") self._previewButton = self.builder.get_object("previewButton") self._l12_module = LOCALIZATION.get_proxy() self._seen = self._l12_module.KeyboardKickstarted
def __init__(self, *args): super().__init__(*args) self._remove_last_attempt = False self._confirmed = False self._xkl_wrapper = XklWrapper.get_instance() self._add_dialog = None self._ready = False self._upButton = self.builder.get_object("upButton") self._downButton = self.builder.get_object("downButton") self._removeButton = self.builder.get_object("removeLayoutButton") self._previewButton = self.builder.get_object("previewButton") self._l12_module = LOCALIZATION.get_observer() self._l12_module.connect() self._seen = self._l12_module.proxy.KeyboardKickstarted
def __init__(self, data, storage, payload, instclass): NormalTUISpoke.__init__(self, data, storage, payload, instclass) self.title = N_("Language settings") self.initialize_start() self._container = None self._langs = [localization.get_english_name(lang) for lang in localization.get_available_translations()] self._langs_and_locales = dict((localization.get_english_name(lang), lang) for lang in localization.get_available_translations()) self._locales = dict((lang, localization.get_language_locales(lang)) for lang in self._langs_and_locales.values()) self._l12_module = LOCALIZATION.get_observer() self._l12_module.connect() self._selected = self._l12_module.proxy.Language self.initialize_done()
def reinitialize_locale(opts, text_mode): """Reinitialize locale. We need to reinitialize the locale if GUI startup failed. The text mode might not be able to display the characters from our current locale. :param opts: the command line/boot options :param text_mode: is the locale being set up for the text mode? """ from pyanaconda import localization localization_proxy = None if is_module_available(LOCALIZATION): localization_proxy = LOCALIZATION.get_proxy() log.warning("reinitializing locale due to failed attempt to start the GUI") localization.setup_locale(os.environ["LANG"], localization_proxy, text_mode=text_mode)
def langpacks(self): # get all available languages in repos available_langpacks = self._base.sack.query().available() \ .filter(name__glob="langpacks-*") alangs = [p.name.split('-', 1)[1] for p in available_langpacks] langpacks = [] # add base langpacks into transaction localization_proxy = LOCALIZATION.get_proxy() for lang in [localization_proxy.Language ] + localization_proxy.LanguageSupport: loc = pyanaconda.localization.find_best_locale_match(lang, alangs) if not loc: log.warning( "Selected lang %s does not match any available langpack", lang) continue langpacks.append("langpacks-" + loc) return langpacks
def activate_keyboard(opts): """Activate keyboard. Set up keyboard layout from the command line option and let it override from kickstart if/when X is initialized. :param opts: the command line/boot options """ if not is_module_available(LOCALIZATION): return from pyanaconda import keyboard localization_proxy = LOCALIZATION.get_proxy() if opts.keymap and not localization_proxy.KeyboardKickstarted: localization_proxy.SetKeyboard(opts.keymap) localization_proxy.SetKeyboardKickstarted(True) if localization_proxy.KeyboardKickstarted: if conf.system.can_activate_keyboard: keyboard.activate_keyboard(localization_proxy) else: # at least make sure we have all the values keyboard.populate_missing_items(localization_proxy)
def __init__(self, *args, **kwargs): NormalSpoke.__init__(self, *args, **kwargs) LangLocaleHandler.__init__(self, self.payload) self._selected_locales = set() self._l12_module = LOCALIZATION.get_proxy()
def execute(self): localization_proxy = LOCALIZATION.get_proxy() keyboard.write_keyboard_config(localization_proxy, util.getSysroot())
# reboot with kexec if ksdata.reboot.kexec: flags.kexec = True # Some kickstart commands must be executed immediately, as they affect # how anaconda operates. ksdata.logging.execute() anaconda.ksdata = ksdata # setup keyboard layout from the command line option and let # it override from kickstart if/when X is initialized from pyanaconda.modules.common.constants.services import LOCALIZATION localization_proxy = LOCALIZATION.get_proxy() configured = any((localization_proxy.Keyboard, localization_proxy.VirtualConsoleKeymap, localization_proxy.XLayouts)) if opts.keymap and not configured: localization_proxy.SetKeyboard(opts.keymap) configured = True if configured: if conf.system.can_activate_keyboard: keyboard.activate_keyboard(localization_proxy) else: # at least make sure we have all the values keyboard.populate_missing_items(localization_proxy)
def _prepare_installation(self, payload, ksdata): """Perform an installation. This method takes the ksdata as prepared by the UI (the first hub, in graphical mode) and applies it to the disk. The two main tasks for this are putting filesystems onto disks and installing packages onto those filesystems. """ installation_queue = TaskQueue("Installation queue") # connect progress reporting installation_queue.queue_started.connect( lambda x: progress_message(x.status_message)) installation_queue.task_completed.connect( lambda x: progress_step(x.name)) # setup the installation environment setup_environment = TaskQueue( "Installation environment setup", _("Setting up the installation environment")) boss_proxy = BOSS.get_proxy() for service_name, object_path in boss_proxy.CollectConfigureRuntimeTasks( ): task_proxy = DBus.get_proxy(service_name, object_path) setup_environment.append(DBusTask(task_proxy)) # Add configuration tasks for the Localization DBus module. if is_module_available(LOCALIZATION): localization_proxy = LOCALIZATION.get_proxy() # Populate the missing keyboard values before the payload installation, # so the module requirements can be generated for the right configuration. # FIXME: Make sure that the module always returns right values. populate_task = localization_proxy.PopulateMissingKeyboardConfigurationWithTask( ) setup_environment.append_dbus_tasks(LOCALIZATION, [populate_task]) installation_queue.append(setup_environment) # Do partitioning. # Depending on current payload the storage might be apparently configured # either before or after package/payload installation. # So let's have two task queues - early storage & late storage. storage_proxy = STORAGE.get_proxy() early_storage = TaskQueue("Early storage configuration", _("Configuring storage")) early_storage.append_dbus_tasks(STORAGE, storage_proxy.InstallWithTasks()) if payload.type == PAYLOAD_TYPE_DNF: conf_task = storage_proxy.WriteConfigurationWithTask() early_storage.append_dbus_tasks(STORAGE, [conf_task]) installation_queue.append(early_storage) # Run %pre-install scripts with the filesystem mounted and no packages pre_install_scripts = TaskQueue("Pre-install scripts", _("Running pre-installation scripts")) pre_install_scripts.append( Task("Run %pre-install scripts", runPreInstallScripts, (ksdata.scripts, ))) installation_queue.append(pre_install_scripts) # Do various pre-installation tasks # - try to discover a realm (if any) # - check for possibly needed additional packages. pre_install = TaskQueue("Pre install tasks", _("Running pre-installation tasks")) if is_module_available(SECURITY): security_proxy = SECURITY.get_proxy() # Discover a realm. pre_install.append_dbus_tasks( SECURITY, [security_proxy.DiscoverRealmWithTask()]) # Set up FIPS for the payload installation. fips_task = security_proxy.PreconfigureFIPSWithTask(payload.type) pre_install.append_dbus_tasks(SECURITY, [fips_task]) # Install the payload. pre_install.append( Task("Find additional packages & run pre_install()", payload.pre_install)) installation_queue.append(pre_install) payload_install = TaskQueue("Payload installation", _("Installing.")) payload_install.append(Task("Install the payload", payload.install)) installation_queue.append(payload_install) # for some payloads storage is configured after the payload is installed if payload.type != PAYLOAD_TYPE_DNF: late_storage = TaskQueue("Late storage configuration", _("Configuring storage")) conf_task = storage_proxy.WriteConfigurationWithTask() late_storage.append_dbus_tasks(STORAGE, [conf_task]) installation_queue.append(late_storage) # Do bootloader. bootloader_proxy = STORAGE.get_proxy(BOOTLOADER) bootloader_install = TaskQueue("Bootloader installation", _("Installing boot loader")) def run_configure_bootloader(): tasks = boss_proxy.CollectConfigureBootloaderTasks( payload.kernel_version_list) for service, task in tasks: sync_run_task(DBus.get_proxy(service, task)) bootloader_install.append( Task("Configure bootloader", run_configure_bootloader)) def run_install_bootloader(): tasks = bootloader_proxy.InstallBootloaderWithTasks( payload.type, payload.kernel_version_list) for task in tasks: sync_run_task(STORAGE.get_proxy(task)) bootloader_install.append( Task("Install bootloader", run_install_bootloader)) installation_queue.append(bootloader_install) post_install = TaskQueue("Post-installation setup tasks", _("Performing post-installation setup tasks")) post_install.append( Task("Run post-installation setup tasks", payload.post_install)) installation_queue.append(post_install) # Create snapshot snapshot_proxy = STORAGE.get_proxy(SNAPSHOT) if snapshot_proxy.IsRequested(SNAPSHOT_WHEN_POST_INSTALL): snapshot_creation = TaskQueue( "Creating post installation snapshots", _("Creating snapshots")) snapshot_task = snapshot_proxy.CreateWithTask( SNAPSHOT_WHEN_POST_INSTALL) snapshot_creation.append_dbus_tasks(STORAGE, [snapshot_task]) installation_queue.append(snapshot_creation) return installation_queue
def _prepare_configuration(payload, ksdata): """Configure the installed system.""" configuration_queue = TaskQueue("Configuration queue") # connect progress reporting configuration_queue.queue_started.connect( lambda x: progress_message(x.status_message)) configuration_queue.task_completed.connect(lambda x: progress_step(x.name)) # add installation tasks for the Subscription DBus module if is_module_available(SUBSCRIPTION): # we only run the tasks if the Subscription module is available subscription_config = TaskQueue("Subscription configuration", N_("Configuring Red Hat subscription")) subscription_proxy = SUBSCRIPTION.get_proxy() subscription_dbus_tasks = subscription_proxy.InstallWithTasks() subscription_config.append_dbus_tasks(SUBSCRIPTION, subscription_dbus_tasks) configuration_queue.append(subscription_config) # schedule the execute methods of ksdata that require an installed system to be present os_config = TaskQueue("Installed system configuration", N_("Configuring installed system")) # add installation tasks for the Security DBus module security_proxy = SECURITY.get_proxy() security_dbus_tasks = security_proxy.InstallWithTasks() os_config.append_dbus_tasks(SECURITY, security_dbus_tasks) # add installation tasks for the Timezone DBus module # run these tasks before tasks of the Services module if is_module_available(TIMEZONE): timezone_proxy = TIMEZONE.get_proxy() timezone_dbus_tasks = timezone_proxy.InstallWithTasks() os_config.append_dbus_tasks(TIMEZONE, timezone_dbus_tasks) # add installation tasks for the Services DBus module services_proxy = SERVICES.get_proxy() services_dbus_tasks = services_proxy.InstallWithTasks() os_config.append_dbus_tasks(SERVICES, services_dbus_tasks) # add installation tasks for the Localization DBus module if is_module_available(LOCALIZATION): localization_proxy = LOCALIZATION.get_proxy() localization_dbus_tasks = localization_proxy.InstallWithTasks() os_config.append_dbus_tasks(LOCALIZATION, localization_dbus_tasks) # add the Firewall configuration task if conf.target.can_configure_network: firewall_proxy = NETWORK.get_proxy(FIREWALL) firewall_dbus_task = firewall_proxy.InstallWithTask() os_config.append_dbus_tasks(NETWORK, [firewall_dbus_task]) configuration_queue.append(os_config) # schedule network configuration (if required) if conf.target.can_configure_network and conf.system.provides_network_config: overwrite = payload.type in PAYLOAD_LIVE_TYPES network_config = TaskQueue("Network configuration", N_("Writing network configuration")) network_config.append( Task("Network configuration", network.write_configuration, (overwrite, ))) configuration_queue.append(network_config) # add installation tasks for the Users DBus module if is_module_available(USERS): user_config = TaskQueue("User creation", N_("Creating users")) users_proxy = USERS.get_proxy() users_dbus_tasks = users_proxy.InstallWithTasks() user_config.append_dbus_tasks(USERS, users_dbus_tasks) configuration_queue.append(user_config) # Anaconda addon configuration addon_config = TaskQueue("Anaconda addon configuration", N_("Configuring addons")) # there is no longer a User class & addons should no longer need it # FIXME: drop user class parameter from the API & all known addons addon_config.append( Task("Configure Anaconda addons", ksdata.addons.execute, (None, ksdata, None, payload))) boss_proxy = BOSS.get_proxy() addon_config.append_dbus_tasks(BOSS, [boss_proxy.InstallSystemWithTask()]) configuration_queue.append(addon_config) # Initramfs generation generate_initramfs = TaskQueue("Initramfs generation", N_("Generating initramfs")) bootloader_proxy = STORAGE.get_proxy(BOOTLOADER) def run_generate_initramfs(): tasks = bootloader_proxy.GenerateInitramfsWithTasks( payload.type, payload.kernel_version_list) for task in tasks: sync_run_task(STORAGE.get_proxy(task)) generate_initramfs.append( Task("Generate initramfs", run_generate_initramfs)) configuration_queue.append(generate_initramfs) # Configure FIPS. configuration_queue.append_dbus_tasks( SECURITY, [security_proxy.ConfigureFIPSWithTask()]) # realm join # - this can run only after network is configured in the target system chroot configuration_queue.append_dbus_tasks(SECURITY, [security_proxy.JoinRealmWithTask()]) post_scripts = TaskQueue("Post installation scripts", N_("Running post-installation scripts")) post_scripts.append( Task("Run post installation scripts", runPostScripts, (ksdata.scripts, ))) configuration_queue.append(post_scripts) # setup kexec reboot if requested if flags.flags.kexec: kexec_setup = TaskQueue("Kexec setup", N_("Setting up kexec")) kexec_setup.append(Task("Setup kexec", setup_kexec)) configuration_queue.append(kexec_setup) # write anaconda related configs & kickstarts write_configs = TaskQueue("Write configs and kickstarts", N_("Storing configuration files and kickstarts")) # Write the kickstart file to the installed system (or, copy the input # kickstart file over if one exists). if flags.flags.nosave_output_ks: # don't write the kickstart file to the installed system if this has # been disabled by the nosave option log.warning( "Writing of the output kickstart to installed system has been disabled" " by the nosave option.") else: # write anaconda related configs & kickstarts write_configs.append(Task("Store kickstarts", _writeKS, (ksdata, ))) # only add write_configs to the main queue if we actually store some kickstarts/configs if write_configs.task_count: configuration_queue.append(write_configs) return configuration_queue
def __str__(self): localization_proxy = LOCALIZATION.get_proxy() return localization_proxy.GenerateKickstart()
def _apply(self): # Do not execute sections that were part of the original # anaconda kickstart file (== have .seen flag set) log.info("applying changes") sections = [self.data.keyboard, self.data.lang, self.data.timezone] # data.selinux # data.firewall localization_proxy = LOCALIZATION.get_proxy() self.data.keyboard.seen = localization_proxy.KeyboardKickstarted self.data.lang.seen = localization_proxy.LanguageKickstarted timezone_proxy = TIMEZONE.get_proxy() self.data.timezone.seen = timezone_proxy.Kickstarted log.info("executing kickstart") for section in sections: section_msg = "%s on line %d" % (repr(section), section.lineno) if section.seen: log.debug("skipping %s", section_msg) continue log.debug("executing %s", section_msg) section.execute(None, self.data, None) # Prepare the user database tools u = Users() sections = [self.data.group, self.data.user, self.data.rootpw] user_proxy = USER.get_proxy() self.data.rootpw.seen = user_proxy.IsRootpwKickstarted for section in sections: section_msg = "%s on line %d" % (repr(section), section.lineno) if section.seen: log.debug("skipping %s", section_msg) continue log.debug("executing %s", section_msg) section.execute(None, self.data, None, u) # Configure all addons log.info("executing addons") self.data.addons.execute(None, self.data, None, u, None) if self.external_reconfig: # prevent the reconfig flag from being written out # to kickstart if neither /etc/reconfigSys or /.unconfigured # are present services_proxy = SERVICES.get_proxy() services_proxy.SetSetupOnBoot(SETUP_ON_BOOT_DEFAULT) # Write the kickstart data to file log.info("writing the Initial Setup kickstart file %s", OUTPUT_KICKSTART_PATH) with open(OUTPUT_KICKSTART_PATH, "w") as f: f.write(str(self.data)) log.info("finished writing the Initial Setup kickstart file") # Remove the reconfig files, if any - otherwise the reconfig mode # would start again next time the Initial Setup service is enabled. if self.external_reconfig: for reconfig_file in RECONFIG_FILES: if os.path.exists(reconfig_file): log.debug("removing reconfig trigger file: %s" % reconfig_file) os.remove(reconfig_file) # and we are done with applying changes log.info("all changes have been applied")
def doConfiguration(storage, payload, ksdata): """Configure the installed system.""" configuration_queue = TaskQueue("Configuration queue") # connect progress reporting configuration_queue.queue_started.connect( lambda x: progress_message(x.status_message)) configuration_queue.task_completed.connect(lambda x: progress_step(x.name)) # schedule the execute methods of ksdata that require an installed system to be present os_config = TaskQueue("Installed system configuration", N_("Configuring installed system")) os_config.append(Task("Configure authselect", ksdata.authselect.execute)) security_proxy = SECURITY.get_proxy() security_dbus_tasks = security_proxy.InstallWithTasks(util.getSysroot()) # add one Task instance per DBUS task for dbus_task in security_dbus_tasks: task_proxy = SECURITY.get_proxy(dbus_task) os_config.append(Task(task_proxy.Name, sync_run_task, (task_proxy, ))) services_proxy = SERVICES.get_proxy() services_dbus_tasks = services_proxy.InstallWithTasks(util.getSysroot()) # add one Task instance per DBUS task for dbus_task in services_dbus_tasks: task_proxy = SERVICES.get_proxy(dbus_task) os_config.append(Task(task_proxy.Name, sync_run_task, (task_proxy, ))) os_config.append(Task("Configure keyboard", ksdata.keyboard.execute)) os_config.append(Task("Configure timezone", ksdata.timezone.execute)) localization_proxy = LOCALIZATION.get_proxy() localization_dbus_tasks = localization_proxy.InstallWithTasks( util.getSysroot()) # add one Task instance per DBUS task for dbus_task in localization_dbus_tasks: task_proxy = LOCALIZATION.get_proxy(dbus_task) os_config.append(Task(task_proxy.Name, sync_run_task, (task_proxy, ))) firewall_proxy = NETWORK.get_proxy(FIREWALL) firewall_dbus_task = firewall_proxy.InstallWithTask(util.getSysroot()) task_proxy = NETWORK.get_proxy(firewall_dbus_task) os_config.append(Task(task_proxy.Name, sync_run_task, (task_proxy, ))) configuration_queue.append(os_config) # schedule network configuration (if required) if conf.system.provides_network_config: network_config = TaskQueue("Network configuration", N_("Writing network configuration")) network_config.append( Task("Network configuration", ksdata.network.execute, (payload, ))) configuration_queue.append(network_config) # creating users and groups requires some pre-configuration. user_config = TaskQueue("User creation", N_("Creating users")) users_proxy = USERS.get_proxy() users_dbus_tasks = users_proxy.InstallWithTasks(util.getSysroot()) # add one Task instance per DBUS task for dbus_task in users_dbus_tasks: task_proxy = USERS.get_proxy(dbus_task) user_config.append(Task(task_proxy.Name, sync_run_task, (task_proxy, ))) configuration_queue.append(user_config) # Anaconda addon configuration addon_config = TaskQueue("Anaconda addon configuration", N_("Configuring addons")) # there is no longer a User class & addons should no longer need it # FIXME: drop user class parameter from the API & all known addons addon_config.append( Task("Configure Anaconda addons", ksdata.addons.execute, (storage, ksdata, None, payload))) configuration_queue.append(addon_config) # Initramfs generation generate_initramfs = TaskQueue("Initramfs generation", N_("Generating initramfs")) generate_initramfs.append( Task("Generate initramfs", payload.recreate_initrds)) # This works around 2 problems, /boot on BTRFS and BTRFS installations where the initrd is # recreated after the first writeBootLoader call. This reruns it after the new initrd has # been created, fixing the kernel root and subvol args and adding the missing initrd entry. boot_on_btrfs = isinstance(storage.mountpoints.get("/"), BTRFSDevice) bootloader_proxy = STORAGE.get_proxy(BOOTLOADER) bootloader_enabled = bootloader_proxy.BootloaderMode != BOOTLOADER_DISABLED if isinstance(payload, LiveImagePayload) and boot_on_btrfs and bootloader_enabled: generate_initramfs.append( Task("Write BTRFS bootloader fix", write_boot_loader, (storage, payload))) # Invoking zipl should be the last thing done on a s390x installation (see #1652727). if arch.is_s390() and not conf.target.is_directory and bootloader_enabled: generate_initramfs.append( Task("Rerun zipl", lambda: util.execInSysroot("zipl", []))) configuration_queue.append(generate_initramfs) # join a realm (if required) if ksdata.realm.discovered: join_realm = TaskQueue( "Realm join", N_("Joining realm: %s") % ksdata.realm.discovered) join_realm.append(Task("Join a realm", ksdata.realm.execute)) configuration_queue.append(join_realm) post_scripts = TaskQueue("Post installation scripts", N_("Running post-installation scripts")) post_scripts.append( Task("Run post installation scripts", runPostScripts, (ksdata.scripts, ))) configuration_queue.append(post_scripts) # setup kexec reboot if requested if flags.flags.kexec: kexec_setup = TaskQueue("Kexec setup", N_("Setting up kexec")) kexec_setup.append(Task("Setup kexec", setup_kexec)) configuration_queue.append(kexec_setup) # write anaconda related configs & kickstarts write_configs = TaskQueue("Write configs and kickstarts", N_("Storing configuration files and kickstarts")) # Write the kickstart file to the installed system (or, copy the input # kickstart file over if one exists). if flags.flags.nosave_output_ks: # don't write the kickstart file to the installed system if this has # been disabled by the nosave option log.warning( "Writing of the output kickstart to installed system has been disabled" " by the nosave option.") else: # write anaconda related configs & kickstarts write_configs.append(Task("Store kickstarts", _writeKS, (ksdata, ))) # only add write_configs to the main queue if we actually store some kickstarts/configs if write_configs.task_count: configuration_queue.append(write_configs) # notify progress tracking about the number of steps progress_init(configuration_queue.task_count) # log contents of the main task queue log.info(configuration_queue.summary) # log tasks and queues when they are started # - note that we are using generators to add the counter queue_counter = util.item_counter(configuration_queue.queue_count) task_started_counter = util.item_counter(configuration_queue.task_count) task_completed_counter = util.item_counter(configuration_queue.task_count) configuration_queue.queue_started.connect(lambda x: log.info( "Queue started: %s (%s)", x.name, next(queue_counter))) configuration_queue.task_started.connect(lambda x: log.info( "Task started: %s (%s)", x.name, next(task_started_counter))) configuration_queue.task_completed.connect( lambda x: log.debug("Task completed: %s (%s) (%1.1f s)", x.name, next(task_completed_counter), x.elapsed_time)) # start the task queue configuration_queue.start() # done progress_complete()
def _prepare_installation(payload, ksdata): """Perform an installation. This method takes the ksdata as prepared by the UI (the first hub, in graphical mode) and applies it to the disk. The two main tasks for this are putting filesystems onto disks and installing packages onto those filesystems. """ installation_queue = TaskQueue("Installation queue") # connect progress reporting installation_queue.queue_started.connect( lambda x: progress_message(x.status_message)) installation_queue.task_completed.connect(lambda x: progress_step(x.name)) # This should be the only thread running, wait for the others to finish if not. if threadMgr.running > 1: # it could be that the threads finish execution before the task is executed, # but that should not cause any issues def wait_for_all_treads(): for message in ("Thread %s is running" % n for n in threadMgr.names): log.debug(message) threadMgr.wait_all() # Use a queue with a single task as only TaskQueues have the status_message # property used for setting the progress status in the UI. wait_for_threads = TaskQueue( "Wait for threads to finish", N_("Waiting for %s threads to finish") % (threadMgr.running - 1)) wait_for_threads.append( Task("Wait for all threads to finish", wait_for_all_treads)) installation_queue.append(wait_for_threads) # Save system time to HW clock. # - this used to be before waiting on threads, but I don't think that's needed if conf.system.can_set_hardware_clock: # lets just do this as a top-level task - no save_hwclock = Task("Save system time to HW clock", timezone.save_hw_clock) installation_queue.append(save_hwclock) # setup the installation environment setup_environment = TaskQueue( "Installation environment setup", N_("Setting up the installation environment")) boss_proxy = BOSS.get_proxy() for service_name, object_path in boss_proxy.CollectConfigureRuntimeTasks(): task_proxy = DBus.get_proxy(service_name, object_path) setup_environment.append(DBusTask(task_proxy)) # Add configuration tasks for the Localization DBus module. if is_module_available(LOCALIZATION): localization_proxy = LOCALIZATION.get_proxy() # Populate the missing keyboard values before the payload installation, # so the module requirements can be generated for the right configuration. # FIXME: Make sure that the module always returns right values. populate_task = localization_proxy.PopulateMissingKeyboardConfigurationWithTask( ) setup_environment.append_dbus_tasks(LOCALIZATION, [populate_task]) installation_queue.append(setup_environment) # Do partitioning. # Depending on current payload the storage might be apparently configured # either before or after package/payload installation. # So let's have two task queues - early storage & late storage. storage_proxy = STORAGE.get_proxy() early_storage = TaskQueue("Early storage configuration", N_("Configuring storage")) early_storage.append_dbus_tasks(STORAGE, storage_proxy.InstallWithTasks()) if payload.type == PAYLOAD_TYPE_DNF: conf_task = storage_proxy.WriteConfigurationWithTask() early_storage.append_dbus_tasks(STORAGE, [conf_task]) installation_queue.append(early_storage) # Run %pre-install scripts with the filesystem mounted and no packages pre_install_scripts = TaskQueue("Pre-install scripts", N_("Running pre-installation scripts")) pre_install_scripts.append( Task("Run %pre-install scripts", runPreInstallScripts, (ksdata.scripts, ))) installation_queue.append(pre_install_scripts) # Do various pre-installation tasks # - try to discover a realm (if any) # - check for possibly needed additional packages. pre_install = TaskQueue("Pre install tasks", N_("Running pre-installation tasks")) # make name resolution work for rpm scripts in chroot if conf.system.provides_resolver_config: # we use a custom Task subclass as the sysroot path has to be resolved # only when the task is actually started, not at task creation time pre_install.append(WriteResolvConfTask("Copy resolv.conf to sysroot")) if is_module_available(SECURITY): security_proxy = SECURITY.get_proxy() # Discover a realm. pre_install.append_dbus_tasks(SECURITY, [security_proxy.DiscoverRealmWithTask()]) # Set up FIPS for the payload installation. fips_task = security_proxy.PreconfigureFIPSWithTask(payload.type) pre_install.append_dbus_tasks(SECURITY, [fips_task]) # Install the payload. pre_install.append( Task("Find additional packages & run pre_install()", payload.pre_install)) installation_queue.append(pre_install) payload_install = TaskQueue("Payload installation", N_("Installing.")) payload_install.append(Task("Install the payload", payload.install)) installation_queue.append(payload_install) # for some payloads storage is configured after the payload is installed if payload.type != PAYLOAD_TYPE_DNF: late_storage = TaskQueue("Late storage configuration", N_("Configuring storage")) conf_task = storage_proxy.WriteConfigurationWithTask() late_storage.append_dbus_tasks(STORAGE, [conf_task]) installation_queue.append(late_storage) # Do bootloader. bootloader_proxy = STORAGE.get_proxy(BOOTLOADER) bootloader_install = TaskQueue("Bootloader installation", N_("Installing boot loader")) def run_install_bootloader(): tasks = bootloader_proxy.InstallBootloaderWithTasks( payload.type, payload.kernel_version_list) for task in tasks: sync_run_task(STORAGE.get_proxy(task)) bootloader_install.append( Task("Install bootloader", run_install_bootloader)) installation_queue.append(bootloader_install) post_install = TaskQueue("Post-installation setup tasks", (N_("Performing post-installation setup tasks"))) post_install.append( Task("Run post-installation setup tasks", payload.post_install)) installation_queue.append(post_install) # Create snapshot snapshot_proxy = STORAGE.get_proxy(SNAPSHOT) if snapshot_proxy.IsRequested(SNAPSHOT_WHEN_POST_INSTALL): snapshot_creation = TaskQueue("Creating post installation snapshots", N_("Creating snapshots")) snapshot_task = snapshot_proxy.CreateWithTask( SNAPSHOT_WHEN_POST_INSTALL) snapshot_creation.append_dbus_tasks(STORAGE, [snapshot_task]) installation_queue.append(snapshot_creation) return installation_queue
def execute(self): localization_proxy = LOCALIZATION.get_proxy() keyboard.write_keyboard_config(localization_proxy, conf.target.system_root)
def execute(self): localization_proxy = LOCALIZATION.get_proxy() task_path = localization_proxy.InstallLanguageWithTask( util.getSysroot()) task_proxy = LOCALIZATION.get_proxy(task_path) sync_run_task(task_proxy)
# reboot with kexec if ksdata.reboot.kexec: flags.kexec = True # Some kickstart commands must be executed immediately, as they affect # how anaconda operates. ksdata.logging.execute() anaconda.ksdata = ksdata # setup keyboard layout from the command line option and let # it override from kickstart if/when X is initialized from pyanaconda.modules.common.constants.services import LOCALIZATION localization_proxy = LOCALIZATION.get_proxy() configured = any( (localization_proxy.Keyboard, localization_proxy.VirtualConsoleKeymap, localization_proxy.XLayouts)) if opts.keymap and not configured: localization_proxy.SetKeyboard(opts.keymap) configured = True if configured: if conf.system.can_activate_keyboard: keyboard.activate_keyboard(localization_proxy) else: # at least make sure we have all the values keyboard.populate_missing_items(localization_proxy)
def execute(self): localization_proxy = LOCALIZATION.get_proxy() task_path = localization_proxy.InstallLanguageWithTask(util.getSysroot()) task_proxy = LOCALIZATION.get_proxy(task_path) sync_run_task(task_proxy)
def _apply(self): # Do not execute sections that were part of the original # anaconda kickstart file (== have .seen flag set) log.info("applying changes") services_proxy = SERVICES.get_proxy() reconfig_mode = services_proxy.SetupOnBoot == SETUP_ON_BOOT_RECONFIG # data.selinux # data.firewall # Configure the timezone. timezone_proxy = TIMEZONE.get_proxy() for task_path in timezone_proxy.InstallWithTasks(): task_proxy = TIMEZONE.get_proxy(task_path) sync_run_task(task_proxy) # Configure the localization. localization_proxy = LOCALIZATION.get_proxy() for task_path in localization_proxy.InstallWithTasks(): task_proxy = LOCALIZATION.get_proxy(task_path) sync_run_task(task_proxy) # Configure persistent hostname network_proxy = NETWORK.get_proxy() network_task = network_proxy.ConfigureHostnameWithTask(True) task_proxy = NETWORK.get_proxy(network_task) sync_run_task(task_proxy) # Set current hostname network_proxy.SetCurrentHostname(network_proxy.Hostname) # Configure groups, users & root account # # NOTE: We only configure groups, users & root account if the respective # kickstart commands are *not* seen in the input kickstart. # This basically means that we will configure only what was # set in the Initial Setup UI and will not attempt to configure # anything that looks like it was configured previously in # the Anaconda UI or installation kickstart. users_proxy = USERS.get_proxy() if self._groups_already_configured and not reconfig_mode: log.debug("skipping user group configuration - already configured") elif users_proxy.Groups: # only run of there are some groups to create groups_task = users_proxy.ConfigureGroupsWithTask() task_proxy = USERS.get_proxy(groups_task) log.debug("configuring user groups via %s task", task_proxy.Name) sync_run_task(task_proxy) if self._users_already_configured and not reconfig_mode: log.debug("skipping user configuration - already configured") elif users_proxy.Users: # only run if there are some users to create users_task = users_proxy.ConfigureUsersWithTask() task_proxy = USERS.get_proxy(users_task) log.debug("configuring users via %s task", task_proxy.Name) sync_run_task(task_proxy) if self._root_password_already_configured and not reconfig_mode: log.debug( "skipping root password configuration - already configured") else: root_task = users_proxy.SetRootPasswordWithTask() task_proxy = USERS.get_proxy(root_task) log.debug("configuring root password via %s task", task_proxy.Name) sync_run_task(task_proxy) # Configure all addons log.info("executing addons") self.data.addons.execute(storage=None, ksdata=self.data, users=None, payload=None) boss_proxy = BOSS.get_proxy() task_path = boss_proxy.InstallSystemWithTask() task_proxy = BOSS.get_proxy(task_path) sync_run_task(task_proxy) if self.external_reconfig: # prevent the reconfig flag from being written out # to kickstart if neither /etc/reconfigSys or /.unconfigured # are present services_proxy = SERVICES.get_proxy() services_proxy.SetSetupOnBoot(SETUP_ON_BOOT_DEFAULT) # Write the kickstart data to file log.info("writing the Initial Setup kickstart file %s", OUTPUT_KICKSTART_PATH) with open(OUTPUT_KICKSTART_PATH, "w") as f: f.write(str(self.data)) log.info("finished writing the Initial Setup kickstart file") # Remove the reconfig files, if any - otherwise the reconfig mode # would start again next time the Initial Setup service is enabled. if self.external_reconfig: for reconfig_file in RECONFIG_FILES: if os.path.exists(reconfig_file): log.debug("removing reconfig trigger file: %s" % reconfig_file) os.remove(reconfig_file) # and we are done with applying changes log.info("all changes have been applied")
def _prepare_configuration(payload, ksdata): """Configure the installed system.""" configuration_queue = TaskQueue("Configuration queue") # connect progress reporting configuration_queue.queue_started.connect( lambda x: progress_message(x.status_message)) configuration_queue.task_completed.connect(lambda x: progress_step(x.name)) # schedule the execute methods of ksdata that require an installed system to be present os_config = TaskQueue("Installed system configuration", N_("Configuring installed system")) # add installation tasks for the Security DBus module security_proxy = SECURITY.get_proxy() security_dbus_tasks = security_proxy.InstallWithTasks() os_config.append_dbus_tasks(SECURITY, security_dbus_tasks) # add installation tasks for the Services DBus module services_proxy = SERVICES.get_proxy() services_dbus_tasks = services_proxy.InstallWithTasks() os_config.append_dbus_tasks(SERVICES, services_dbus_tasks) # add installation tasks for the Timezone DBus module timezone_proxy = TIMEZONE.get_proxy() timezone_dbus_tasks = timezone_proxy.InstallWithTasks() os_config.append_dbus_tasks(TIMEZONE, timezone_dbus_tasks) # add installation tasks for the Localization DBus module localization_proxy = LOCALIZATION.get_proxy() localization_dbus_tasks = localization_proxy.InstallWithTasks() os_config.append_dbus_tasks(LOCALIZATION, localization_dbus_tasks) # add the Firewall configuration task firewall_proxy = NETWORK.get_proxy(FIREWALL) firewall_dbus_task = firewall_proxy.InstallWithTask() os_config.append_dbus_tasks(NETWORK, [firewall_dbus_task]) configuration_queue.append(os_config) # schedule network configuration (if required) if conf.system.provides_network_config: overwrite = isinstance(payload, LiveImagePayload) network_config = TaskQueue("Network configuration", N_("Writing network configuration")) network_config.append( Task("Network configuration", network.write_configuration, (overwrite, ))) configuration_queue.append(network_config) # add installation tasks for the Users DBus module user_config = TaskQueue("User creation", N_("Creating users")) users_proxy = USERS.get_proxy() users_dbus_tasks = users_proxy.InstallWithTasks() os_config.append_dbus_tasks(USERS, users_dbus_tasks) configuration_queue.append(user_config) # Anaconda addon configuration addon_config = TaskQueue("Anaconda addon configuration", N_("Configuring addons")) # there is no longer a User class & addons should no longer need it # FIXME: drop user class parameter from the API & all known addons addon_config.append( Task("Configure Anaconda addons", ksdata.addons.execute, (None, ksdata, None, payload))) boss_proxy = BOSS.get_proxy() addon_config.append_dbus_tasks(BOSS, [boss_proxy.InstallSystemWithTask()]) configuration_queue.append(addon_config) # Initramfs generation generate_initramfs = TaskQueue("Initramfs generation", N_("Generating initramfs")) generate_initramfs.append( Task("Generate initramfs", payload.recreate_initrds)) # This works around 2 problems, /boot on BTRFS and BTRFS installations where the initrd is # recreated after the first writeBootLoader call. This reruns it after the new initrd has # been created, fixing the kernel root and subvol args and adding the missing initrd entry. bootloader_proxy = STORAGE.get_proxy(BOOTLOADER) if isinstance(payload, LiveImagePayload): btrfs_task = bootloader_proxy.FixBTRFSWithTask( payload.kernel_version_list) generate_initramfs.append_dbus_tasks(STORAGE, [btrfs_task]) # Invoking zipl should be the last thing done on a s390x installation (see #1652727). zipl_task = bootloader_proxy.FixZIPLWithTask() generate_initramfs.append_dbus_tasks(STORAGE, [zipl_task]) configuration_queue.append(generate_initramfs) # realm join # - this can run only after network is configured in the target system chroot configuration_queue.append_dbus_tasks(SECURITY, [security_proxy.JoinRealmWithTask()]) post_scripts = TaskQueue("Post installation scripts", N_("Running post-installation scripts")) post_scripts.append( Task("Run post installation scripts", runPostScripts, (ksdata.scripts, ))) configuration_queue.append(post_scripts) # setup kexec reboot if requested if flags.flags.kexec: kexec_setup = TaskQueue("Kexec setup", N_("Setting up kexec")) kexec_setup.append(Task("Setup kexec", setup_kexec)) configuration_queue.append(kexec_setup) # write anaconda related configs & kickstarts write_configs = TaskQueue("Write configs and kickstarts", N_("Storing configuration files and kickstarts")) # Write the kickstart file to the installed system (or, copy the input # kickstart file over if one exists). if flags.flags.nosave_output_ks: # don't write the kickstart file to the installed system if this has # been disabled by the nosave option log.warning( "Writing of the output kickstart to installed system has been disabled" " by the nosave option.") else: # write anaconda related configs & kickstarts write_configs.append(Task("Store kickstarts", _writeKS, (ksdata, ))) # only add write_configs to the main queue if we actually store some kickstarts/configs if write_configs.task_count: configuration_queue.append(write_configs) return configuration_queue