From db125435953242059c5d3674fc87527108428329 Mon Sep 17 00:00:00 2001 From: Radek Vykydal Date: Mon, 28 Aug 2017 13:51:15 +0200 Subject: [PATCH] Add url --metalink support (#1464843) --- docs/kickstart-docs.rst | 7 ++++- pykickstart/commands/url.py | 58 ++++++++++++++++++++++++++++++++++--- pykickstart/handlers/f27.py | 2 +- tests/commands/url.py | 23 +++++++++++++++ 4 files changed, 84 insertions(+), 6 deletions(-) diff --git a/docs/kickstart-docs.rst b/docs/kickstart-docs.rst index 2e57f39c..098ed3af 100644 --- a/docs/kickstart-docs.rst +++ b/docs/kickstart-docs.rst @@ -776,7 +776,7 @@ nfs url ~~~ -``url --url=|--mirrorlist= [--proxy=] [--noverifyssl]`` +``url --url=|--mirrorlist=|--metalink= [--proxy=] [--noverifyssl]`` Install from an installation tree on a remote server via FTP or HTTP. @@ -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 diff --git a/pykickstart/commands/url.py b/pykickstart/commands/url.py index a852f5d3..105b153f 100644 --- a/pykickstart/commands/url.py +++ b/pykickstart/commands/url.py @@ -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): @@ -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 diff --git a/pykickstart/handlers/f27.py b/pykickstart/handlers/f27.py index fb24bd55..ac1be7ca 100644 --- a/pykickstart/handlers/f27.py +++ b/pykickstart/handlers/f27.py @@ -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, diff --git a/tests/commands/url.py b/tests/commands/url.py index f0463431..4eeb84cf 100644 --- a/tests/commands/url.py +++ b/tests/commands/url.py @@ -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()