From: "Brian C. Lane" bcl@redhat.com
This allows us to create tests that inspect the resulting object instead of just testing to see if it parses. --- tests/baseclass.py | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/tests/baseclass.py b/tests/baseclass.py index 5efd4d2..9d9e8c3 100644 --- a/tests/baseclass.py +++ b/tests/baseclass.py @@ -86,21 +86,23 @@ class CommandTest(unittest.TestCase):
# If expectedStr supplied, we want to ensure the parsed result matches if expectedStr is not None: - result = parser.parse(args[1:]) + obj = parser.parse(args[1:]) + result = str(obj)
# Strip any comment lines ... we only match on non-comments if ignoreComments: - result = re.sub("^#[^\n]*\n", "", str(result)) + result = re.sub("^#[^\n]*\n", "", result)
# Ensure we parsed as expected - self.assertEqual(str(result), expectedStr) + self.assertEqual(result, expectedStr) # No expectedStr supplied, just make sure it does not raise an # exception else: try: - result = parser.parse(args[1:]) + obj = parser.parse(args[1:]) except Exception, e: self.fail("Failed while parsing: %s" % e) + return obj
def assert_parse_error(self, inputStr, exception=KickstartParseError): '''Assert that parsing the supplied string raises a
From: "Brian C. Lane" bcl@redhat.com
Previously the 'halt' command resulted in KS_SHUTDOWN being set instead of KS_WAIT. --- pykickstart/commands/reboot.py | 23 +++++++++++++++++++++++ pykickstart/handlers/control.py | 8 ++++---- 2 files changed, 27 insertions(+), 4 deletions(-)
diff --git a/pykickstart/commands/reboot.py b/pykickstart/commands/reboot.py index 391af14..ef246fd 100644 --- a/pykickstart/commands/reboot.py +++ b/pykickstart/commands/reboot.py @@ -77,3 +77,26 @@ class FC6_Reboot(FC3_Reboot): (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno) self._setToSelf(self.op, opts) return self + +class F18_Reboot(FC6_Reboot): + removedKeywords = FC6_Reboot.removedKeywords + removedAttrs = FC6_Reboot.removedAttrs + + def __init__(self, writePriority=0, *args, **kwargs): + FC6_Reboot.__init__(self, writePriority, *args, **kwargs) + self.op = self._getParser() + + def __str__(self): + retval = FC6_Reboot.__str__(self).rstrip() + + if self.action == KS_WAIT: + retval += "# Halt after installation\nhalt\n" + + return retval + + def parse(self, args): + FC6_Reboot.parse(self, args) + if self.currentCmd == "halt": + self.action = KS_WAIT + return self + diff --git a/pykickstart/handlers/control.py b/pykickstart/handlers/control.py index bda3a5e..a24c8b7 100644 --- a/pykickstart/handlers/control.py +++ b/pykickstart/handlers/control.py @@ -904,7 +904,7 @@ commandMap = { "firstboot": firstboot.FC3_Firstboot, "graphical": displaymode.FC3_DisplayMode, "group": group.F12_Group, - "halt": reboot.FC6_Reboot, + "halt": reboot.F18_Reboot, "harddrive": method.F14_Method, "ignoredisk": ignoredisk.F14_IgnoreDisk, "install": upgrade.F11_Upgrade, @@ -920,15 +920,15 @@ commandMap = { "nfs": method.F14_Method, "part": partition.F18_Partition, "partition": partition.F18_Partition, - "poweroff": reboot.FC6_Reboot, + "poweroff": reboot.F18_Reboot, "raid": raid.F15_Raid, - "reboot": reboot.FC6_Reboot, + "reboot": reboot.F18_Reboot, "repo": repo.F15_Repo, "rescue": rescue.F10_Rescue, "rootpw": rootpw.F8_RootPw, "selinux": selinux.FC3_SELinux, "services": services.FC6_Services, - "shutdown": reboot.FC6_Reboot, + "shutdown": reboot.F18_Reboot, "skipx": skipx.FC3_SkipX, "sshpw": sshpw.F13_SshPw, "text": displaymode.FC3_DisplayMode,
Previously the 'halt' command resulted in KS_SHUTDOWN being set instead of KS_WAIT.
So this is an interesting one. On the one hand, anaconda/pykickstart have been busted in this respect for an awful long time so adding an F18 version of the command to fix it is correct. On the other hand, wouldn't anaconda have been working all along had pykickstart been working and thus, this should just be added to the initial version of the command.
I can make an argument either way.
- Chris
On Wed, Jul 25, 2012 at 02:56:41PM -0400, Chris Lumens wrote:
Previously the 'halt' command resulted in KS_SHUTDOWN being set instead of KS_WAIT.
So this is an interesting one. On the one hand, anaconda/pykickstart have been busted in this respect for an awful long time so adding an F18 version of the command to fix it is correct. On the other hand, wouldn't anaconda have been working all along had pykickstart been working and thus, this should just be added to the initial version of the command.
I can make an argument either way.
I think it is better to make a new version with it so that we don't lose the historical behavior.
I think it is better to make a new version with it so that we don't lose the historical behavior.
Yes, this is probably right. If you push, I can do a new build. There's a couple things that I've been sitting on.
I assume newui needs its Requires updated for pykickstart, too?
- Chris
From: "Brian C. Lane" bcl@redhat.com
Test for parsing of reboot, shutdown, poweroff and halt. Check the resulting action value and check for --eject state. --- tests/commands/reboot.py | 65 ++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 65 insertions(+), 0 deletions(-) create mode 100644 tests/commands/reboot.py
diff --git a/tests/commands/reboot.py b/tests/commands/reboot.py new file mode 100644 index 0000000..09963f2 --- /dev/null +++ b/tests/commands/reboot.py @@ -0,0 +1,65 @@ +# +# Brian C. Lane bcl@redhat.com +# +# Copyright 2012 Red Hat, Inc. +# +# This copyrighted material is made available to anyone wishing to use, modify, +# copy, or redistribute it subject to the terms and conditions of the GNU +# General Public License v.2. This program is distributed in the hope that it +# will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the +# implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., 51 +# 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. +# +import unittest, shlex +import warnings +from tests.baseclass import * + +from pykickstart.errors import * +from pykickstart.constants import * + +class FC3_TestCase(CommandTest): + command = "reboot" + + def runTest(self): + # pass + cmd = self.assert_parse("reboot") + self.assertEqual(cmd.action, KS_REBOOT) + cmd = self.assert_parse("shutdown") + self.assertEqual(cmd.action, KS_SHUTDOWN) + + cmd = self.assert_parse("halt") + # halt changed in F18 + if self.__class__.__name__ in ("FC3_TestCase", "FC6_TestCase"): + self.assertEqual(cmd.action, KS_SHUTDOWN) + + cmd = self.assert_parse("poweroff") + self.assertEqual(cmd.action, KS_SHUTDOWN) + +class FC6_TestCase(FC3_TestCase): + def runTest(self): + FC3_TestCase.runTest(self) + + # pass + cmd = self.assert_parse("reboot --eject") + self.assertEqual(cmd.action, KS_REBOOT) + self.assertEqual(cmd.eject, True) + +class F18_TestCase(FC6_TestCase): + def runTest(self): + FC6_TestCase.runTest(self) + + # pass + cmd = self.assert_parse("halt") + self.assertEqual(cmd.action, KS_WAIT) + cmd = self.assert_parse("halt --eject") + self.assertEqual(cmd.eject, True) + +if __name__ == "__main__": + unittest.main()
anaconda-patches@lists.fedorahosted.org