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.
This commit is contained in:
Brian C. Lane 2018-05-03 14:21:33 -07:00
parent 48671b682a
commit c9187ce4ca
3 changed files with 38 additions and 46 deletions

View File

@ -55,33 +55,25 @@ from pylorax.sysutils import joinpaths
def repo_to_ks(r, url="url"): def repo_to_ks(r, url="url"):
""" Return a kickstart line with the correct args. """ 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. Set url to "baseurl" if it is a repo, leave it as "url" for the installation url.
""" """
cmd = "" cmd = ""
if url == "url": # url uses --url not --baseurl
if not r.urls: if r.baseurl:
raise RuntimeError("Cannot find a base url for %s" % r.name) cmd += '--%s="%s" ' % (url, r.baseurl[0])
# 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])
elif r.metalink: elif r.metalink:
# XXX Total Hack cmd += '--metalink="%s" ' % r.metalink
# 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)
elif r.mirrorlist: elif r.mirrorlist:
cmd += '--mirrorlist="%s" ' % r.mirrorlist cmd += '--mirrorlist="%s" ' % r.mirrorlist
elif r.baseurl:
cmd += '--%s="%s" ' % (url, r.baseurl[0])
else: else:
raise RuntimeError("Repo has no baseurl or mirror") raise RuntimeError("Repo has no baseurl, metalink, or mirrorlist")
if r.proxy: if r.proxy:
cmd += '--proxy="%s" ' % r.proxy cmd += '--proxy="%s" ' % r.proxy
@ -91,13 +83,13 @@ def repo_to_ks(r, url="url"):
return cmd 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 """ Start the build
:param cfg: Configuration object :param cfg: Configuration object
:type cfg: ComposerConfig :type cfg: ComposerConfig
:param yumlock: Lock and YumBase for depsolving :param dnflock: Lock and YumBase for depsolving
:type yumlock: YumLock :type dnflock: YumLock
:param recipe: The recipe to build :param recipe: The recipe to build
:type recipe: str :type recipe: str
:param compose_type: The type of output to create from the recipe :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()) projects = sorted(set(module_names+package_names), key=lambda n: n.lower())
deps = [] deps = []
try: try:
with yumlock.lock: with dnflock.lock:
(installed_size, deps) = projects_depsolve_with_size(yumlock.yb, projects, with_core=False) (installed_size, deps) = projects_depsolve_with_size(dnflock.dbo, projects, with_core=False)
except ProjectsError as e: except ProjectsError as e:
log.error("start_build depsolve: %s", str(e)) log.error("start_build depsolve: %s", str(e))
raise RuntimeError("Problem depsolving %s: %s" % (recipe["name"], 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 = KickstartParser(ks_version, errorsAreFatal=False, missingIncludeIsFatal=False)
ks.readKickstartFromString(ks_template+"\n%end\n") ks.readKickstartFromString(ks_template+"\n%end\n")
try: try:
with yumlock.lock: with dnflock.lock:
(template_size, _) = projects_depsolve_with_size(yumlock.yb, ks.handler.packages.packageList, (template_size, _) = projects_depsolve_with_size(dnflock.dbo, ks.handler.packages.packageList,
with_core=not ks.handler.packages.nocore) with_core=not ks.handler.packages.nocore)
except ProjectsError as e: except ProjectsError as e:
log.error("start_build depsolve: %s", str(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 # Write out the dependencies to the results dir
deps_path = joinpaths(results_dir, "deps.toml") deps_path = joinpaths(results_dir, "deps.toml")
with open(deps_path, "w") as f: 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 # Save a copy of the original kickstart
shutil.copy(ks_template_path, results_dir) 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 # Create the final kickstart with repos and package list
ks_path = joinpaths(results_dir, "final-kickstart.ks") ks_path = joinpaths(results_dir, "final-kickstart.ks")
with open(ks_path, "w") as f: with open(ks_path, "w") as f:
with yumlock.lock: with dnflock.lock:
repos = yumlock.yb.repos.listEnabled() repos = list(dnflock.dbo.repos.iter_enabled())
if not repos: if not repos:
raise RuntimeError("No enabled repos, canceling build.") 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 "logfile": log_dir
}) })
with open(joinpaths(results_dir, "config.toml"), "w") as f: 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 # Set the initial status
open(joinpaths(results_dir, "STATUS"), "w").write("WAITING") open(joinpaths(results_dir, "STATUS"), "w").write("WAITING")

View File

@ -28,7 +28,7 @@ from pylorax.api.v0 import v0_api
from pylorax.sysutils import joinpaths from pylorax.sysutils import joinpaths
GitLock = namedtuple("GitLock", ["repo", "lock", "dir"]) GitLock = namedtuple("GitLock", ["repo", "lock", "dir"])
YumLock = namedtuple("YumLock", ["yb", "lock"]) DNFLock = namedtuple("DNFLock", ["dbo", "lock"])
server = Flask(__name__) server = Flask(__name__)

View File

@ -1186,8 +1186,8 @@ def v0_api(api):
projects = sorted(set(module_names+package_names), key=lambda n: n.lower()) projects = sorted(set(module_names+package_names), key=lambda n: n.lower())
deps = [] deps = []
try: try:
with api.config["YUMLOCK"].lock: with api.config["DNFLOCK"].lock:
deps = projects_depsolve(api.config["YUMLOCK"].yb, projects) deps = projects_depsolve(api.config["DNFLOCK"].dbo, projects)
except ProjectsError as e: except ProjectsError as e:
errors.append("%s: %s" % (blueprint_name, str(e))) errors.append("%s: %s" % (blueprint_name, str(e)))
log.error("(v0_blueprints_freeze) %s", 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()) projects = sorted(set(module_names+package_names), key=lambda n: n.lower())
deps = [] deps = []
try: try:
with api.config["YUMLOCK"].lock: with api.config["DNFLOCK"].lock:
deps = projects_depsolve(api.config["YUMLOCK"].yb, projects) deps = projects_depsolve(api.config["DNFLOCK"].dbo, projects)
except ProjectsError as e: except ProjectsError as e:
errors.append("%s: %s" % (blueprint_name, str(e))) errors.append("%s: %s" % (blueprint_name, str(e)))
log.error("(v0_blueprints_depsolve) %s", 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 return jsonify(status=False, errors=[str(e)]), 400
try: try:
with api.config["YUMLOCK"].lock: with api.config["DNFLOCK"].lock:
available = projects_list(api.config["YUMLOCK"].yb) available = projects_list(api.config["DNFLOCK"].dbo)
except ProjectsError as e: except ProjectsError as e:
log.error("(v0_projects_list) %s", str(e)) log.error("(v0_projects_list) %s", str(e))
return jsonify(status=False, errors=[str(e)]), 400 return jsonify(status=False, errors=[str(e)]), 400
@ -1280,8 +1280,8 @@ def v0_api(api):
def v0_projects_info(project_names): def v0_projects_info(project_names):
"""Return detailed information about the listed projects""" """Return detailed information about the listed projects"""
try: try:
with api.config["YUMLOCK"].lock: with api.config["DNFLOCK"].lock:
projects = projects_info(api.config["YUMLOCK"].yb, project_names.split(",")) projects = projects_info(api.config["DNFLOCK"].dbo, project_names.split(","))
except ProjectsError as e: except ProjectsError as e:
log.error("(v0_projects_info) %s", str(e)) log.error("(v0_projects_info) %s", str(e))
return jsonify(status=False, errors=[str(e)]), 400 return jsonify(status=False, errors=[str(e)]), 400
@ -1293,8 +1293,8 @@ def v0_api(api):
def v0_projects_depsolve(project_names): def v0_projects_depsolve(project_names):
"""Return detailed information about the listed projects""" """Return detailed information about the listed projects"""
try: try:
with api.config["YUMLOCK"].lock: with api.config["DNFLOCK"].lock:
deps = projects_depsolve(api.config["YUMLOCK"].yb, project_names.split(",")) deps = projects_depsolve(api.config["DNFLOCK"].dbo, project_names.split(","))
except ProjectsError as e: except ProjectsError as e:
log.error("(v0_projects_depsolve) %s", str(e)) log.error("(v0_projects_depsolve) %s", str(e))
return jsonify(status=False, errors=[str(e)]), 400 return jsonify(status=False, errors=[str(e)]), 400
@ -1316,8 +1316,8 @@ def v0_api(api):
module_names = module_names.split(",") module_names = module_names.split(",")
try: try:
with api.config["YUMLOCK"].lock: with api.config["DNFLOCK"].lock:
available = modules_list(api.config["YUMLOCK"].yb, module_names) available = modules_list(api.config["DNFLOCK"].dbo, module_names)
except ProjectsError as e: except ProjectsError as e:
log.error("(v0_modules_list) %s", str(e)) log.error("(v0_modules_list) %s", str(e))
return jsonify(status=False, errors=[str(e)]), 400 return jsonify(status=False, errors=[str(e)]), 400
@ -1330,8 +1330,8 @@ def v0_api(api):
def v0_modules_info(module_names): def v0_modules_info(module_names):
"""Return detailed information about the listed modules""" """Return detailed information about the listed modules"""
try: try:
with api.config["YUMLOCK"].lock: with api.config["DNFLOCK"].lock:
modules = modules_info(api.config["YUMLOCK"].yb, module_names.split(",")) modules = modules_info(api.config["DNFLOCK"].dbo, module_names.split(","))
except ProjectsError as e: except ProjectsError as e:
log.error("(v0_modules_info) %s", str(e)) log.error("(v0_modules_info) %s", str(e))
return jsonify(status=False, errors=[str(e)]), 400 return jsonify(status=False, errors=[str(e)]), 400
@ -1380,7 +1380,7 @@ def v0_api(api):
return jsonify(status=False, errors=errors), 400 return jsonify(status=False, errors=errors), 400
try: 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) branch, blueprint_name, compose_type, test_mode)
except Exception as e: except Exception as e:
return jsonify(status=False, errors=[str(e)]), 400 return jsonify(status=False, errors=[str(e)]), 400