def set_from_files_test(self): conf = AnacondaConfiguration.from_defaults() paths = [] with tempfile.TemporaryDirectory() as d: # Add nonexistent file. nonexistent = os.path.join(d, "nonexistent") paths.append(nonexistent) # Add empty directory. empty_dir = os.path.join(d, "empty") os.mkdir(empty_dir) paths.append(empty_dir) # Add existing file. existing = os.path.join(d, "a.conf") paths.append(existing) with open(existing, mode="w") as f: f.write("") # Add non-empty directory. conf_dir = os.path.join(d, "conf.d") os.mkdir(conf_dir) paths.append(conf_dir) for name in ["b.conf", "c.conf", "d"]: with open(os.path.join(conf_dir, name), mode="w") as f: f.write("") # Check the paths. self.assertEqual( [os.path.relpath(path, d) for path in paths], ["nonexistent", "empty", "a.conf", "conf.d"] ) conf._sources = [] conf.set_from_files(paths) # Check the loaded files. self.assertEqual( [os.path.relpath(path, d) for path in conf.get_sources()], ["a.conf", "conf.d/b.conf", "conf.d/c.conf"] )
def __init__(self, gui_mode): """Initialize the Initial Setup internals""" log.debug("initializing Initial Setup") # True if running in graphical mode, False otherwise (text mode) self.gui_mode = gui_mode # kickstart data self.data = None # reboot on quit flag self._reboot_on_quit = False # parse any command line arguments args = self._parse_arguments() # initialize logging initial_setup_log.init(stdout_log=not args.no_stdout_log) global logging_initialized logging_initialized = True log.info("Initial Setup %s" % __version__) # check if we are running as root if os.geteuid() != 0: log.critical("Initial Setup needs to be run as root") raise InitialSetupError # load configuration files from pyanaconda.core.configuration.anaconda import conf conf.set_from_files(["/etc/initial-setup/conf.d/"]) if self.gui_mode: log.debug("running in GUI mode") else: log.debug("running in TUI mode") self._external_reconfig = False # check if the reconfig mode should be enabled # by checking if at least one of the reconfig # files exist for reconfig_file in RECONFIG_FILES: if os.path.exists(reconfig_file): self.external_reconfig = True log.debug("reconfig trigger file found: %s", reconfig_file) if self.external_reconfig: log.debug("running in externally triggered reconfig mode") if self.gui_mode: # We need this so we can tell GI to look for overrides objects # also in anaconda source directories import gi.overrides for p in os.environ.get("ANACONDA_WIDGETS_OVERRIDES", "").split(":"): gi.overrides.__path__.insert(0, p) log.debug("GI overrides imported") from pyanaconda.addons import collect_addon_paths addon_paths = [ "/usr/share/initial-setup/modules", "/usr/share/anaconda/addons" ] # append ADDON_PATHS dirs at the end sys.path.extend(addon_paths) self._addon_module_paths = collect_addon_paths(addon_paths, self.gui_mode_id) log.info("found %d addon modules:", len(self._addon_module_paths)) for addon_path in self._addon_module_paths: log.debug(addon_path) # Too bad anaconda does not have modularized logging log.debug("initializing the Anaconda log") from pyanaconda import anaconda_logging anaconda_logging.init(write_to_journal=True) # create class for launching our dbus session self._dbus_launcher = AnacondaDBusLauncher() # group, user, root password set-before tracking self._groups_already_configured = False self._users_already_configured = False self._root_password_already_configured = False
# do this early so we can set flags before initializing logging from pyanaconda.flags import flags (opts, depr) = parse_arguments(boot_cmdline=flags.cmdline) from pyanaconda.core.configuration.anaconda import conf conf.set_from_opts(opts) # Set up logging as early as possible. from pyanaconda import anaconda_logging from pyanaconda import anaconda_loggers anaconda_logging.init(write_to_journal=conf.target.is_hardware) anaconda_logging.logger.setupVirtio(opts.virtiolog) # Load the remaining configuration after a logging is set up. conf.set_from_product(opts.product_name, opts.variant_name) conf.set_from_files() conf.set_from_opts(opts) log = anaconda_loggers.get_main_logger() stdout_log = anaconda_loggers.get_stdout_logger() if os.geteuid() != 0: stdout_log.error("anaconda must be run as root.") sys.exit(1) # check if input kickstart should be saved if flags.nosave_input_ks: log.warning( "Input kickstart will not be saved to the installed system due to the nosave option." ) util.touch('/tmp/NOSAVE_INPUT_KS')