[PATCH 1/2 pykickstart rhel7-branch] ostreesetup: New command

Radek Vykydal rvykydal at redhat.com
Mon Jul 14 11:36:37 UTC 2014


From: Colin Walters <walters at redhat.com>

This tells the installer to handle an OSTree repository.

Related: rhbz#1113535
Port of rpmostreepayload patches from master
commit dd1f59278ad2aa0cb2c79483528770b78488661d
---
 pykickstart/commands/__init__.py    |  2 +-
 pykickstart/commands/ostreesetup.py | 76 +++++++++++++++++++++++++++++++++++++
 pykickstart/handlers/control.py     |  1 +
 tests/commands/ostreesetup.py       | 38 +++++++++++++++++++
 4 files changed, 116 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..4cc20af 100644
--- a/pykickstart/commands/__init__.py
+++ b/pykickstart/commands/__init__.py
@@ -21,6 +21,6 @@ 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, 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..269d91f
--- /dev/null
+++ b/pykickstart/commands/ostreesetup.py
@@ -0,0 +1,76 @@
+#
+# 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 KickstartCommand
+from pykickstart.options import KSOptionParser
+
+import gettext
+_ = lambda x: gettext.ldgettext("pykickstart", x)
+
+class RHEL7_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', False)
+
+    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):
+        retcmd = []
+        if self.osname:
+            retcmd.append('--osname="%s"' % self.osname)
+        if self.remote:
+            retcmd.append('--remote="%s"' % self.remote)
+        if self.url:
+            retcmd.append('--url="%s"' % self.url)
+        if self.ref:
+            retcmd.append('--ref="%s"' % self.ref)
+        if self.noGpg:
+            retcmd.append('--nogpg')
+        return ' '.join(retcmd)
+
+    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)
+        if self.remote is None:
+            self.remote = self.osname
+        return self
+
diff --git a/pykickstart/handlers/control.py b/pykickstart/handlers/control.py
index 9d3bbf0..8b0d338 100644
--- a/pykickstart/handlers/control.py
+++ b/pykickstart/handlers/control.py
@@ -1349,6 +1349,7 @@ commandMap = {
         "multipath": multipath.FC6_MultiPath,
         "network": network.RHEL7_Network,
         "nfs": nfs.FC6_NFS,
+        "ostreesetup": ostreesetup.RHEL7_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..3c59a5a
--- /dev/null
+++ b/tests/commands/ostreesetup.py
@@ -0,0 +1,38 @@
+#
+# Colin Walters <walters at redhat.com>
+#
+# 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 RHEL7_TestCase(CommandTest):
+    def runTest(self):
+        # pass
+        self.assert_parse("ostreesetup --osname=fedora-atomic --url=http://example.com/repo --ref=fedora-atomic/sometest/base/core")
+        cmdstr = "ostreesetup --osname=\"fedora-atomic\" --remote=\"fedora-atomic\" --url=\"http://example.com/repo\" --ref=\"fedora-atomic/sometest/base/core\""
+        self.assert_parse(cmdstr, cmdstr + '\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.9.0



More information about the anaconda-patches mailing list