root / ci / snf-ci @ 2945e7ed
History | View | Annotate | Download (6.7 kB)
1 |
#!/usr/bin/env python |
---|---|
2 |
|
3 |
# Invalid name for type module. pylint: disable-msg=C0103 |
4 |
|
5 |
""" |
6 |
Continuous Integration script for Synnefo. |
7 |
""" |
8 |
|
9 |
import os |
10 |
import utils |
11 |
from optparse import OptionParser |
12 |
|
13 |
CREATE_SERVER_CMD = "create" |
14 |
BUILD_SYNNEFO_CMD = "build" |
15 |
BUILD_DOCS_SYNNEFO_CMD = "docs" |
16 |
DEPLOY_SYNNEFO_CMD = "deploy" |
17 |
TEST_SYNNEFO_CMD = "test" |
18 |
RUN_BURNIN_CMD = "burnin" |
19 |
CREATE_X2GO_FILE = "x2goplugin" |
20 |
ALL_CMDS = "all" |
21 |
|
22 |
COMMANDS_IN_ALL_MODE = [ |
23 |
CREATE_SERVER_CMD, |
24 |
BUILD_SYNNEFO_CMD, |
25 |
BUILD_DOCS_SYNNEFO_CMD, |
26 |
DEPLOY_SYNNEFO_CMD, |
27 |
TEST_SYNNEFO_CMD, |
28 |
RUN_BURNIN_CMD, |
29 |
] |
30 |
|
31 |
AVAILABLE_COMMANDS = [ |
32 |
CREATE_X2GO_FILE, |
33 |
] + COMMANDS_IN_ALL_MODE |
34 |
|
35 |
USAGE = """usage: %%prog [options] command[,command...] |
36 |
|
37 |
command: |
38 |
* %s: Create the slave server |
39 |
* %s: Create debian packages for Synnefo in the created server |
40 |
* %s: Create documentation for Synnefo in the created server |
41 |
* %s: Deploy Synnefo in created server |
42 |
* %s: Run Synnefo unittests |
43 |
* %s: Run snf-burnin in the deployed Synnefo |
44 |
* %s: Create x2go plugin file |
45 |
|
46 |
* %s: Run all the available commands |
47 |
""" % tuple([CREATE_SERVER_CMD, |
48 |
BUILD_SYNNEFO_CMD, |
49 |
BUILD_DOCS_SYNNEFO_CMD, |
50 |
DEPLOY_SYNNEFO_CMD, |
51 |
TEST_SYNNEFO_CMD, |
52 |
RUN_BURNIN_CMD, |
53 |
CREATE_X2GO_FILE, |
54 |
ALL_CMDS]) |
55 |
|
56 |
|
57 |
def main(): # Too many branches. pylint: disable-msg=R0912 |
58 |
"""Parse command line options and run the specified actions""" |
59 |
parser = OptionParser(usage=USAGE) |
60 |
parser.add_option("-c", "--conf", dest="config_file", default=None, |
61 |
help="Configuration file for SynnefoCI script") |
62 |
parser.add_option("--cloud", dest="kamaki_cloud", default=None, |
63 |
help="Use specified cloud, as is in .kamakirc") |
64 |
parser.add_option("-f", "--flavor", dest="flavor", default=None, |
65 |
help="Flavor to use for the server." |
66 |
" Supports both search by name (reg expression)" |
67 |
" with \"name:flavor name\" or by id with" |
68 |
" \"id:flavor id\".") |
69 |
parser.add_option("-i", "--image", dest="image", default=None, |
70 |
help="Image to use for the server." |
71 |
" Supports both search by name (reg expression)" |
72 |
" with \"name:image name\" or by id with" |
73 |
" \"id:image id\".") |
74 |
parser.add_option("--ssh-keys", dest="ssh_keys", default=None, |
75 |
help="Upload/Install the public ssh keys contained" |
76 |
" in this file to the server") |
77 |
parser.add_option("--name", dest="server_name", default=None, |
78 |
help=""), |
79 |
parser.add_option("-n", "--build-id", dest="build_id", default=None, |
80 |
type="int", |
81 |
help="Specify a number to use to identify this build." |
82 |
" One can later use this number to retrieve" |
83 |
" information (such as IPs, passwords etc) about" |
84 |
" the machines created. If not given this script" |
85 |
" will create a new build-id.") |
86 |
parser.add_option("--fetch-packages", dest="fetch_packages", |
87 |
default=None, |
88 |
help="Download the debian packages that were created" |
89 |
" during the '%s' step in this directory." % |
90 |
BUILD_SYNNEFO_CMD) |
91 |
parser.add_option("--fetch-docs", dest="fetch_docs", |
92 |
default=None, |
93 |
help="Download the documentation that was created" |
94 |
" during the '%s' step in this directory." % |
95 |
BUILD_DOCS_SYNNEFO_CMD) |
96 |
parser.add_option("--schema", dest="schema", default=None, |
97 |
help="Schema for snf-deploy.") |
98 |
parser.add_option("--local-repo", dest="local_repo", default=False, |
99 |
action="store_true", |
100 |
help="Instead of cloning from the official Synnefo" |
101 |
" repo, copy and use the local one.") |
102 |
parser.add_option("--x2go-output", dest="x2go_output", default=None, |
103 |
help="File where to save the x2go plugin html page.") |
104 |
parser.add_option("--no-colors", dest="use_colors", |
105 |
default=True, action="store_false", |
106 |
help="Don't use colorful output messages.") |
107 |
|
108 |
(options, args) = parser.parse_args() |
109 |
|
110 |
# ---------------------------------- |
111 |
# Check arguments |
112 |
if len(args) != 1: |
113 |
msg = "ERROR: Command takes exactly one argument" |
114 |
parser.print_help() |
115 |
|
116 |
print msg |
117 |
return |
118 |
|
119 |
commands = args[0] |
120 |
if commands == ALL_CMDS: |
121 |
for cmd in COMMANDS_IN_ALL_MODE: |
122 |
setattr(options, cmd, True) |
123 |
|
124 |
else: |
125 |
commands = commands.split(",") |
126 |
for command in commands: |
127 |
if command not in AVAILABLE_COMMANDS: |
128 |
msg = "ERROR: Unknown command: %s" % command |
129 |
parser.print_help() |
130 |
|
131 |
print msg |
132 |
return |
133 |
else: |
134 |
setattr(options, command, True) |
135 |
|
136 |
# ---------------------------------- |
137 |
# Initialize SynnefoCi |
138 |
utils.USE_COLORS = options.use_colors |
139 |
synnefo_ci = utils.SynnefoCI(config_file=options.config_file, |
140 |
build_id=options.build_id, |
141 |
cloud=options.kamaki_cloud) |
142 |
|
143 |
# ---------------------------------- |
144 |
# Run commands |
145 |
if getattr(options, CREATE_SERVER_CMD, False): |
146 |
synnefo_ci.create_server(flavor=options.flavor, |
147 |
image=options.image, |
148 |
ssh_keys=options.ssh_keys, |
149 |
server_name=options.server_name) |
150 |
synnefo_ci.clone_repo(local_repo=options.local_repo) |
151 |
if getattr(options, BUILD_SYNNEFO_CMD, False): |
152 |
synnefo_ci.build_packages() |
153 |
if options.fetch_packages: |
154 |
dest = os.path.abspath(options.fetch_packages) |
155 |
synnefo_ci.fetch_packages(dest=dest) |
156 |
if getattr(options, BUILD_DOCS_SYNNEFO_CMD, False): |
157 |
synnefo_ci.build_documentation() |
158 |
if options.fetch_docs: |
159 |
dest = os.path.abspath(options.fetch_docs) |
160 |
synnefo_ci.fetch_documentation(dest=dest) |
161 |
if getattr(options, DEPLOY_SYNNEFO_CMD, False): |
162 |
synnefo_ci.deploy_synnefo(schema=options.schema) |
163 |
if getattr(options, TEST_SYNNEFO_CMD, False): |
164 |
synnefo_ci.unit_test() |
165 |
if getattr(options, RUN_BURNIN_CMD, False): |
166 |
synnefo_ci.run_burnin() |
167 |
if getattr(options, CREATE_X2GO_FILE, False): |
168 |
synnefo_ci.x2go_plugin(options.x2go_output) |
169 |
|
170 |
|
171 |
if __name__ == "__main__": |
172 |
main() |