Skip to content

Commit

Permalink
Add repo --metalink support (#1464843)
Browse files Browse the repository at this point in the history
  • Loading branch information
rvykydal committed Sep 1, 2017
1 parent 09682a8 commit a549f2f
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 24 deletions.
37 changes: 23 additions & 14 deletions docs/kickstart-docs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1757,7 +1757,7 @@ automatically. Providing a baseurl or mirrorlist URL will result in
anaconda attempting to add another repo by the same name, which will
cause a conflicting repo error.

``repo --name=<name> [--baseurl=<url>|--mirrorlist=<url>] [options]``
``repo --name=<name> [--baseurl=<url>|--mirrorlist=<url>|--metalink=<url>] [options]``

``--name=``

Expand All @@ -1770,22 +1770,31 @@ cause a conflicting repo error.

``--baseurl=``

The URL for the repository. The variables that may be used in yum
repo config files are not supported here. You may use one of either
this option or ``--mirrorlist``, not both. If an NFS repository is
specified, it should be of the form ``nfs://host:/path/to/repo``.
Note that there is a colon after the host--Anaconda passes
everything after "nfs://\ " directly to the mount command instead of
parsing URLs according to RFC 2224. Variable substitution is done
for $releasever and $basearch in the url (added in F19).
The URL for the repository. The variables that may be used in yum repo
config files are not supported here. You may use only one of the
``--baseurl``, ``--mirrorlist``, or ``--metalink`` options. If an NFS
repository is specified, it should be of the form
``nfs://host:/path/to/repo``. Note that there is a colon after the
host--Anaconda passes everything after "nfs://\ " directly to the mount
command instead of parsing URLs according to RFC 2224. Variable
substitution is done for $releasever and $basearch in the url (added in
F19).

``--mirrorlist=``

The URL pointing at a list of mirrors for the repository. The
variables that may be used in yum repo config files are not
supported here. You may use one of either this option or
``--baseurl``, not both. Variable substitution is done for
$releasever and $basearch in the url (added in F19).
The URL pointing at a list of mirrors for the repository. The variables
that may be used in yum repo config files are not supported here. You may
use only one of the ``--baseurl``, ``--mirrorlist``, or ``--metalink``
options. Variable substitution is done for $releasever and $basearch in the
url (added in F19).

``--metalink=``

The URL pointing at a metalink for the repository. The
variables that may be used in yum repo config files are not supported here.
You may use only one of the ``--baseurl``, ``--mirrorlist``, or
``--metalink`` options. Variable substitution is done for $releasever and
$basearch in the url (added in F27).

``--cost=``

Expand Down
49 changes: 41 additions & 8 deletions pykickstart/commands/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Any Red Hat
# trademarks that are incorporated in the source code or documentation are not
# subject to the GNU General Public License and may only be used or replicated
# with the express permission of Red Hat, Inc.
# with the express permission of Red Hat, Inc.
#
from pykickstart.base import BaseData, KickstartCommand
from pykickstart.errors import KickstartError, KickstartValueError, formatErrorMsg
Expand Down Expand Up @@ -147,6 +147,22 @@ def _getArgsAsStr(self):

return retval

class F27_RepoData(F21_RepoData):
removedKeywords = F21_RepoData.removedKeywords
removedAttrs = F21_RepoData.removedAttrs

def __init__(self, *args, **kwargs):
F21_RepoData.__init__(self, *args, **kwargs)
self.metalink = kwargs.get("metalink", False)

def _getArgsAsStr(self):
retval = F21_RepoData._getArgsAsStr(self)

if self.metalink:
retval += " --metalink=%s" % self.metalink

return retval

RHEL7_RepoData = F21_RepoData

class FC6_Repo(KickstartCommand):
Expand All @@ -160,6 +176,8 @@ def __init__(self, writePriority=0, *args, **kwargs):
self.op = self._getParser()

self.repoList = kwargs.get("repoList", [])
self.exclusive_required_options = [("mirrorlist", "--mirrorlist"),
("baseurl", "--baseurl")]

def __str__(self):
retval = ""
Expand All @@ -182,13 +200,15 @@ def parse(self, args):
mapping = {"command": "repo", "options": extra}
raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("Unexpected arguments to %(command)s command: %(options)s") % mapping))

