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