From cad071d736cb35e67245ca11cf8750931c0d98ba Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Tue, 11 Mar 2014 09:33:36 -0400 Subject: [PATCH] ostreesetup: New command This tells the installer to handle an OSTree repository. --- pykickstart/commands/__init__.py | 3 +- pykickstart/commands/ostreesetup.py | 74 +++++++++++++++++++++++++++++++++++++ pykickstart/handlers/control.py | 2 + tests/commands/ostreesetup.py | 37 +++++++++++++++++++ 4 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 pykickstart/commands/ostreesetup.py create mode 100644 tests/commands/ostreesetup.py diff --git a/pykickstart/commands/__init__.py b/pykickstart/commands/__init__.py index c5145ba..ed4d649 100644 --- a/pykickstart/commands/__init__.py +++ b/pykickstart/commands/__init__.py @@ -21,6 +21,7 @@ import authconfig, autopart, autostep, bootloader, btrfs, clearpart, cdrom, devi import deviceprobe, displaymode, dmraid, driverdisk, eula, fcoe, firewall, firstboot import group, harddrive, ignoredisk, interactive, iscsi, iscsiname, key, keyboard, lang import langsupport, lilocheck, liveimg, logging, logvol, mediacheck, method, monitor -import mouse, multipath, network, nfs, partition, raid, realm, reboot, repo, rescue +import mouse, multipath, network, nfs, ostreesetup +import partition, raid, realm, reboot, repo, rescue import rootpw, selinux, services, skipx, sshpw, timezone, updates, upgrade, url, user import unsupported_hardware, vnc, volgroup, xconfig, zerombr, zfcp diff --git a/pykickstart/commands/ostreesetup.py b/pykickstart/commands/ostreesetup.py new file mode 100644 index 0000000..b722c2c --- /dev/null +++ b/pykickstart/commands/ostreesetup.py @@ -0,0 +1,74 @@ +# +# Copyright (C) 2014 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, or (at your option) any later version. +# 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. +# + +from pykickstart.base import * +from pykickstart.errors import * +from pykickstart.options import * + +import gettext +_ = lambda x: gettext.ldgettext("pykickstart", x) + +class F20_OSTreeSetup(KickstartCommand): + removedKeywords = KickstartCommand.removedKeywords + removedAttrs = KickstartCommand.removedAttrs + + def __init__(self, *args, **kwargs): + KickstartCommand.__init__(self, *args, **kwargs) + self.op = self._getParser() + self.osname = kwargs.get('osname', None) + self.remote = kwargs.get("remote", self.osname) + self.url = kwargs.get('url', None) + self.ref = kwargs.get('ref', None) + self.noGpg = kwargs.get('noGpg', True) + + def __str__(self): + retval = KickstartCommand.__str__(self) + + if self.osname: + retval += "# OSTree setup\n" + retval += "ostreesetup %s\n" % self._getArgsAsStr() + + return retval + + def _getArgsAsStr(self): + retval = "" + if self.osname: + retval += "--osname=%s" % self.osname + if self.remote: + retval += "--remote=%s" % self.remote + if self.url: + retval += "--url=%s" % self.url + if self.ref: + retval += "--ref=%s" % self.ref + if self.noGpg: + retval += "--nogpg" + return retval + + def _getParser(self): + op = KSOptionParser() + op.add_option("--osname", dest="osname", required=1) + op.add_option("--remote", dest="remote") + op.add_option("--url", dest="url", required=1) + op.add_option("--ref", dest="ref", required=1) + op.add_option("--nogpg", action="store_true") + return op + + def parse(self, args): + (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno) + self._setToSelf(self.op, opts) + return self diff --git a/pykickstart/handlers/control.py b/pykickstart/handlers/control.py index 9d3bbf0..7b2bc0c 100644 --- a/pykickstart/handlers/control.py +++ b/pykickstart/handlers/control.py @@ -1060,6 +1060,7 @@ commandMap = { "multipath": multipath.FC6_MultiPath, "network": network.F20_Network, "nfs": nfs.FC6_NFS, + "ostreesetup": ostreesetup.F20_OSTreeSetup, "part": partition.F20_Partition, "partition": partition.F20_Partition, "poweroff": reboot.F18_Reboot, @@ -1349,6 +1350,7 @@ commandMap = { "multipath": multipath.FC6_MultiPath, "network": network.RHEL7_Network, "nfs": nfs.FC6_NFS, + "ostreesetup": ostreesetup.F20_OSTreeSetup, "part": partition.F20_Partition, "partition": partition.F20_Partition, "poweroff": reboot.F18_Reboot, diff --git a/tests/commands/ostreesetup.py b/tests/commands/ostreesetup.py new file mode 100644 index 0000000..b837e5d --- /dev/null +++ b/tests/commands/ostreesetup.py @@ -0,0 +1,37 @@ +# +# Colin Walters +# +# Copyright 2014 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 +from tests.baseclass import * + +class F20_TestCase(CommandTest): + def runTest(self): + # pass + self.assert_parse("ostreesetup --os=fedora-atomic --url http://example.com/repo --ref fedora-atomic/sometest/base/core\n") + self.assert_parse("ostreesetup --os=fedora-atomic --remote=testremote --url http://example.com/repo --ref=fedora-atomic/sometest/base/core\n") + + # fail - we have required arguments + self.assert_parse_error("ostreesetup", KickstartValueError) + self.assert_parse_error("ostreesetup --os=fedora-atomic", KickstartValueError) + self.assert_parse_error("ostreesetup --os=fedora-atomic --url=http://example.com/repo", KickstartValueError) + self.assert_parse_error("ostreesetup --bacon=tasty") + +if __name__ == "__main__": + unittest.main() -- 1.8.3.1