def run(self): """Run the task""" if not self._gpg_keys: log.debug("No GPG keys to import.") return if not os.path.exists(self._sysroot + "/usr/bin/rpm"): log.error( "Can not import GPG keys to RPM database because " "the 'rpm' executable is missing on the target " "system. The following keys were not imported:\n%s", "\n".join(self._gpg_keys) ) return # Get substitutions for variables. # TODO: replace the interpolation with DNF once possible basearch = util.execWithCapture("uname", ["-i"]).strip().replace("'", "") releasever = util.get_os_release_value("VERSION_ID", sysroot=self._sysroot) or "" # Import GPG keys to RPM database. for key in self._gpg_keys: key = key.replace("$releasever", releasever).replace("$basearch", basearch) log.info("Importing GPG key to RPM database: %s", key) rc = util.execWithRedirect("rpm", ["--import", key], root=self._sysroot) if rc: log.error("Failed to import the GPG key.")
def _create_base(cls): """Create a new DNF base.""" base = dnf.Base() base.conf.read() base.conf.cachedir = DNF_CACHE_DIR base.conf.pluginconfpath = DNF_PLUGINCONF_DIR base.conf.logdir = '/tmp/' # Set installer defaults base.conf.gpgcheck = False base.conf.skip_if_unavailable = False # Set the substitution variables. cls._reset_substitution(base) # Set the installation root. base.conf.installroot = conf.target.system_root base.conf.prepend_installroot('persistdir') # Set the platform id based on the /os/release present # in the installation environment. platform_id = get_os_release_value("PLATFORM_ID") if platform_id is not None: base.conf.module_platform_id = platform_id # Start with an empty comps so we can go ahead and use # the environment and group properties. Unset reposdir # to ensure dnf has nothing it can check automatically. base.conf.reposdir = [] base.read_comps(arch_filter=True) base.conf.reposdir = DNF_REPO_DIRS log.debug("The DNF base has been created.") return base
def _create_base(): """Create a new DNF base.""" base = dnf.Base() base.conf.cachedir = DNF_CACHE_DIR base.conf.pluginconfpath = DNF_PLUGINCONF_DIR base.conf.logdir = '/tmp/' base.conf.releasever = get_product_release_version() base.conf.installroot = conf.target.system_root base.conf.prepend_installroot('persistdir') # Load variables substitutions configuration (rhbz#1920735) base.conf.substitutions.update_from_etc("/") # Set the platform id based on the /os/release present # in the installation environment. platform_id = get_os_release_value("PLATFORM_ID") if platform_id is not None: base.conf.module_platform_id = platform_id # Start with an empty comps so we can go ahead and use # the environment and group properties. Unset reposdir # to ensure dnf has nothing it can check automatically. base.conf.reposdir = [] base.read_comps(arch_filter=True) base.conf.reposdir = DNF_REPO_DIRS log.debug("The DNF base has been created.") return base
def test_get_os_relase_value(self): """Test the get_release_value function.""" with tempfile.TemporaryDirectory() as root: # prepare paths util.mkdirChain(root + "/usr/lib") util.mkdirChain(root + "/etc") # no file with self.assertLogs(level="DEBUG") as cm: version = util.get_os_release_value("VERSION_ID", root) msg = "VERSION_ID not found in os-release files" self.assertTrue(any(map(lambda x: msg in x, cm.output))) self.assertEqual(version, None) # backup file only with open(root + "/usr/lib/os-release", "w") as f: f.write( "# blah\nVERSION_ID=foo256bar \n VERSION_ID = wrong\n\n") version = util.get_os_release_value("VERSION_ID", root) self.assertEqual(version, "foo256bar") self.assertEqual(util.get_os_release_value("PLATFORM_ID", root), None) # main file and backup too with open(root + "/etc/os-release", "w") as f: f.write("# blah\nVERSION_ID=more-important\n") version = util.get_os_release_value("VERSION_ID", root) self.assertEqual(version, "more-important") # both, main file twice with open(root + "/etc/os-release", "w") as f: f.write( "# blah\nVERSION_ID=more-important\nVERSION_ID=not-reached\n \n" ) version = util.get_os_release_value("VERSION_ID", root) self.assertEqual(version, "more-important") # quoted values with open(root + "/etc/os-release", "w") as f: f.write( "PRETTY_NAME=\"Fedora 32\"\nPLATFORM_ID='platform:f32'\n") self.assertEqual(util.get_os_release_value("PRETTY_NAME", root), "Fedora 32") self.assertEqual(util.get_os_release_value("PLATFORM_ID", root), "platform:f32") # no files os.remove(root + "/usr/lib/os-release") os.remove(root + "/etc/os-release") version = util.get_os_release_value("VERSION_ID", root) self.assertEqual(version, None)
def test_set_from_detected_product(self): conf = AnacondaConfiguration.from_defaults() conf.set_from_product(get_os_release_value("NAME"))
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. if opts.profile_id: conf.set_from_profile(opts.profile_id, ) else: conf.set_from_detected_profile( util.get_os_release_value("ID"), util.get_os_release_value("VARIANT_ID"), ) 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 not conf.target.can_copy_input_kickstart:
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. from pyanaconda import product conf.set_from_product(requested_product=opts.product_name, requested_variant=opts.variant_name, buildstamp_product=product.productName, buildstamp_variant=product.productVariant, default_product=util.get_os_release_value("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."
def get_product_name(): """Get a product name :return: a product name """ return get_os_release_value("NAME") or ""
def get_product_title(): """Get product title. :return: a product title """ return get_os_release_value("PRETTY_NAME") or ""