# This is lame, but I can't think of a better way to make sure only
# one of these two is specified.
if opts.baseurl and opts.mirrorlist:
raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("Only one of --baseurl and --mirrorlist may be specified for repo command.")))

if self.urlRequired and not opts.baseurl and not opts.mirrorlist:
raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("One of --baseurl or --mirrorlist must be specified for repo command.")))
# Check that just one of exclusive required options is specified
used_options = [opt for attr, opt in self.exclusive_required_options
if getattr(opts, attr, None)]
if self.urlRequired and not used_options:
mapping = {"options_list": ", ".join((opt for attr, opt in self.exclusive_required_options))}
raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("One of -%(options_list)s options must be specified for repo command.") % mapping))
if len(used_options) > 1:
mapping = {"options_list": ", ".join((opt for opt in used_options))}
raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("Only one of %(options_list)s options may be specified for repo command.") % mapping))

rd = self.handler.RepoData()
self.set_to_obj(self.op, opts, rd)
Expand Down Expand Up @@ -279,4 +299,17 @@ def _getParser(self):
op.add_option("--install", action="store_true", default=False)
return op

class F27_Repo(F21_Repo):
removedKeywords = F21_Repo.removedKeywords
removedAttrs = F21_Repo.removedAttrs

def __init__(self, *args, **kwargs):
F21_Repo.__init__(self, *args, **kwargs)
self.exclusive_required_options.append(("metalink", "--metalink"))

def _getParser(self):
op = F21_Repo._getParser(self)
op.add_option("--metalink")
return op

RHEL7_Repo = F21_Repo
4 changes: 2 additions & 2 deletions pykickstart/handlers/f27.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class F27Handler(BaseHandler):
"raid": commands.raid.F25_Raid,
"realm": commands.realm.F19_Realm,
"reboot": commands.reboot.F23_Reboot,
"repo": commands.repo.F21_Repo,
"repo": commands.repo.F27_Repo,
"reqpart": commands.reqpart.F23_ReqPart,
"rescue": commands.rescue.F10_Rescue,
"rootpw": commands.rootpw.F18_RootPw,
Expand Down Expand Up @@ -106,7 +106,7 @@ class F27Handler(BaseHandler):
"NetworkData": commands.network.F25_NetworkData,
"PartData": commands.partition.F23_PartData,
"RaidData": commands.raid.F25_RaidData,
"RepoData": commands.repo.F21_RepoData,
"RepoData": commands.repo.F27_RepoData,
"SnapshotData": commands.snapshot.F26_SnapshotData,
"SshPwData": commands.sshpw.F24_SshPwData,
"SshKeyData": commands.sshkey.F22_SshKeyData,
Expand Down
12 changes: 12 additions & 0 deletions tests/commands/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,17 @@ def runTest(self, urlRequired=False):
self.assert_parse_error("repo --name=blah --baseurl=https://www.domain.com --mirrorlist=https://www.domain.com/mirror",
KickstartValueError)

class F27_TestCase(F21_TestCase):
def runTest(self, urlRequired=False):
F21_TestCase.runTest(self, urlRequired=urlRequired)

self.assert_parse("repo --name=blah --metalink=https://www.domain.com/metalink")

# only one of --baseurl --mirrorlist --metalink may be specified
self.assert_parse_error("repo --name=blah --metalink=https://www.domain.com/metalink --mirrorlist=https://www.domain.com/mirror",
KickstartValueError)
self.assert_parse_error("repo --name=blah --baseurl=https://www.domain.com --metalink=https://www.domain.com/metalink",
KickstartValueError)

if __name__ == "__main__":
unittest.main()

0 comments on commit a549f2f

Please sign in to comment.