root / ci / snf-ci @ 88e6558b
History | View | Annotate | Download (4.1 kB)
1 |
#!/usr/bin/env python |
---|---|
2 |
|
3 |
""" |
4 |
""" |
5 |
import os |
6 |
from utils import SynnefoCI |
7 |
from optparse import OptionParser |
8 |
|
9 |
CREATE_SERVER_CMD = "create" |
10 |
BUILD_SYNNEFO_CMD = "build" |
11 |
BUILD_DOCS_SYNNEFO_CMD = "docs" |
12 |
DEPLOY_SYNNEFO_CMD = "deploy" |
13 |
TEST_SYNNEFO_CMD = "test" |
14 |
RUN_BURNIN_CMD = "burnin" |
15 |
ALL_CMDS = "all" |
16 |
|
17 |
AVAILABLE_COMMANDS = [ |
18 |
CREATE_SERVER_CMD, |
19 |
BUILD_SYNNEFO_CMD, |
20 |
BUILD_DOCS_SYNNEFO_CMD, |
21 |
DEPLOY_SYNNEFO_CMD, |
22 |
TEST_SYNNEFO_CMD, |
23 |
RUN_BURNIN_CMD, |
24 |
] |
25 |
|
26 |
CLEAN_CONFIG_CMDS = [CREATE_SERVER_CMD, ALL_CMDS] |
27 |
|
28 |
USAGE = """usage: %%prog [options] command |
29 |
|
30 |
command: |
31 |
* %s: Create the slave server |
32 |
* %s: Create debian packages for Synnefo in the created server |
33 |
* %s: Create documentation for Synnefo in the created server |
34 |
* %s: Deploy Synnefo in created server |
35 |
* %s: Run Synnefo unittests |
36 |
* %s: Run snf-burnin in the deployed Synnefo |
37 |
|
38 |
* %s: Run all the available commands |
39 |
""" % tuple([CREATE_SERVER_CMD, |
40 |
BUILD_SYNNEFO_CMD, |
41 |
BUILD_DOCS_SYNNEFO_CMD, |
42 |
DEPLOY_SYNNEFO_CMD, |
43 |
TEST_SYNNEFO_CMD, |
44 |
RUN_BURNIN_CMD, |
45 |
ALL_CMDS]) |
46 |
|
47 |
|
48 |
def main(): |
49 |
parser = OptionParser(usage=USAGE) |
50 |
parser.add_option("--conf", dest="config_file", default=None, |
51 |
help="Configuration file for SynnefoCI script"), |
52 |
parser.add_option("-c", "--cloud", dest="kamaki_cloud", default=None, |
53 |
help="Use specified cloud, as is in .kamakirc"), |
54 |
parser.add_option("-f", "--flavor", dest="flavor", default=None, |
55 |
help="Name of flavor to use for the server.") |
56 |
parser.add_option("-i", "--image", dest="image", default=None, |
57 |
help="UUID of image to use for the server.") |
58 |
parser.add_option("--fetch-packages", dest="fetch_packages", |
59 |
default=None, |
60 |
help="Download the debian packages that were created" |
61 |
" during the '%s' step in this directory" % |
62 |
BUILD_SYNNEFO_CMD) |
63 |
parser.add_option("--fetch-docs", dest="fetch_docs", |
64 |
default=None, |
65 |
help="Download the documentation that was created" |
66 |
" during the '%s' step in this directory" % |
67 |
BUILD_DOCS_SYNNEFO_CMD) |
68 |
parser.add_option("--schema", dest="schema", default=None, |
69 |
help="Schema for snf-deploy.") |
70 |
|
71 |
(options, args) = parser.parse_args() |
72 |
|
73 |
if len(args) != 1: |
74 |
msg = "ERROR: Command takes exactly one argument" |
75 |
parser.print_help() |
76 |
|
77 |
print msg |
78 |
return |
79 |
|
80 |
command = args[0] |
81 |
if command == ALL_CMDS: |
82 |
for cmd in AVAILABLE_COMMANDS: |
83 |
setattr(options, cmd, True) |
84 |
elif command not in AVAILABLE_COMMANDS: |
85 |
msg = "ERROR: Unknown command: %s" % command |
86 |
parser.print_help() |
87 |
|
88 |
print msg |
89 |
return |
90 |
else: |
91 |
setattr(options, command, True) |
92 |
|
93 |
cleanup_config = command in CLEAN_CONFIG_CMDS |
94 |
synnefo_ci = SynnefoCI(config_file=options.config_file, |
95 |
cleanup_config=cleanup_config, |
96 |
cloud=options.kamaki_cloud) |
97 |
|
98 |
if getattr(options, CREATE_SERVER_CMD, False): |
99 |
synnefo_ci.create_server(flavor_id=options.flavor, |
100 |
image_id=options.image) |
101 |
synnefo_ci.clone_repo() |
102 |
if getattr(options, BUILD_SYNNEFO_CMD, False): |
103 |
synnefo_ci.build_synnefo() |
104 |
if options.fetch_packages: |
105 |
dest = os.path.abspath(options.fetch_packages) |
106 |
synnefo_ci.fetch_packages(dest=dest) |
107 |
if getattr(options, BUILD_DOCS_SYNNEFO_CMD, False): |
108 |
synnefo_ci.build_documentation() |
109 |
if options.fetch_docs: |
110 |
dest = os.path.abspath(options.fetch_docs) |
111 |
synnefo_ci.fetch_documentation(dest=dest) |
112 |
if getattr(options, DEPLOY_SYNNEFO_CMD, False): |
113 |
synnefo_ci.deploy_synnefo(schema=options.schema) |
114 |
if getattr(options, TEST_SYNNEFO_CMD, False): |
115 |
synnefo_ci.unit_test() |
116 |
if getattr(options, RUN_BURNIN_CMD, False): |
117 |
synnefo_ci.run_burnin() |
118 |
|
119 |
|
120 |
if __name__ == "__main__": |
121 |
main() |