diff --git a/0001-Ditch-all-use-of-pyanaconda-s-simpleconfig.patch b/0001-Ditch-all-use-of-pyanaconda-s-simpleconfig.patch new file mode 100644 index 0000000..dba642d --- /dev/null +++ b/0001-Ditch-all-use-of-pyanaconda-s-simpleconfig.patch @@ -0,0 +1,166 @@ +From a7c1245430597bcfaf595ffce70d16630ef4bfbe Mon Sep 17 00:00:00 2001 +From: Adam Williamson +Date: Thu, 30 Aug 2018 11:31:55 -0700 +Subject: [PATCH] Ditch all use of pyanaconda's simpleconfig + +lorax uses pyanaconda's SimpleConfigParser in three different +places (twice with a copy that's been dumped into pylorax, once +by importing it), just to do a fairly simple job: read some +values out of /etc/os-release. The only value SimpleConfigParser +is adding over Python's own ConfigParser here is to read a file +with no section headers, and to unquote the values. The cost is +either a dependency on pyanaconda, or needing to copy the whole +of simpleparser plus some other utility bits from pyanaconda +into lorax. This seems like a bad trade-off. + +This changes the approach: we copy one very simple utility +function from pyanaconda (`unquote`), and do some very simple +wrapping of ConfigParser to handle reading a file without any +section headers, and returning unquoted values. This way we can +read what we need out of os-release without needing a dep on +pyanaconda or to copy lots of things from it into pylorax. + +Resolves: #449 +Resolves: #450 + +Signed-off-by: Adam Williamson +--- + src/pylorax/api/compose.py | 15 ++++++--------- + src/pylorax/api/dnfbase.py | 7 +++---- + src/pylorax/sysutils.py | 23 +++++++++++++++++++++++ + src/sbin/lorax | 7 +++---- + 4 files changed, 35 insertions(+), 17 deletions(-) + +diff --git a/src/pylorax/api/compose.py b/src/pylorax/api/compose.py +index c0ed3b7d..816ea535 100644 +--- a/src/pylorax/api/compose.py ++++ b/src/pylorax/api/compose.py +@@ -40,8 +40,6 @@ import pytoml as toml + import shutil + from uuid import uuid4 + +-from pyanaconda.simpleconfig import SimpleConfigFile +- + # Use pykickstart to calculate disk image size + from pykickstart.parser import KickstartParser + from pykickstart.version import makeVersion +@@ -51,7 +49,7 @@ from pylorax.api.projects import ProjectsError + from pylorax.api.recipes import read_recipe_and_id + from pylorax.api.timestamp import TS_CREATED, write_timestamp + from pylorax.imgutils import default_image_name +-from pylorax.sysutils import joinpaths ++from pylorax.sysutils import joinpaths, flatconfig + + + def test_templates(dbo, share_dir): +@@ -356,14 +354,13 @@ def start_build(cfg, dnflock, gitlock, branch, recipe_name, compose_type, test_m + # Get the title, project, and release version from the host + if not os.path.exists("/etc/os-release"): + log.error("/etc/os-release is missing, cannot determine product or release version") +- os_release = SimpleConfigFile("/etc/os-release") +- os_release.read() ++ os_release = flatconfig("/etc/os-release") + +- log.debug("os_release = %s", os_release) ++ log.debug("os_release = %s", dict(os_release.items())) + +- cfg_args["title"] = os_release.get("PRETTY_NAME") +- cfg_args["project"] = os_release.get("NAME") +- cfg_args["releasever"] = os_release.get("VERSION_ID") ++ cfg_args["title"] = os_release.get("PRETTY_NAME", "") ++ cfg_args["project"] = os_release.get("NAME", "") ++ cfg_args["releasever"] = os_release.get("VERSION_ID", "") + cfg_args["volid"] = "" + + cfg_args.update({ +diff --git a/src/pylorax/api/dnfbase.py b/src/pylorax/api/dnfbase.py +index df4444dc..b7a4d1c6 100644 +--- a/src/pylorax/api/dnfbase.py ++++ b/src/pylorax/api/dnfbase.py +@@ -26,7 +26,7 @@ import os + import shutil + + from pylorax import DEFAULT_PLATFORM_ID +-from pylorax.simpleconfig import SimpleConfigFile ++from pylorax.sysutils import flatconfig + + def get_base_object(conf): + """Get the DNF object with settings from the config file +@@ -76,9 +76,8 @@ def get_base_object(conf): + log.warning("/etc/os-release is missing, cannot determine platform id, falling back to %s", DEFAULT_PLATFORM_ID) + platform_id = DEFAULT_PLATFORM_ID + else: +- os_release = SimpleConfigFile("/etc/os-release") +- os_release.read() +- platform_id = os_release.get("PLATFORM_ID") or DEFAULT_PLATFORM_ID ++ os_release = flatconfig("/etc/os-release") ++ platform_id = os_release.get("PLATFORM_ID", DEFAULT_PLATFORM_ID) + log.info("Using %s for module_platform_id", platform_id) + dbc.module_platform_id = platform_id + +diff --git a/src/pylorax/sysutils.py b/src/pylorax/sysutils.py +index c2f46f1e..1ecbac67 100644 +--- a/src/pylorax/sysutils.py ++++ b/src/pylorax/sysutils.py +@@ -30,6 +30,8 @@ import pwd + import grp + import glob + import shutil ++import shlex ++from configparser import ConfigParser + + from pylorax.executils import runcmd + +@@ -106,3 +108,24 @@ def remove(target): + + def linktree(src, dst): + runcmd(["/bin/cp", "-alx", src, dst]) ++ ++def unquote(s): ++ return ' '.join(shlex.split(s)) ++ ++class UnquotingConfigParser(ConfigParser): ++ """A ConfigParser, only with unquoting of the values.""" ++ def get(self, *args, **kwargs): ++ ret = super().get(*args, **kwargs) ++ if ret: ++ ret = unquote(ret) ++ return ret ++ ++def flatconfig(filename): ++ """Use UnquotingConfigParser to read a flat config file (without ++ section headers) by adding a section header. ++ """ ++ with open (filename, 'r') as conffh: ++ conftext = "[main]\n" + conffh.read() ++ config = ConfigParser() ++ config.read_string(conftext) ++ return config['main'] +diff --git a/src/sbin/lorax b/src/sbin/lorax +index ce21d8f5..30b9cadc 100755 +--- a/src/sbin/lorax ++++ b/src/sbin/lorax +@@ -35,7 +35,7 @@ import librepo + import pylorax + from pylorax import DRACUT_DEFAULT, DEFAULT_PLATFORM_ID + from pylorax.cmdline import lorax_parser +-from pylorax.simpleconfig import SimpleConfigFile ++from pylorax.sysutils import flatconfig + import selinux + + def setup_logging(opts): +@@ -225,9 +225,8 @@ def get_dnf_base_object(installroot, sources, mirrorlists=None, repos=None, + log.warning("/etc/os-release is missing, cannot determine platform id, falling back to %s", DEFAULT_PLATFORM_ID) + platform_id = DEFAULT_PLATFORM_ID + else: +- os_release = SimpleConfigFile("/etc/os-release") +- os_release.read() +- platform_id = os_release.get("PLATFORM_ID") or DEFAULT_PLATFORM_ID ++ os_release = flatconfig("/etc/os-release") ++ platform_id = os_release.get("PLATFORM_ID", DEFAULT_PLATFORM_ID) + log.info("Using %s for module_platform_id", platform_id) + conf.module_platform_id = platform_id + +-- +2.17.1 + diff --git a/lorax.spec b/lorax.spec index 0264589..9a8fef6 100644 --- a/lorax.spec +++ b/lorax.spec @@ -4,7 +4,7 @@ Name: lorax Version: 29.13 -Release: 1%{?dist} +Release: 2%{?dist} Summary: Tool for creating the anaconda install images Group: Applications/System @@ -15,6 +15,8 @@ URL: https://github.com/weldr/lorax # git checkout -b archive-branch lorax-%%{version}-%%{release} # tito build --tgz Source0: %{name}-%{version}.tar.gz +# Hopefully make lorax actually work without pyanaconda +Patch0: 0001-Ditch-all-use-of-pyanaconda-s-simpleconfig.patch BuildRequires: python3-devel @@ -156,6 +158,7 @@ build images, etc. from the command line. %prep %setup -q -n %{name}-%{version} +%patch0 -p1 %build @@ -230,6 +233,9 @@ getent passwd weldr >/dev/null 2>&1 || useradd -r -g weldr -d / -s /sbin/nologin %{_sysconfdir}/bash_completion.d/composer-cli %changelog +* Thu Aug 30 2018 Adam Williamson - 29.13-2 +- Backport upstream PR#451 to avoid undeclared pyanaconda dependency + * Wed Aug 29 2018 Brian C. Lane 29.13-1 - Update the example blueprints for rawhide (bcl@redhat.com) - Bump required dnf version to 3.2.0 for module_platform_id support (bcl@redhat.com)