We need a place to store NTP servers specified in the UI and it has to be in ksdata, so let's allow users to specify them in kickstarts as well. Since NTP is the default behaviour in the UI installation it should also be the default for the kickstart installation. Thus there should be --nontp option rather then --ntp option. <not-in-the-commit-message> Because the __str__ method of the FC6_Timezone class is hard to use in the new class, I've written the new __str__ method without using it. However the new one is ready for additional changes in the future. Same goes for the FC6_TestCase which ran FC3_TestCase that included the assertion of parsing "timezone Eastern" as "timezone Eastern\n" (with double space). Since this is now fixed in the new __str__ method, the old test case is failing and thus can no longer be run. </not-in-the-commit-message> --- pykickstart/commands/timezone.py | 53 ++++++++++++++++++++++++++++++++++++++ pykickstart/handlers/control.py | 2 +- tests/commands/timezone.py | 25 ++++++++++++++++++ 3 files changed, 79 insertions(+), 1 deletions(-) diff --git a/pykickstart/commands/timezone.py b/pykickstart/commands/timezone.py index f5441de..8cd5527 100644 --- a/pykickstart/commands/timezone.py +++ b/pykickstart/commands/timezone.py @@ -84,3 +84,56 @@ class FC6_Timezone(FC3_Timezone): op = FC3_Timezone._getParser(self) op.add_option("--utc", "--isUtc", dest="isUtc", action="store_true", default=False) return op + +class F18_Timezone(FC6_Timezone): + def __init__(self, writePriority=0, *args, **kwargs): + FC6_Timezone.__init__(self, writePriority, *args, **kwargs) + self.op = self._getParser() + self.nontp = kwargs.get("nontp", False) + self.ntpservers = kwargs.get("ntpservers", set()) + + def __str__(self): + retval = KickstartCommand.__str__(self) + + retval += "# System timezone\n" + retval += "timezone " + self._getArgsAsStr() + "\n" + + return retval + + def _getArgsAsStr(self): + retval = self.timezone + + if self.isUtc: + retval += " --isUtc" + + if self.nontp: + retval += " --nontp" + + if self.ntpservers: + retval += " --ntpservers=" + ",".join(self.ntpservers) + + return retval + + def _getParser(self): + def servers_cb(option, opt_str, value, parser): + for server in value.split(","): + if server: + parser.values.ensure_value(option.dest, set()).add(server) + + + op = FC6_Timezone._getParser(self) + op.add_option("--nontp", dest="nontp", action="store_true", default=False) + op.add_option("--ntpservers", dest="ntpservers", action="callback", + callback=servers_cb, nargs=1, type="string") + + return op + + def parse(self, args): + FC6_Timezone.parse(self, args) + + if self.ntpservers and self.nontp: + msg = formatErrorMsg(self.lineno, msg=_("Options --nontp and "\ + "--ntpservers are mutually exclusive")) + raise KickstartParseError(msg) + + return self diff --git a/pykickstart/handlers/control.py b/pykickstart/handlers/control.py index 6fe7c10..9b39b10 100644 --- a/pykickstart/handlers/control.py +++ b/pykickstart/handlers/control.py @@ -933,7 +933,7 @@ commandMap = { "skipx": skipx.FC3_SkipX, "sshpw": sshpw.F13_SshPw, "text": displaymode.FC3_DisplayMode, - "timezone": timezone.FC6_Timezone, + "timezone": timezone.F18_Timezone, "updates": updates.F7_Updates, "upgrade": upgrade.F11_Upgrade, "url": method.F14_Method, diff --git a/tests/commands/timezone.py b/tests/commands/timezone.py index e17674c..3932ecd 100644 --- a/tests/commands/timezone.py +++ b/tests/commands/timezone.py @@ -52,5 +52,30 @@ class FC6_TestCase(FC3_TestCase): # fail self.assert_parse_error("timezone --isUtc", KickstartValueError) +class F18_TestCase(FC6_TestCase): + def runTest(self): + # pass + self.assert_parse("timezone --utc Europe/Prague") + self.assert_parse("timezone --isUtc Europe/Prague\n") + self.assert_parse("timezone --isUtc Eastern", "timezone Eastern --isUtc\n") + self.assert_parse("timezone Europe/Prague") + self.assert_parse("timezone Europe/Prague --nontp") + self.assert_parse("timezone Europe/Prague "\ + "--ntpservers=ntp.cesnet.cz,tik.nic.cz") + self.assert_parse("timezone Europe/Prague --ntpservers=ntp.cesnet.cz,") + + # fail + self.assert_parse_error("timezone", KickstartValueError) + self.assert_parse_error("timezone Eastern Central", KickstartValueError) + self.assert_parse_error("timezone --blah Eastern") + self.assert_parse_error("timezone --utc", KickstartValueError) + self.assert_parse_error("timezone --isUtc", KickstartValueError) + self.assert_parse_error("timezone Europe/Prague --nontp "\ + "--ntpservers=ntp.cesnet.cz", + KickstartParseError) + self.assert_parse_error("timezone Europe/Prague --ntpservers="\ + "ntp.cesnet.cz, tik.nic.cz", + KickstartValueError) + if __name__ == "__main__": unittest.main() -- 1.7.4.4 _______________________________________________ Anaconda-devel-list mailing list Anaconda-devel-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/anaconda-devel-list