[PATCH] Add support for the realm command

Martin Kolman mkolman at gmail.com
Thu May 9 15:02:05 UTC 2013


The realm command uses realmd to enable joining a
domain during installation.

Only the join command is supported.
Also includes tests for the realm command.

Signed-off-by: Martin Kolman <mkolman at gmail.com>
---
 pykickstart/commands/__init__.py |   2 +-
 pykickstart/commands/realm.py    | 105 +++++++++++++++++++++++++++++++++++++++
 pykickstart/handlers/control.py  |   1 +
 tests/commands/realm.py          |  43 ++++++++++++++++
 4 files changed, 150 insertions(+), 1 deletion(-)
 create mode 100644 pykickstart/commands/realm.py
 create mode 100644 tests/commands/realm.py

diff --git a/pykickstart/commands/__init__.py b/pykickstart/commands/__init__.py
index 0e7d0d1..d8c71f3 100644
--- a/pykickstart/commands/__init__.py
+++ b/pykickstart/commands/__init__.py
@@ -21,6 +21,6 @@ import authconfig, autopart, autostep, bootloader, btrfs, clearpart, device
 import deviceprobe, displaymode, dmraid, driverdisk, fcoe, firewall, firstboot
 import group, ignoredisk, interactive, iscsi, iscsiname, key, keyboard, lang
 import langsupport, lilocheck, logging, logvol, mediacheck, method, monitor
-import mouse, multipath, network, partition, raid, reboot, repo, rescue, rootpw
+import mouse, multipath, network, partition, raid, realm, reboot, repo, rescue, rootpw
 import selinux, services, skipx, sshpw, timezone, updates, upgrade, user
 import unsupported_hardware, vnc, volgroup, xconfig, zerombr, zfcp
diff --git a/pykickstart/commands/realm.py b/pykickstart/commands/realm.py
new file mode 100644
index 0000000..80be0eb
--- /dev/null
+++ b/pykickstart/commands/realm.py
@@ -0,0 +1,105 @@
+#
+# Stef Walter <stefw at redhat.com>
+#
+# Copyright 2013 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.
+#
+
+from pykickstart.base import *
+
+import getopt
+import pipes
+import shlex
+
+_ = lambda x: gettext.ldgettext("pykickstart", x)
+
+
+class F19_Realm(KickstartCommand):
+    removedKeywords = KickstartCommand.removedKeywords
+    removedAttrs = KickstartCommand.removedAttrs
+
+    def __init__(self, writePriority=0, *args, **kwargs):
+        KickstartCommand.__init__(self, *args, **kwargs)
+        self.join_realm = None
+        self.join_args = []
+        self.discover_options = []
+
+    def _parseArguments(self, string):
+        if self.join_realm:
+            raise KickstartParseError, formatErrorMsg(self.lineno, msg=_(
+                "The realm command 'join' should only be specified once"))
+        args = shlex.split(string)
+        if not args:
+            raise KickstartValueError, formatErrorMsg(self.lineno, msg=_(
+                "Missing realm command arguments"))
+        command = args.pop(0)
+        if command == "join":
+            self._parseJoin(args)
+        else:
+            raise KickstartValueError, formatErrorMsg(self.lineno, msg=_(
+                "Unsupported realm '%s' command" % command))
+
+    def _parseJoin(self, args):
+        try:
+            # We only support these args
+            opts, remaining = getopt.getopt(args, "", ("client-software=",
+                                                       "server-software=",
+                                                       "membership-software=",
+                                                       "one-time-password=",
+                                                       "no-password=",
+                                                       "computer-ou="))
+        except getopt.GetoptError, ex:
+            raise KickstartValueError, formatErrorMsg(self.lineno, msg=_(
+                "Invalid realm arguments: %s") % str(ex))
+
+        if len(remaining) != 1:
+            raise KickstartValueError, formatErrorMsg(self.lineno, msg=_(
+                "Specify only one realm to join"))
+
+        # Parse successful, just use this as the join command
+        self.join_realm = remaining[0]
+        self.join_args = args
+
+        # Build a discovery command
+        self.discover_options = []
+        supported_discover_options = ("--client-software",
+                                      "--server-software",
+                                      "--membership-software")
+        for (o, a) in opts:
+            if o in supported_discover_options:
+                self.discover_options.append("%s=%s" % (o, a))
+
+    def _getCommandsAsStrings(self):
+        commands = []
+        if self.join_args:
+            args = [pipes.quote(arg) for arg in self.join_args]
+            commands.append("realm join " + " ".join(args))
+        return commands
+
+    def __str__(self):
+        retval = KickstartCommand.__str__(self)
+
+        commands = self._getCommandsAsStrings()
+        if commands:
+            retval += "# Realm or domain membership\n"
+            retval += "\n".join(commands)
+            retval += "\n"
+
+        return retval
+
+    def parse(self, args):
+        self._parseArguments(self.currentLine[len(self.currentCmd):].strip())
+        return self
diff --git a/pykickstart/handlers/control.py b/pykickstart/handlers/control.py
index e77e7e4..8b4462d 100644
--- a/pykickstart/handlers/control.py
+++ b/pykickstart/handlers/control.py
@@ -982,6 +982,7 @@ commandMap = {
         "partition": partition.F18_Partition,
         "poweroff": reboot.F18_Reboot,
         "raid": raid.F18_Raid,
+        "realm": realm.F19_Realm,
         "reboot": reboot.F18_Reboot,
         "repo": repo.F15_Repo,
         "rescue": rescue.F10_Rescue,
diff --git a/tests/commands/realm.py b/tests/commands/realm.py
new file mode 100644
index 0000000..0b108b1
--- /dev/null
+++ b/tests/commands/realm.py
@@ -0,0 +1,43 @@
+import unittest, shlex
+import warnings
+from tests.baseclass import *
+
+from pykickstart.errors import *
+from pykickstart.commands.realm import *
+
+class F19_TestCase(CommandTest):
+    command = "realm"
+
+    def runTest(self):
+
+        # No realm command arguments
+        self.assert_parse_error("realm", KickstartValueError)
+
+        # Unsupported realmcommand
+        self.assert_parse_error("realm unknown --args", KickstartValueError)
+
+        # pass for join
+        realm = self.assert_parse("realm join blah")
+        self.assertEquals(realm.join_realm, "blah")
+        self.assertEquals(realm.join_args, ["blah"])
+        self.assertEquals(realm.discover_options, [])
+        self.assertEquals(str(realm), "# Realm or domain membership\nrealm join blah\n")
+
+        # pass for join with client-software
+        realm = self.assert_parse("realm join --client-software=sssd --computer-ou=OU=blah domain.example.com")
+        self.assertEquals(realm.join_realm, "domain.example.com")
+        self.assertEquals(realm.join_args, ["--client-software=sssd", "--computer-ou=OU=blah", "domain.example.com"])
+        self.assertEquals(realm.discover_options, ["--client-software=sssd"])
+        self.assertEquals(str(realm), "# Realm or domain membership\nrealm join --client-software=sssd --computer-ou=OU=blah domain.example.com\n")
+
+        # Bad arguments, only one domain for join
+        self.assert_parse_error("realm join one two", KickstartValueError)
+
+        # Bad arguments, unsupported argument
+        self.assert_parse_error("realm join --user=blah one.example.com", KickstartValueError)
+
+        # Bad arguments, unsupported argument
+        self.assert_parse_error("realm join --user=blah one.example.com", KickstartValueError)
+
+if __name__ == "__main__":
+    unittest.main()
-- 
1.8.1.4



More information about the anaconda-patches mailing list