Statistics
| Branch: | Tag: | Revision:

root / ci / snf-ci @ fcfef550

History | View | Annotate | Download (6.1 kB)

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