summaryrefslogtreecommitdiffstats
path: root/ipatests/ipa-test-config
diff options
context:
space:
mode:
authorPetr Viktorin <pviktori@redhat.com>2013-05-24 19:55:21 +0200
committerPetr Viktorin <pviktori@redhat.com>2013-07-15 15:49:05 +0200
commitc577420e40a353f3038263bf8ef763f7c01f6f22 (patch)
tree219dc0dadf42d001e65c0d5beacf04a6bcfdcb7e /ipatests/ipa-test-config
parent226f9d681df92ea2757c3f97386859983474f727 (diff)
downloadfreeipa-c577420e40a353f3038263bf8ef763f7c01f6f22.tar.gz
freeipa-c577420e40a353f3038263bf8ef763f7c01f6f22.tar.xz
freeipa-c577420e40a353f3038263bf8ef763f7c01f6f22.zip
Add a framework for integration test configuration
Integration tests are configured via environment variables. Add a framework for parsing these variables and storing them in easy-to-use objects. Add an `ipa-test-config` executable that loads the configuration and prints out variables needed in shell scripts. Part of the work for https://fedorahosted.org/freeipa/ticket/3621
Diffstat (limited to 'ipatests/ipa-test-config')
-rwxr-xr-xipatests/ipa-test-config107
1 files changed, 107 insertions, 0 deletions
diff --git a/ipatests/ipa-test-config b/ipatests/ipa-test-config
new file mode 100755
index 000000000..eb2da10f2
--- /dev/null
+++ b/ipatests/ipa-test-config
@@ -0,0 +1,107 @@
+#! /usr/bin/python
+
+import sys
+import os
+import argparse
+
+from ipalib.constants import FQDN
+from ipatests.test_integration import config
+
+
+def main(argv):
+ parser = argparse.ArgumentParser(
+ description='Prints out IPA test configuration for use in shell scripts.'
+ 'IPA integration tests are configured via environment variables')
+
+ parser.add_argument('host', nargs='?',
+ help='Print config for the given hostname')
+
+ parser.add_argument('--global', action='store_true', dest='global_',
+ help='Print global config (not specific to a host '
+ 'or domain)')
+
+ parser.add_argument('--domain',
+ help='IPA domain name, or number (the X in _envX)')
+
+ parser.add_argument('--master',
+ help='Print config for the master',
+ action='store_true')
+
+ parser.add_argument('--replica', type=int,
+ help='Print config for the replica with this number')
+
+ parser.add_argument('--client', type=int,
+ help='Print config for the client with this number')
+
+ parser.add_argument('--no-simple', dest='simple', action='store_false',
+ help='Do not print Simple Vars '
+ '(normally included backwards-compatibility)')
+
+ args = parser.parse_args(argv)
+
+ hostsargs = [bool(args.host), bool(args.master), bool(args.replica),
+ bool(args.client)]
+ if hostsargs.count(True) > 1:
+ parser.error('Must specify at most one of host selection options')
+ if any(hostsargs) or args.domain:
+ if args.global_:
+ parser.error('--global may not be combined with host selection options')
+ else:
+ args.host = FQDN
+
+ kwargs = {}
+ if not args.simple:
+ kwargs['simple'] = False
+
+ conf = config.Config.from_env(os.environ)
+
+ return config.env_to_script(get_object(conf, args).to_env(**kwargs))
+
+
+def get_object(conf, args):
+ if args.global_:
+ return conf
+ elif args.host:
+ try:
+ return conf.host_by_name(args.host)
+ except LookupError:
+ exit('Host %s not found in config. Try --global' % args.host)
+ else:
+ if args.domain:
+ try:
+ num = int(args.domain) - 1
+ except ValueError:
+ domains = [d for d in conf.domains if d.name == args.domain]
+ if not domains:
+ exit('Domain %s not found' % args.domain)
+ domain = domains[0]
+ else:
+ try:
+ domain = conf.domains[num]
+ except LookupError:
+ exit('Domain %s not found.' % args.domain)
+ else:
+ try:
+ domain = conf.domains[0]
+ except IndexError:
+ exit('No domains are configured.')
+ if args.master:
+ return domain.master
+ elif args.replica:
+ num = int(args.replica) - 1
+ try:
+ return domain.replicas[args.replica]
+ except LookupError:
+ exit('Domain %s not found in domain %s' % (args.replica, domain.name))
+ elif args.client:
+ num = int(args.client) - 1
+ try:
+ return domain.replicas[args.client]
+ except LookupError:
+ exit('Client %s not found in domain %s' % (args.client, domain.name))
+ else:
+ return domain
+
+
+if __name__ == '__main__':
+ print main(sys.argv[1:]),