From e6145faf86153d4a50a6a3ef242ae2d9d126c6f7 Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Thu, 3 May 2018 14:21:33 -0700 Subject: [PATCH] Convert Yum usage to DNF The DNF api is similar, but not the same, as Yum. Make the needed changes, and rename yum references to dnf to avoid confustion later. --- src/pylorax/api/compose.py | 52 ++++++++++++++++---------------------- src/pylorax/api/server.py | 2 +- src/pylorax/api/v0.py | 30 +++++++++++----------- 3 files changed, 38 insertions(+), 46 deletions(-) diff --git a/src/pylorax/api/compose.py b/src/pylorax/api/compose.py index bacde108..3df6f36b 100644 --- a/src/pylorax/api/compose.py +++ b/src/pylorax/api/compose.py @@ -55,33 +55,25 @@ from pylorax.sysutils import joinpaths def repo_to_ks(r, url="url"): """ Return a kickstart line with the correct args. + :param r: DNF repository information + :type r: dnf.Repo + :param url: "url" or "baseurl" to use for the baseurl parameter + :type url: str + :returns: kickstart command arguments for url/repo command + :rtype: str Set url to "baseurl" if it is a repo, leave it as "url" for the installation url. """ cmd = "" - if url == "url": - if not r.urls: - raise RuntimeError("Cannot find a base url for %s" % r.name) - - # url is passed to Anaconda on the cmdline with --repo, so it cannot support a mirror - # If a mirror is setup yum will return the list of mirrors in .urls - # So just use the first one. - cmd += '--%s="%s" ' % (url, r.urls[0]) + # url uses --url not --baseurl + if r.baseurl: + cmd += '--%s="%s" ' % (url, r.baseurl[0]) elif r.metalink: - # XXX Total Hack - # RHEL7 kickstart doesn't support metalink. If the url has 'metalink' in it, rewrite it as 'mirrorlist' - if "metalink" in r.metalink: - log.info("RHEL7 does not support metalink, translating to mirrorlist") - cmd += '--mirrorlist="%s" ' % r.metalink.replace("metalink", "mirrorlist") - else: - log.error("Could not convert metalink to mirrorlist. %s", r.metalink) - raise RuntimeError("Cannot convert metalink to mirrorlist: %s" % r.metalink) + cmd += '--metalink="%s" ' % r.metalink elif r.mirrorlist: cmd += '--mirrorlist="%s" ' % r.mirrorlist - elif r.baseurl: - cmd += '--%s="%s" ' % (url, r.baseurl[0]) else: - raise RuntimeError("Repo has no baseurl or mirror") + raise RuntimeError("Repo has no baseurl, metalink, or mirrorlist") if r.proxy: cmd += '--proxy="%s" ' % r.proxy @@ -91,13 +83,13 @@ def repo_to_ks(r, url="url"): return cmd -def start_build(cfg, yumlock, gitlock, branch, recipe_name, compose_type, test_mode=0): +def start_build(cfg, dnflock, gitlock, branch, recipe_name, compose_type, test_mode=0): """ Start the build :param cfg: Configuration object :type cfg: ComposerConfig - :param yumlock: Lock and YumBase for depsolving - :type yumlock: YumLock + :param dnflock: Lock and YumBase for depsolving + :type dnflock: YumLock :param recipe: The recipe to build :type recipe: str :param compose_type: The type of output to create from the recipe @@ -122,8 +114,8 @@ def start_build(cfg, yumlock, gitlock, branch, recipe_name, compose_type, test_m projects = sorted(set(module_names+package_names), key=lambda n: n.lower()) deps = [] try: - with yumlock.lock: - (installed_size, deps) = projects_depsolve_with_size(yumlock.yb, projects, with_core=False) + with dnflock.lock: + (installed_size, deps) = projects_depsolve_with_size(dnflock.dbo, projects, with_core=False) except ProjectsError as e: log.error("start_build depsolve: %s", str(e)) raise RuntimeError("Problem depsolving %s: %s" % (recipe["name"], str(e))) @@ -137,8 +129,8 @@ def start_build(cfg, yumlock, gitlock, branch, recipe_name, compose_type, test_m ks = KickstartParser(ks_version, errorsAreFatal=False, missingIncludeIsFatal=False) ks.readKickstartFromString(ks_template+"\n%end\n") try: - with yumlock.lock: - (template_size, _) = projects_depsolve_with_size(yumlock.yb, ks.handler.packages.packageList, + with dnflock.lock: + (template_size, _) = projects_depsolve_with_size(dnflock.dbo, ks.handler.packages.packageList, with_core=not ks.handler.packages.nocore) except ProjectsError as e: log.error("start_build depsolve: %s", str(e)) @@ -173,7 +165,7 @@ def start_build(cfg, yumlock, gitlock, branch, recipe_name, compose_type, test_m # Write out the dependencies to the results dir deps_path = joinpaths(results_dir, "deps.toml") with open(deps_path, "w") as f: - f.write(toml.dumps({"packages":deps}).encode("UTF-8")) + f.write(toml.dumps({"packages":deps})) # Save a copy of the original kickstart shutil.copy(ks_template_path, results_dir) @@ -181,8 +173,8 @@ def start_build(cfg, yumlock, gitlock, branch, recipe_name, compose_type, test_m # Create the final kickstart with repos and package list ks_path = joinpaths(results_dir, "final-kickstart.ks") with open(ks_path, "w") as f: - with yumlock.lock: - repos = yumlock.yb.repos.listEnabled() + with dnflock.lock: + repos = list(dnflock.dbo.repos.iter_enabled()) if not repos: raise RuntimeError("No enabled repos, canceling build.") @@ -230,7 +222,7 @@ def start_build(cfg, yumlock, gitlock, branch, recipe_name, compose_type, test_m "logfile": log_dir }) with open(joinpaths(results_dir, "config.toml"), "w") as f: - f.write(toml.dumps(cfg_args).encode("UTF-8")) + f.write(toml.dumps(cfg_args)) # Set the initial status open(joinpaths(results_dir, "STATUS"), "w").write("WAITING") diff --git a/src/pylorax/api/server.py b/src/pylorax/api/server.py index 492c0c0d..9e668330 100644 --- a/src/pylorax/api/server.py +++ b/src/pylorax/api/server.py @@ -28,7 +28,7 @@ from pylorax.api.v0 import v0_api from pylorax.sysutils import joinpaths GitLock = namedtuple("GitLock", ["repo", "lock", "dir"]) -YumLock = namedtuple("YumLock", ["yb", "lock"]) +DNFLock = namedtuple("DNFLock", ["dbo", "lock"]) server = Flask(__name__) diff --git a/src/pylorax/api/v0.py b/src/pylorax/api/v0.py index 3bf7a2e6..5e27f160 100644 --- a/src/pylorax/api/v0.py +++ b/src/pylorax/api/v0.py @@ -1186,8 +1186,8 @@ def v0_api(api): projects = sorted(set(module_names+package_names), key=lambda n: n.lower()) deps = [] try: - with api.config["YUMLOCK"].lock: - deps = projects_depsolve(api.config["YUMLOCK"].yb, projects) + with api.config["DNFLOCK"].lock: + deps = projects_depsolve(api.config["DNFLOCK"].dbo, projects) except ProjectsError as e: errors.append("%s: %s" % (blueprint_name, str(e))) log.error("(v0_blueprints_freeze) %s", str(e)) @@ -1238,8 +1238,8 @@ def v0_api(api): projects = sorted(set(module_names+package_names), key=lambda n: n.lower()) deps = [] try: - with api.config["YUMLOCK"].lock: - deps = projects_depsolve(api.config["YUMLOCK"].yb, projects) + with api.config["DNFLOCK"].lock: + deps = projects_depsolve(api.config["DNFLOCK"].dbo, projects) except ProjectsError as e: errors.append("%s: %s" % (blueprint_name, str(e))) log.error("(v0_blueprints_depsolve) %s", str(e)) @@ -1266,8 +1266,8 @@ def v0_api(api): return jsonify(status=False, errors=[str(e)]), 400 try: - with api.config["YUMLOCK"].lock: - available = projects_list(api.config["YUMLOCK"].yb) + with api.config["DNFLOCK"].lock: + available = projects_list(api.config["DNFLOCK"].dbo) except ProjectsError as e: log.error("(v0_projects_list) %s", str(e)) return jsonify(status=False, errors=[str(e)]), 400 @@ -1280,8 +1280,8 @@ def v0_api(api): def v0_projects_info(project_names): """Return detailed information about the listed projects""" try: - with api.config["YUMLOCK"].lock: - projects = projects_info(api.config["YUMLOCK"].yb, project_names.split(",")) + with api.config["DNFLOCK"].lock: + projects = projects_info(api.config["DNFLOCK"].dbo, project_names.split(",")) except ProjectsError as e: log.error("(v0_projects_info) %s", str(e)) return jsonify(status=False, errors=[str(e)]), 400 @@ -1293,8 +1293,8 @@ def v0_api(api): def v0_projects_depsolve(project_names): """Return detailed information about the listed projects""" try: - with api.config["YUMLOCK"].lock: - deps = projects_depsolve(api.config["YUMLOCK"].yb, project_names.split(",")) + with api.config["DNFLOCK"].lock: + deps = projects_depsolve(api.config["DNFLOCK"].dbo, project_names.split(",")) except ProjectsError as e: log.error("(v0_projects_depsolve) %s", str(e)) return jsonify(status=False, errors=[str(e)]), 400 @@ -1316,8 +1316,8 @@ def v0_api(api): module_names = module_names.split(",") try: - with api.config["YUMLOCK"].lock: - available = modules_list(api.config["YUMLOCK"].yb, module_names) + with api.config["DNFLOCK"].lock: + available = modules_list(api.config["DNFLOCK"].dbo, module_names) except ProjectsError as e: log.error("(v0_modules_list) %s", str(e)) return jsonify(status=False, errors=[str(e)]), 400 @@ -1330,8 +1330,8 @@ def v0_api(api): def v0_modules_info(module_names): """Return detailed information about the listed modules""" try: - with api.config["YUMLOCK"].lock: - modules = modules_info(api.config["YUMLOCK"].yb, module_names.split(",")) + with api.config["DNFLOCK"].lock: + modules = modules_info(api.config["DNFLOCK"].dbo, module_names.split(",")) except ProjectsError as e: log.error("(v0_modules_info) %s", str(e)) return jsonify(status=False, errors=[str(e)]), 400 @@ -1380,7 +1380,7 @@ def v0_api(api): return jsonify(status=False, errors=errors), 400 try: - build_id = start_build(api.config["COMPOSER_CFG"], api.config["YUMLOCK"], api.config["GITLOCK"], + build_id = start_build(api.config["COMPOSER_CFG"], api.config["DNFLOCK"], api.config["GITLOCK"], branch, blueprint_name, compose_type, test_mode) except Exception as e: return jsonify(status=False, errors=[str(e)]), 400