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