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