--- pykickstart/commands/repo.py | 29 +++++++++++++++++++++++++++++ pykickstart/handlers/f21.py | 4 ++-- pykickstart/handlers/rhel7.py | 4 ++-- tests/commands/repo.py | 10 ++++++++++ 4 files changed, 43 insertions(+), 4 deletions(-)
diff --git a/pykickstart/commands/repo.py b/pykickstart/commands/repo.py index 6e0da76..3ee114c 100644 --- a/pykickstart/commands/repo.py +++ b/pykickstart/commands/repo.py @@ -132,6 +132,24 @@ RHEL6_RepoData = F14_RepoData
F15_RepoData = F14_RepoData
+class F21_RepoData(F14_RepoData): + removedKeywords = F14_RepoData.removedKeywords + removedAttrs = F14_RepoData.removedAttrs + + def __init__(self, *args, **kwargs): + F14_RepoData.__init__(self, *args, **kwargs) + self.install = kwargs.get("install", False) + + def _getArgsAsStr(self): + retval = F14_RepoData._getArgsAsStr(self) + + if self.install: + retval += " --install" + + return retval + +RHEL7_RepoData = F21_RepoData + class FC6_Repo(KickstartCommand): removedKeywords = KickstartCommand.removedKeywords removedAttrs = KickstartCommand.removedAttrs @@ -252,3 +270,14 @@ class F15_Repo(F14_Repo): removedAttrs = F14_Repo.removedAttrs
urlRequired = False + +class F21_Repo(F15_Repo): + removedKeywords = F15_Repo.removedKeywords + removedAttrs = F15_Repo.removedAttrs + + def _getParser(self): + op = F15_Repo._getParser(self) + op.add_option("--install", action="store_true", default=False) + return op + +RHEL7_Repo = F21_Repo diff --git a/pykickstart/handlers/f21.py b/pykickstart/handlers/f21.py index cac66bc..3f377da 100644 --- a/pykickstart/handlers/f21.py +++ b/pykickstart/handlers/f21.py @@ -69,7 +69,7 @@ class F21Handler(BaseHandler): "raid": commands.raid.F20_Raid, "realm": commands.realm.F19_Realm, "reboot": commands.reboot.F18_Reboot, - "repo": commands.repo.F15_Repo, + "repo": commands.repo.F21_Repo, "rescue": commands.rescue.F10_Rescue, "rootpw": commands.rootpw.F18_RootPw, "selinux": commands.selinux.FC3_SELinux, @@ -103,7 +103,7 @@ class F21Handler(BaseHandler): "NetworkData": commands.network.F21_NetworkData, "PartData": commands.partition.F18_PartData, "RaidData": commands.raid.F18_RaidData, - "RepoData": commands.repo.F15_RepoData, + "RepoData": commands.repo.F21_RepoData, "SshPwData": commands.sshpw.F13_SshPwData, "UserData": commands.user.F19_UserData, "VolGroupData": commands.volgroup.F21_VolGroupData, diff --git a/pykickstart/handlers/rhel7.py b/pykickstart/handlers/rhel7.py index a128182..94609ac 100644 --- a/pykickstart/handlers/rhel7.py +++ b/pykickstart/handlers/rhel7.py @@ -68,7 +68,7 @@ class RHEL7Handler(BaseHandler): "raid": commands.raid.F20_Raid, "realm": commands.realm.F19_Realm, "reboot": commands.reboot.F18_Reboot, - "repo": commands.repo.F15_Repo, + "repo": commands.repo.RHEL7_Repo, "rescue": commands.rescue.F10_Rescue, "rootpw": commands.rootpw.F18_RootPw, "selinux": commands.selinux.FC3_SELinux, @@ -103,7 +103,7 @@ class RHEL7Handler(BaseHandler): "NetworkData": commands.network.RHEL7_NetworkData, "PartData": commands.partition.F18_PartData, "RaidData": commands.raid.F18_RaidData, - "RepoData": commands.repo.F15_RepoData, + "RepoData": commands.repo.RHEL7_RepoData, "SshPwData": commands.sshpw.F13_SshPwData, "UserData": commands.user.F19_UserData, "VolGroupData": commands.volgroup.FC16_VolGroupData, diff --git a/tests/commands/repo.py b/tests/commands/repo.py index e03e7da..b944c54 100644 --- a/tests/commands/repo.py +++ b/tests/commands/repo.py @@ -118,5 +118,15 @@ class F15_TestCase(F14_TestCase): def runTest(self, urlRequired=False): F14_TestCase.runTest(self, urlRequired=urlRequired)
+class F21_TestCase(F15_TestCase): + def runTest(self, urlRequired=False): + F15_TestCase.runTest(self, urlRequired=urlRequired) + #pass + self.assert_parse("repo --name=blah --baseurl=https://www.domain.com --install", + "repo --name="blah" --baseurl=https://www.domain.com --install\n") + #fail + self.assert_parse_error("repo --name=blah --baseurl=https://www.domain.com --install=yeeeaah", KickstartParseError) + + if __name__ == "__main__": unittest.main()
This implements writing selected kickstart repos to the target system. Add --install to the repo commands in the kickstart and the repo will be written to /etc/yum.repos.d/<repoid>.repo --- anaconda.spec.in | 2 +- pyanaconda/kickstart.py | 4 +- pyanaconda/packaging/yumpayload.py | 135 ++++++++++++++++++++++--------------- 3 files changed, 82 insertions(+), 59 deletions(-)
diff --git a/anaconda.spec.in b/anaconda.spec.in index 685886c..a24162b 100644 --- a/anaconda.spec.in +++ b/anaconda.spec.in @@ -21,7 +21,7 @@ Source0: %{name}-%{version}.tar.bz2 # Also update in AM_GNU_GETTEXT_VERSION in configure.ac %define gettextver 0.18.3 %define intltoolver 0.31.2-3 -%define pykickstartver 1.99.57 +%define pykickstartver 1.99.58 %define yumver 3.4.3-91 %define dnfver 0.4.18 %define partedver 1.8.1 diff --git a/pyanaconda/kickstart.py b/pyanaconda/kickstart.py index 09f2a88..bbcc5a9 100644 --- a/pyanaconda/kickstart.py +++ b/pyanaconda/kickstart.py @@ -1426,7 +1426,7 @@ class RaidData(commands.raid.F18_RaidData): parents=request) storage.createDevice(luksdev)
-class RepoData(commands.repo.F15_RepoData): +class RepoData(commands.repo.F21_RepoData): def __init__(self, *args, **kwargs): """ Add enabled kwarg
@@ -1435,7 +1435,7 @@ class RepoData(commands.repo.F15_RepoData): """ self.enabled = kwargs.pop("enabled", True)
- commands.repo.F15_RepoData.__init__(self, *args, **kwargs) + commands.repo.F21_RepoData.__init__(self, *args, **kwargs)
class RootPw(commands.rootpw.F18_RootPw): def execute(self, storage, ksdata, instClass, users): diff --git a/pyanaconda/packaging/yumpayload.py b/pyanaconda/packaging/yumpayload.py index 6dca7f6..a36ef55 100644 --- a/pyanaconda/packaging/yumpayload.py +++ b/pyanaconda/packaging/yumpayload.py @@ -58,6 +58,7 @@ try: # handler setup. We already set one up so we don't need it to run. # yum may give us an API to fiddle this at a later time. yum.logginglevels._added_handlers = True + from yum.Errors import RepoError, RepoMDError, GroupsError except ImportError: log.error("import of yum failed") yum = None @@ -299,6 +300,65 @@ reposdir=%s root = self._yum.conf.installroot self._yum.conf.cachedir = self._yum.conf.cachedir[len(root):]
+ def _writeYumRepo(self, repo, repo_path): + """ Write a repo object to a yum repo.conf file + + :param repo: Yum repository object + :param string repo_path: Path to write the repo to + :raises: PayloadSetupError if the repo doesn't have a url + """ + with open(repo_path, "w") as f: + f.write("[%s]\n" % repo.id) + f.write("name=%s\n" % repo.id) + if self.isRepoEnabled(repo.id): + f.write("enabled=1\n") + else: + f.write("enabled=0\n") + + if repo.mirrorlist: + f.write("mirrorlist=%s\n" % repo.mirrorlist) + elif repo.metalink: + f.write("metalink=%s\n" % repo.metalink) + elif repo.baseurl: + f.write("baseurl=%s\n" % repo.baseurl[0]) + else: + f.close() + os.unlink(repo_path) + raise PayloadSetupError("repo %s has no baseurl, mirrorlist or metalink", repo.id) + + # kickstart repo modifiers + ks_repo = self.getAddOnRepo(repo.id) + if ks_repo: + if ks_repo.noverifyssl: + f.write("sslverify=0\n") + + if ks_repo.proxy: + try: + proxy = ProxyString(ks_repo.proxy) + f.write("proxy=%s\n" % (proxy.noauth_url,)) + if proxy.username: + f.write("proxy_username=%s\n" % (proxy.username,)) + if proxy.password: + f.write("proxy_password=%s\n" % (proxy.password,)) + except ProxyStringError as e: + log.error("Failed to parse proxy for _writeInstallConfig %s: %s", + ks_repo.proxy, e) + + if ks_repo.cost: + f.write("cost=%d\n" % ks_repo.cost) + + if ks_repo.includepkgs: + f.write("includepkgs=%s\n" + % ",".join(ks_repo.includepkgs)) + + if ks_repo.excludepkgs: + f.write("exclude=%s\n" + % ",".join(ks_repo.excludepkgs)) + + if ks_repo.ignoregroups: + f.write("enablegroups=0\n") + + def _writeInstallConfig(self): """ Write out the yum config that will be used to install packages.
@@ -315,53 +375,10 @@ reposdir=%s for repo in self._yum.repos.listEnabled(): cfg_path = "%s/%s.repo" % (self._repos_dir, repo.id) log.debug("writing repository file %s for repository %s", cfg_path, repo.id) - ks_repo = self.getAddOnRepo(repo.id) - with open(cfg_path, "w") as f: - f.write("[%s]\n" % repo.id) - f.write("name=Install - %s\n" % repo.id) - f.write("enabled=1\n") - if repo.mirrorlist: - f.write("mirrorlist=%s" % repo.mirrorlist) - elif repo.metalink: - f.write("metalink=%s" % repo.metalink) - elif repo.baseurl: - f.write("baseurl=%s\n" % repo.baseurl[0]) - else: - log.error("repo %s has no baseurl, mirrorlist or metalink", repo.id) - f.close() - os.unlink(cfg_path) - continue - - # kickstart repo modifiers - if ks_repo: - if ks_repo.noverifyssl: - f.write("sslverify=0\n") - - if ks_repo.proxy: - try: - proxy = ProxyString(ks_repo.proxy) - f.write("proxy=%s\n" % (proxy.noauth_url,)) - if proxy.username: - f.write("proxy_username=%s\n" % (proxy.username,)) - if proxy.password: - f.write("proxy_password=%s\n" % (proxy.password,)) - except ProxyStringError as e: - log.error("Failed to parse proxy for _writeInstallConfig %s: %s", - ks_repo.proxy, e) - - if ks_repo.cost: - f.write("cost=%d\n" % ks_repo.cost) - - if ks_repo.includepkgs: - f.write("includepkgs=%s\n" - % ",".join(ks_repo.includepkgs)) - - if ks_repo.excludepkgs: - f.write("exclude=%s\n" - % ",".join(ks_repo.excludepkgs)) - - if ks_repo.ignoregroups: - f.write("enablegroups=0\n") + try: + self._writeYumRepo(repo, cfg_path) + except PayloadSetupError as e: + log.error(e)
releasever = self._yum.conf.yumvar['releasever'] self._writeYumConfig() @@ -455,8 +472,6 @@ reposdir=%s
def isRepoEnabled(self, repo_id): """ Return True if repo is enabled. """ - from yum.Errors import RepoError - try: return self.getRepo(repo_id).enabled except RepoError: @@ -722,8 +737,6 @@ reposdir=%s
def _getRepoMetadata(self, yumrepo): """ Retrieve repo metadata if we don't already have it. """ - from yum.Errors import RepoError, RepoMDError - # And try to grab its metadata. We do this here so it can be done # on a per-repo basis, so we can then get some finer grained error # handling and recovery. @@ -765,8 +778,6 @@ reposdir=%s
def _addYumRepo(self, name, baseurl, mirrorlist=None, proxyurl=None, **kwargs): """ Add a yum repo to the YumBase instance. """ - from yum.Errors import RepoError - needsAdding = True
# First, delete any pre-existing repo with the same name. @@ -999,7 +1010,6 @@ reposdir=%s @property def _yumGroups(self): """ yum.comps.Comps instance. """ - from yum.Errors import RepoError, GroupsError with _yum_lock: if not self._groups: if not self.needsNetwork or nm_is_connected(): @@ -1109,8 +1119,6 @@ reposdir=%s ### @property def packages(self): - from yum.Errors import RepoError - with _yum_lock: if not self._packages: if self.needsNetwork and not nm_is_connected(): @@ -1489,6 +1497,21 @@ reposdir=%s
self.writeMultiLibConfig()
+ # Write selected kickstart repos to target system + for ks_repo in (ks for ks in (self.getAddOnRepo(r) for r in self.addOns) if ks.install): + try: + repo = self.getRepo(ks_repo.name) + if not repo: + continue + except RepoError: + continue + repo_path = iutil.getSysroot() + "/etc/yum.repos.d/%s.repo" % repo.id + try: + log.info("Writing %s.repo to target system.", repo.id) + self._writeYumRepo(repo, repo_path) + except PayloadSetupError as e: + log.error(e) + super(YumPayload, self).postInstall()
# Make sure yum is really done and gone and lets go of the yum.log
On Thu, 2014-07-24 at 18:34 -0700, Brian C. Lane wrote:
This implements writing selected kickstart repos to the target system. Add --install to the repo commands in the kickstart and the repo will be written to /etc/yum.repos.d/<repoid>.repo
anaconda.spec.in | 2 +- pyanaconda/kickstart.py | 4 +- pyanaconda/packaging/yumpayload.py | 135 ++++++++++++++++++++++--------------- 3 files changed, 82 insertions(+), 59 deletions(-)
diff --git a/anaconda.spec.in b/anaconda.spec.in index 685886c..a24162b 100644 --- a/anaconda.spec.in +++ b/anaconda.spec.in @@ -21,7 +21,7 @@ Source0: %{name}-%{version}.tar.bz2 # Also update in AM_GNU_GETTEXT_VERSION in configure.ac %define gettextver 0.18.3 %define intltoolver 0.31.2-3 -%define pykickstartver 1.99.57 +%define pykickstartver 1.99.58 %define yumver 3.4.3-91 %define dnfver 0.4.18 %define partedver 1.8.1 diff --git a/pyanaconda/kickstart.py b/pyanaconda/kickstart.py index 09f2a88..bbcc5a9 100644 --- a/pyanaconda/kickstart.py +++ b/pyanaconda/kickstart.py @@ -1426,7 +1426,7 @@ class RaidData(commands.raid.F18_RaidData): parents=request) storage.createDevice(luksdev)
-class RepoData(commands.repo.F15_RepoData): +class RepoData(commands.repo.F21_RepoData): def __init__(self, *args, **kwargs): """ Add enabled kwarg
@@ -1435,7 +1435,7 @@ class RepoData(commands.repo.F15_RepoData): """ self.enabled = kwargs.pop("enabled", True)
commands.repo.F15_RepoData.__init__(self, *args, **kwargs)
commands.repo.F21_RepoData.__init__(self, *args, **kwargs)class RootPw(commands.rootpw.F18_RootPw): def execute(self, storage, ksdata, instClass, users): diff --git a/pyanaconda/packaging/yumpayload.py b/pyanaconda/packaging/yumpayload.py index 6dca7f6..a36ef55 100644 --- a/pyanaconda/packaging/yumpayload.py +++ b/pyanaconda/packaging/yumpayload.py @@ -58,6 +58,7 @@ try: # handler setup. We already set one up so we don't need it to run. # yum may give us an API to fiddle this at a later time. yum.logginglevels._added_handlers = True
- from yum.Errors import RepoError, RepoMDError, GroupsError
except ImportError: log.error("import of yum failed") yum = None @@ -299,6 +300,65 @@ reposdir=%s root = self._yum.conf.installroot self._yum.conf.cachedir = self._yum.conf.cachedir[len(root):]
- def _writeYumRepo(self, repo, repo_path):
""" Write a repo object to a yum repo.conf file:param repo: Yum repository object:param string repo_path: Path to write the repo to:raises: PayloadSetupError if the repo doesn't have a url"""with open(repo_path, "w") as f:f.write("[%s]\n" % repo.id)f.write("name=%s\n" % repo.id)if self.isRepoEnabled(repo.id):f.write("enabled=1\n")else:f.write("enabled=0\n")if repo.mirrorlist:f.write("mirrorlist=%s\n" % repo.mirrorlist)elif repo.metalink:f.write("metalink=%s\n" % repo.metalink)elif repo.baseurl:f.write("baseurl=%s\n" % repo.baseurl[0])else:f.close()os.unlink(repo_path)raise PayloadSetupError("repo %s has no baseurl, mirrorlist or metalink", repo.id)
I'm not sure about that, but doesn't this path result in the file being closed twice? Is it just silently ignored or does it cause an error?
# kickstart repo modifiersks_repo = self.getAddOnRepo(repo.id)if ks_repo:if ks_repo.noverifyssl:f.write("sslverify=0\n")if ks_repo.proxy:try:proxy = ProxyString(ks_repo.proxy)f.write("proxy=%s\n" % (proxy.noauth_url,))if proxy.username:f.write("proxy_username=%s\n" % (proxy.username,))if proxy.password:f.write("proxy_password=%s\n" % (proxy.password,))except ProxyStringError as e:log.error("Failed to parse proxy for _writeInstallConfig %s: %s",ks_repo.proxy, e)if ks_repo.cost:f.write("cost=%d\n" % ks_repo.cost)if ks_repo.includepkgs:f.write("includepkgs=%s\n"% ",".join(ks_repo.includepkgs))if ks_repo.excludepkgs:f.write("exclude=%s\n"% ",".join(ks_repo.excludepkgs))if ks_repo.ignoregroups:f.write("enablegroups=0\n")
This long block could be indented less if the condition is negated and followed with return.
- def _writeInstallConfig(self): """ Write out the yum config that will be used to install packages.
@@ -315,53 +375,10 @@ reposdir=%s for repo in self._yum.repos.listEnabled(): cfg_path = "%s/%s.repo" % (self._repos_dir, repo.id) log.debug("writing repository file %s for repository %s", cfg_path, repo.id)
ks_repo = self.getAddOnRepo(repo.id)with open(cfg_path, "w") as f:f.write("[%s]\n" % repo.id)f.write("name=Install - %s\n" % repo.id)f.write("enabled=1\n")if repo.mirrorlist:f.write("mirrorlist=%s" % repo.mirrorlist)elif repo.metalink:f.write("metalink=%s" % repo.metalink)elif repo.baseurl:f.write("baseurl=%s\n" % repo.baseurl[0])else:log.error("repo %s has no baseurl, mirrorlist or metalink", repo.id)f.close()os.unlink(cfg_path)continue# kickstart repo modifiersif ks_repo:if ks_repo.noverifyssl:f.write("sslverify=0\n")if ks_repo.proxy:try:proxy = ProxyString(ks_repo.proxy)f.write("proxy=%s\n" % (proxy.noauth_url,))if proxy.username:f.write("proxy_username=%s\n" % (proxy.username,))if proxy.password:f.write("proxy_password=%s\n" % (proxy.password,))except ProxyStringError as e:log.error("Failed to parse proxy for _writeInstallConfig %s: %s",ks_repo.proxy, e)if ks_repo.cost:f.write("cost=%d\n" % ks_repo.cost)if ks_repo.includepkgs:f.write("includepkgs=%s\n"% ",".join(ks_repo.includepkgs))if ks_repo.excludepkgs:f.write("exclude=%s\n"% ",".join(ks_repo.excludepkgs))if ks_repo.ignoregroups:f.write("enablegroups=0\n")
try:self._writeYumRepo(repo, cfg_path)except PayloadSetupError as e:log.error(e) releasever = self._yum.conf.yumvar['releasever'] self._writeYumConfig()@@ -455,8 +472,6 @@ reposdir=%s
def isRepoEnabled(self, repo_id): """ Return True if repo is enabled. """
from yum.Errors import RepoErrortry: return self.getRepo(repo_id).enabled except RepoError:@@ -722,8 +737,6 @@ reposdir=%s
def _getRepoMetadata(self, yumrepo): """ Retrieve repo metadata if we don't already have it. """
from yum.Errors import RepoError, RepoMDError# And try to grab its metadata. We do this here so it can be done # on a per-repo basis, so we can then get some finer grained error # handling and recovery.@@ -765,8 +778,6 @@ reposdir=%s
def _addYumRepo(self, name, baseurl, mirrorlist=None, proxyurl=None, **kwargs): """ Add a yum repo to the YumBase instance. """
from yum.Errors import RepoErrorneedsAdding = True # First, delete any pre-existing repo with the same name.@@ -999,7 +1010,6 @@ reposdir=%s @property def _yumGroups(self): """ yum.comps.Comps instance. """
from yum.Errors import RepoError, GroupsError with _yum_lock: if not self._groups: if not self.needsNetwork or nm_is_connected():@@ -1109,8 +1119,6 @@ reposdir=%s ### @property def packages(self):
from yum.Errors import RepoErrorwith _yum_lock: if not self._packages: if self.needsNetwork and not nm_is_connected():@@ -1489,6 +1497,21 @@ reposdir=%s
self.writeMultiLibConfig()
# Write selected kickstart repos to target systemfor ks_repo in (ks for ks in (self.getAddOnRepo(r) for r in self.addOns) if ks.install):try:repo = self.getRepo(ks_repo.name)if not repo:continueexcept RepoError:continuerepo_path = iutil.getSysroot() + "/etc/yum.repos.d/%s.repo" % repo.id
The "/etc/yum.repos.d" path should be a constant defined at the top of the module. Or maybe the whole template.
On Fri, Jul 25, 2014 at 08:24:43AM +0200, Vratislav Podzimek wrote:
else:f.close()os.unlink(repo_path)raise PayloadSetupError("repo %s has no baseurl, mirrorlist or metalink", repo.id)I'm not sure about that, but doesn't this path result in the file being closed twice? Is it just silently ignored or does it cause an error?
It works fine, it doesn't care if the file has been previously closed when you exit the context.
if ks_repo.ignoregroups:f.write("enablegroups=0\n")This long block could be indented less if the condition is negated and followed with return.
Good point, I'm moving it anyway.
except RepoError:continuerepo_path = iutil.getSysroot() + "/etc/yum.repos.d/%s.repo" % repo.idThe "/etc/yum.repos.d" path should be a constant defined at the top of the module. Or maybe the whole template.
I think just the path, since that is the part you may want to change in the future. Users of the path add to the end of it.
_writeDNFRepo is mostly a copy of _writeYumRepo because there are slight differences in the options supported, and because it may diverge further in the futute. --- pyanaconda/packaging/dnfpayload.py | 68 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+)
diff --git a/pyanaconda/packaging/dnfpayload.py b/pyanaconda/packaging/dnfpayload.py index 64f7433..07d1bf0 100644 --- a/pyanaconda/packaging/dnfpayload.py +++ b/pyanaconda/packaging/dnfpayload.py @@ -19,6 +19,7 @@ # # Red Hat Author(s): Ales Kozumplik akozumpl@redhat.com # +import os
from blivet.size import Size from pyanaconda.flags import flags @@ -39,6 +40,7 @@ import pyanaconda.localization import pyanaconda.packaging as packaging import sys import time +from pyanaconda.iutil import ProxyString, ProxyStringError
log = logging.getLogger("packaging")
@@ -537,6 +539,10 @@ class DNFPayload(packaging.PackagePayload): process.join() self._base.close()
+ def getRepo(self, repo_id): + """ Return the yum repo object. """ + return self._base.repos[repo_id] + def isRepoEnabled(self, repo_id): try: return self._base.repos[repo_id].enabled @@ -629,3 +635,65 @@ class DNFPayload(packaging.PackagePayload): self.disableRepo(id_) elif constants.isFinal and 'rawhide' in id_: self.disableRepo(id_) + + def _writeDNFRepo(self, repo, repo_path): + """ Write a repo object to a DNF repo.conf file + + :param repo: DNF repository object + :param string repo_path: Path to write the repo to + :raises: PayloadSetupError if the repo doesn't have a url + """ + with open(repo_path, "w") as f: + f.write("[%s]\n" % repo.id) + f.write("name=%s\n" % repo.id) + if self.isRepoEnabled(repo.id): + f.write("enabled=1\n") + else: + f.write("enabled=0\n") + + if repo.mirrorlist: + f.write("mirrorlist=%s\n" % repo.mirrorlist) + elif repo.metalink: + f.write("metalink=%s\n" % repo.metalink) + elif repo.baseurl: + f.write("baseurl=%s\n" % repo.baseurl[0]) + else: + f.close() + os.unlink(repo_path) + raise packaging.PayloadSetupError("repo %s has no baseurl, mirrorlist or metalink", repo.id) + + # kickstart repo modifiers + ks_repo = self.getAddOnRepo(repo.id) + if ks_repo: + if ks_repo.noverifyssl: + f.write("sslverify=0\n") + + if ks_repo.proxy: + try: + proxy = ProxyString(ks_repo.proxy) + f.write("proxy=%s\n" % proxy.url) + except ProxyStringError as e: + log.error("Failed to parse proxy for _writeInstallConfig %s: %s", + ks_repo.proxy, e) + + if ks_repo.cost: + f.write("cost=%d\n" % ks_repo.cost) + + def postInstall(self): + """ Perform post-installation tasks. """ + # Write selected kickstart repos to target system + for ks_repo in (ks for ks in (self.getAddOnRepo(r) for r in self.addOns) if ks.install): + try: + repo = self.getRepo(ks_repo.name) + if not repo: + continue + except (dnf.exceptions.RepoError, KeyError): + continue + repo_path = pyanaconda.iutil.getSysroot() + "/etc/yum.repos.d/%s.repo" % repo.id + try: + log.info("Writing %s.repo to target system.", repo.id) + self._writeDNFRepo(repo, repo_path) + except packaging.PayloadSetupError as e: + log.error(e) + + super(DNFPayload, self).postInstall()
Other than those rather neatpicking questions and comments these all look good to me.
----- Original Message -----
From: "Brian C. Lane" bcl@redhat.com To: anaconda-patches@lists.fedorahosted.org Sent: Friday, July 25, 2014 3:34:13 AM Subject: [anaconda 3/3] Add repo --install support to DNF (#1119867)
_writeDNFRepo is mostly a copy of _writeYumRepo because there are slight differences in the options supported, and because it may diverge further in the futute.
^^^^^^ future ?
pyanaconda/packaging/dnfpayload.py | 68 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+)
diff --git a/pyanaconda/packaging/dnfpayload.py b/pyanaconda/packaging/dnfpayload.py index 64f7433..07d1bf0 100644 --- a/pyanaconda/packaging/dnfpayload.py +++ b/pyanaconda/packaging/dnfpayload.py @@ -19,6 +19,7 @@ # # Red Hat Author(s): Ales Kozumplik akozumpl@redhat.com # +import os
from blivet.size import Size from pyanaconda.flags import flags @@ -39,6 +40,7 @@ import pyanaconda.localization import pyanaconda.packaging as packaging import sys import time +from pyanaconda.iutil import ProxyString, ProxyStringError
log = logging.getLogger("packaging")
@@ -537,6 +539,10 @@ class DNFPayload(packaging.PackagePayload): process.join() self._base.close()
- def getRepo(self, repo_id):
""" Return the yum repo object. """return self._base.repos[repo_id]- def isRepoEnabled(self, repo_id): try: return self._base.repos[repo_id].enabled
@@ -629,3 +635,65 @@ class DNFPayload(packaging.PackagePayload): self.disableRepo(id_) elif constants.isFinal and 'rawhide' in id_: self.disableRepo(id_)
- def _writeDNFRepo(self, repo, repo_path):
""" Write a repo object to a DNF repo.conf file:param repo: DNF repository object:param string repo_path: Path to write the repo to:raises: PayloadSetupError if the repo doesn't have a url"""with open(repo_path, "w") as f:f.write("[%s]\n" % repo.id)f.write("name=%s\n" % repo.id)if self.isRepoEnabled(repo.id):f.write("enabled=1\n")else:f.write("enabled=0\n")if repo.mirrorlist:f.write("mirrorlist=%s\n" % repo.mirrorlist)elif repo.metalink:f.write("metalink=%s\n" % repo.metalink)elif repo.baseurl:f.write("baseurl=%s\n" % repo.baseurl[0])else:f.close()os.unlink(repo_path)raise packaging.PayloadSetupError("repo %s has no baseurl,mirrorlist or metalink", repo.id)
# kickstart repo modifiersks_repo = self.getAddOnRepo(repo.id)if ks_repo:if ks_repo.noverifyssl:f.write("sslverify=0\n")if ks_repo.proxy:try:proxy = ProxyString(ks_repo.proxy)f.write("proxy=%s\n" % proxy.url)except ProxyStringError as e:log.error("Failed to parse proxy for_writeInstallConfig %s: %s",
ks_repo.proxy, e)if ks_repo.cost:f.write("cost=%d\n" % ks_repo.cost)- def postInstall(self):
""" Perform post-installation tasks. """# Write selected kickstart repos to target systemfor ks_repo in (ks for ks in (self.getAddOnRepo(r) for r inself.addOns) if ks.install):
try:repo = self.getRepo(ks_repo.name)if not repo:continueexcept (dnf.exceptions.RepoError, KeyError):continuerepo_path = pyanaconda.iutil.getSysroot() +"/etc/yum.repos.d/%s.repo" % repo.id
try:log.info("Writing %s.repo to target system.", repo.id)self._writeDNFRepo(repo, repo_path)except packaging.PayloadSetupError as e:log.error(e)super(DNFPayload, self).postInstall()-- 1.9.3
anaconda-patches mailing list anaconda-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/anaconda-patches
On Mon, Jul 28, 2014 at 04:12:14AM -0400, Martin Kolman wrote:
----- Original Message -----
From: "Brian C. Lane" bcl@redhat.com To: anaconda-patches@lists.fedorahosted.org Sent: Friday, July 25, 2014 3:34:13 AM Subject: [anaconda 3/3] Add repo --install support to DNF (#1119867)
_writeDNFRepo is mostly a copy of _writeYumRepo because there are slight differences in the options supported, and because it may diverge further in the futute.
^^^^^^ future ?
Ha! Thanks for catching that.
On Thu, 2014-07-24 at 18:34 -0700, Brian C. Lane wrote:
pykickstart/commands/repo.py | 29 +++++++++++++++++++++++++++++ pykickstart/handlers/f21.py | 4 ++-- pykickstart/handlers/rhel7.py | 4 ++-- tests/commands/repo.py | 10 ++++++++++ 4 files changed, 43 insertions(+), 4 deletions(-)
diff --git a/pykickstart/commands/repo.py b/pykickstart/commands/repo.py index 6e0da76..3ee114c 100644 --- a/pykickstart/commands/repo.py +++ b/pykickstart/commands/repo.py @@ -132,6 +132,24 @@ RHEL6_RepoData = F14_RepoData
F15_RepoData = F14_RepoData
+class F21_RepoData(F14_RepoData):
- removedKeywords = F14_RepoData.removedKeywords
- removedAttrs = F14_RepoData.removedAttrs
- def __init__(self, *args, **kwargs):
F14_RepoData.__init__(self, *args, **kwargs)self.install = kwargs.get("install", False)- def _getArgsAsStr(self):
retval = F14_RepoData._getArgsAsStr(self)if self.install:retval += " --install"return retval+RHEL7_RepoData = F21_RepoData
Do I understand it correctly that these patches are for both master and rhel7-branch then?
On Fri, Jul 25, 2014 at 08:18:19AM +0200, Vratislav Podzimek wrote:
On Thu, 2014-07-24 at 18:34 -0700, Brian C. Lane wrote:
pykickstart/commands/repo.py | 29 +++++++++++++++++++++++++++++ pykickstart/handlers/f21.py | 4 ++-- pykickstart/handlers/rhel7.py | 4 ++-- tests/commands/repo.py | 10 ++++++++++ 4 files changed, 43 insertions(+), 4 deletions(-)
diff --git a/pykickstart/commands/repo.py b/pykickstart/commands/repo.py index 6e0da76..3ee114c 100644 --- a/pykickstart/commands/repo.py +++ b/pykickstart/commands/repo.py @@ -132,6 +132,24 @@ RHEL6_RepoData = F14_RepoData
F15_RepoData = F14_RepoData
+class F21_RepoData(F14_RepoData):
- removedKeywords = F14_RepoData.removedKeywords
- removedAttrs = F14_RepoData.removedAttrs
- def __init__(self, *args, **kwargs):
F14_RepoData.__init__(self, *args, **kwargs)self.install = kwargs.get("install", False)- def _getArgsAsStr(self):
retval = F14_RepoData._getArgsAsStr(self)if self.install:retval += " --install"return retval+RHEL7_RepoData = F21_RepoData
Do I understand it correctly that these patches are for both master and rhel7-branch then?
Right, I see I forgot to add branch details to my subject. I'm planning on waiting until this goes into rhel7-branch, then I'll add it to master. f21 is debatable and depends on how strict we want to be at that time.
pykickstart/commands/repo.py | 29 +++++++++++++++++++++++++++++ pykickstart/handlers/f21.py | 4 ++-- pykickstart/handlers/rhel7.py | 4 ++-- tests/commands/repo.py | 10 ++++++++++ 4 files changed, 43 insertions(+), 4 deletions(-)
The pykickstart portion looks fine to me.
- Chris
anaconda-patches@lists.fedorahosted.org