-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathipa-vagrant-ci-runner
executable file
·156 lines (137 loc) · 5.31 KB
/
ipa-vagrant-ci-runner
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/python3
# Author: Martin Basti
# See LICENSE file for license
import argparse
import logging
import sys
import traceback
from ipavagrant.config import IPAVagrantConfig
from ipavagrant.ipaci import IPACIRunner
from ipavagrant import constants
def main():
parser = argparse.ArgumentParser(description="")
parser.add_argument("test_name", type=str,
help="Name of CI test(s) to be executed",
nargs='*')
parser.add_argument("--init", action="store_true", default=False,
dest="initialize",
help="Initialize IPA CI runner in current directory")
test_config = parser.add_argument_group("Test configuration options")
test_config.add_argument(
'--add-package',
dest="packages",
action="append",
help="Allows to specify packages that will be installed from "
"repository",
default=[],
metavar="NAME")
test_config.add_argument(
'--add-copr', dest="copr_repos", action="append",
help="Allows to specify copr repositories that will be enabled",
default=[], metavar="NAME")
test_config.add_argument(
'--memory-controller', dest="memory_controller",
help="Allows to specify memory for controller [MB]",
metavar="MBytes", default=None)
test_config.add_argument(
'--memory-server', dest="memory_server",
help="Allows to specify memory for server [MB]",
metavar="MBytes", default=None)
test_config.add_argument(
'--memory-client', dest="memory_client",
help="Allows to specify memory for client [MB]",
metavar="MBytes", default=None)
# selinux
test_config.add_argument(
'--selinux-enforce', dest="selinux_enforcing",
action='store_true',
help="Set SELinux to enforce mode")
test_config.add_argument(
'--no-selinux-enforce', dest="selinux_enforcing",
action='store_false',
help="Set SELinux to permissive mode")
test_config.set_defaults(selinux_enforcing=None)
test_config.add_argument(
'--box', dest="box", default=None,
help="Set box that will be used")
test_config.add_argument(
'--domain', dest="domain", type=str,
default=None, help="Domain for provisioned VM")
file_config = parser.add_argument_group("Configuration file options")
file_config.add_argument(
'--config-file', dest="config_file", default=None,
help="Path to configuration file (default: %s)" %
constants.DEFAULT_CONFIG_FILENAME)
file_config.add_argument(
"--config-topo-file", dest="config_topo_file",
default=None,
help="Path for configuration file contains tests and topologies "
"configuration. (default: {})".format(
constants.DEFAULT_TOPO_CONFIG_FILENAME))
file_config.add_argument(
'--export-topo-config',
dest="export_topo_config",
default=False,
action="store_true",
help="export current configuration to config file (destination: "
"--config-topo-file)")
file_config.add_argument(
'--list-tests', dest="list_tests", default=False,
action="store_true", help="list available/configured tests")
parser.add_argument("--debug", action="store_true", default=False,
dest="debug",
help="Enables DEBUG level logging")
parser.add_argument("--dry-run", action="store_true", default=False,
dest="dry_run",
help="Do not execute any vagrant command, just "
"create vagrant files (for testing)")
args = parser.parse_args()
if args.debug:
logging.basicConfig(level=logging.DEBUG)
else:
logging.basicConfig(level=logging.INFO)
config = IPAVagrantConfig(
filename=args.config_file,
# options
domain=args.domain,
memory_controller=args.memory_controller,
memory_server=args.memory_server,
memory_client=args.memory_client,
selinux_enforcing=args.selinux_enforcing,
box=args.box,
packages=args.packages,
copr_repos=args.copr_repos
)
runner = IPACIRunner(
args.test_name,
config_topo_file=args.config_topo_file,
config=config,
dry_run=args.dry_run
)
if args.initialize:
if runner.is_initialized():
raise RuntimeError("Already initialized")
else:
runner.initialize()
print("Initialization done", file=sys.stderr)
sys.exit(0)
if args.export_topo_config:
where = runner.topo_config.export_config()
print("Configuration saved to", where, file=sys.stderr)
return
if args.list_tests:
print("\n".join(sorted(runner.topo_config.tests.keys())))
return
if not runner.is_initialized():
raise RuntimeError("IPA CI runner must be initialized first in "
"current directory. Please use option '--init'")
if not args.test_name:
RuntimeError("No tests have been specified")
runner.run()
if __name__ == "__main__":
try:
main()
except RuntimeError as e:
logging.debug(traceback.format_exc())
print(e, file=sys.stderr)
sys.exit(2)