Skip to content

Commit

Permalink
Add url --metalink support (#1464843)
Browse files Browse the repository at this point in the history
  • Loading branch information
rvykydal committed Sep 1, 2017
1 parent a549f2f commit db12543
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 6 deletions.
7 changes: 6 additions & 1 deletion docs/kickstart-docs.rst
Expand Up @@ -776,7 +776,7 @@ nfs
url
~~~

``url --url=<url>|--mirrorlist=<url> [--proxy=<proxy url>] [--noverifyssl]``
``url --url=<url>|--mirrorlist=<url>|--metalink=<url> [--proxy=<proxy url>] [--noverifyssl]``

Install from an installation tree on a remote server via FTP or
HTTP.
Expand All @@ -791,6 +791,11 @@ url
The mirror URL to install from. Variable substitution is done
for $releasever and $basearch in the url (added in F19).

``--metalink=``

The metalink URL to install from. Variable substitution is done
for $releasever and $basearch in the url (added in F27).

``--proxy=[protocol://][username[:password]@]host[:port]``

Specify an HTTP/HTTPS/FTP proxy to use while performing the
Expand Down
58 changes: 54 additions & 4 deletions pykickstart/commands/url.py
Expand Up @@ -126,6 +126,8 @@ class F18_Url(F14_Url):
def __init__(self, *args, **kwargs):
F14_Url.__init__(self, *args, **kwargs)
self.mirrorlist = kwargs.get("mirrorlist", None)
self.exclusive_required_options = [("mirrorlist", "--mirrorlist"),
("url", "--url")]

def __eq__(self, other):
if not F14_Url.__eq__(self, other):
Expand Down Expand Up @@ -165,10 +167,58 @@ def _getParser(self):
def parse(self, args):
retval = F14_Url.parse(self, args)

if self.url and self.mirrorlist:
raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("Only one of --url and --mirrorlist may be specified for url command.")))
(opts, _extra) = self.op.parse_args(args=args, lineno=self.lineno)

if not self.url and not self.mirrorlist:
raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("One of --url or --mirrorlist must be specified for url 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 len(used_options) == 0:
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 url 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 url command.") % mapping))

return retval

class F27_Url(F18_Url):
removedKeywords = F18_Url.removedKeywords
removedAttrs = F18_Url.removedAttrs

def __init__(self, *args, **kwargs):
F18_Url.__init__(self, *args, **kwargs)
self.metalink = kwargs.get("metalink", None)
self.exclusive_required_options.append(("metalink", "--metalink"))

def __eq__(self, other):
if not F18_Url.__eq__(self, other):
return False

return self.metalink == other.metalink

def __str__(self):
retval = KickstartCommand.__str__(self)
if not self.seen:
return retval

retval += "# Use network installation\n"

if self.url:
retval += "url --url=\"%s\"" % self.url
elif self.mirrorlist:
retval += "url --mirrorlist=\"%s\"" % self.mirrorlist
elif self.metalink:
retval += "url --metalink=\"%s\"" % self.metalink

if self.proxy:
retval += " --proxy=\"%s\"" % self.proxy

if self.noverifyssl:
retval += " --noverifyssl"

return retval + "\n"

def _getParser(self):
op = F18_Url._getParser(self)
op.add_option("--metalink", dest="metalink")
return op
2 changes: 1 addition & 1 deletion pykickstart/handlers/f27.py
Expand Up @@ -84,7 +84,7 @@ class F27Handler(BaseHandler):
"timezone": commands.timezone.F25_Timezone,
"updates": commands.updates.F7_Updates,
"upgrade": commands.upgrade.F20_Upgrade,
"url": commands.url.F18_Url,
"url": commands.url.F27_Url,
"user": commands.user.F19_User,
"vnc": commands.vnc.F9_Vnc,
"volgroup": commands.volgroup.F21_VolGroup,
Expand Down
23 changes: 23 additions & 0 deletions tests/commands/url.py
Expand Up @@ -115,5 +115,28 @@ def runTest(self):
cmd.mirrorlist = None
self.assertEqual(cmd.__str__(), "# Use network installation\n\n")

class F27_TestCase(F18_TestCase):
def runTest(self):
# run F18 test case.
F18_TestCase.runTest(self)

# pass
self.assert_parse("url --metalink=http://www.wherever.com/metalink",
"url --metalink=\"http://www.wherever.com/metalink\"\n")

self.assertTrue(self.assert_parse("url --metalink=https://domain.com") == \
self.assert_parse("url --metalink=https://domain.com"))
self.assertFalse(self.assert_parse("url --url=https://domain.com") == \
self.assert_parse("url --metalink=https://domain.com"))

# fail
self.assert_parse_error("url --metalink", KickstartParseError)

# only one of --url, --mirrorlist, or --metalink may be specified
self.assert_parse_error("url --url=www.wherever.com --metalink=www.wherever.com",
KickstartValueError)
self.assert_parse_error("url --mirrorlist=www.wherever.com --metalink=www.wherever.com",
KickstartValueError)

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

0 comments on commit db12543

Please sign in to comment.