Statistics
| Branch: | Tag: | Revision:

root / ci / snf-ci @ 88e6558b

History | View | Annotate | Download (4.1 kB)

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