Statistics
| Branch: | Tag: | Revision:

root / ci / snf-ci @ fcfef550

History | View | Annotate | Download (6.1 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
CREATE_X2GO_FILE = "x2goplugin"
20
ALL_CMDS = "all"
21

    
22
COMMANDS_IN_ALL_MODE = [
23
    CREATE_SERVER_CMD,
24
    BUILD_SYNNEFO_CMD,
25
    BUILD_DOCS_SYNNEFO_CMD,
26
    DEPLOY_SYNNEFO_CMD,
27
    TEST_SYNNEFO_CMD,
28
    RUN_BURNIN_CMD,
29
]
30

    
31
AVAILABLE_COMMANDS = [
32
    CREATE_X2GO_FILE,
33
] + COMMANDS_IN_ALL_MODE
34

    
35
USAGE = """usage: %%prog [options] command[,command...]
36

    
37
command:
38
    * %s: Create the slave server
39
    * %s: Create debian packages for Synnefo in the created server
40
    * %s: Create documentation for Synnefo in the created server
41
    * %s: Deploy Synnefo in created server
42
    * %s: Run Synnefo unittests
43
    * %s: Run snf-burnin in the deployed Synnefo
44
    * %s: Create x2go plugin file
45

    
46
    * %s: Run all the available commands
47
""" % tuple([CREATE_SERVER_CMD,
48
             BUILD_SYNNEFO_CMD,
49
             BUILD_DOCS_SYNNEFO_CMD,
50
             DEPLOY_SYNNEFO_CMD,
51
             TEST_SYNNEFO_CMD,
52
             RUN_BURNIN_CMD,
53
             CREATE_X2GO_FILE,
54
             ALL_CMDS])
55

    
56

    
57
def main():  # Too many branches. pylint: disable-msg=R0912
58
    """Parse command line options and run the specified actions"""
59
    parser = OptionParser(usage=USAGE)
60
    parser.add_option("-c", "--conf", dest="config_file", default=None,
61
                      help="Configuration file for SynnefoCI script")
62
    parser.add_option("--cloud", dest="kamaki_cloud", default=None,
63
                      help="Use specified cloud, as is in .kamakirc")
64
    parser.add_option("-f", "--flavor", dest="flavor", default=None,
65
                      help="Flavor to use for the server."
66
                           " Supports both search by name (reg expression)"
67
                           " with \"name:flavor name\" or by id with"
68
                           " \"id:flavor id\".")
69
    parser.add_option("-i", "--image", dest="image", default=None,
70
                      help="Image to use for the server."
71
                           " Supports both search by name (reg expression)"
72
                           " with \"name:image name\" or by id with"
73
                           " \"id:image id\".")
74
    parser.add_option("--ssh-keys", dest="ssh_keys", default=None,
75
                      help="Upload/Install the public ssh keys contained"
76
                           " in this file to the server")
77
    parser.add_option("-n", "--build-id", dest="build_id", default=None,
78
                      type="int",
79
                      help="Specify a number to use to identify this build."
80
                           " One can later use this number to retrieve"
81
                           " information (such as IPs, passwords etc) about"
82
                           " the machines created. If not given this script"
83
                           " will create a new build-id.")
84
    parser.add_option("--fetch-packages", dest="fetch_packages",
85
                      default=None,
86
                      help="Download the debian packages that were created"
87
                           " during the '%s' step in this directory" %
88
                           BUILD_SYNNEFO_CMD)
89
    parser.add_option("--fetch-docs", dest="fetch_docs",
90
                      default=None,
91
                      help="Download the documentation that was created"
92
                           " during the '%s' step in this directory" %
93
                           BUILD_DOCS_SYNNEFO_CMD)
94
    parser.add_option("--schema", dest="schema", default=None,
95
                      help="Schema for snf-deploy.")
96
    parser.add_option("--local-repo", dest="local_repo", default=False,
97
                      action="store_true",
98
                      help="Instead of cloning from the official Synnefo"
99
                           " repo, copy and use the local one.")
100
    parser.add_option("--x2go-output", dest="x2go_output", default=None,
101
                      help="File where to save the x2go plugin html page.")
102

    
103
    (options, args) = parser.parse_args()
104

    
105
    if len(args) != 1:
106
        msg = "ERROR: Command takes exactly one argument"
107
        parser.print_help()
108
        print
109
        print msg
110
        return
111

    
112
    commands = args[0]
113
    if commands == ALL_CMDS:
114
        for cmd in COMMANDS_IN_ALL_MODE:
115
            setattr(options, cmd, True)
116

    
117
    else:
118
        commands = commands.split(",")
119
        for command in commands:
120
            if command not in AVAILABLE_COMMANDS:
121
                msg = "ERROR: Unknown command: %s" % command
122
                parser.print_help()
123
                print
124
                print msg
125
                return
126
            else:
127
                setattr(options, command, True)
128

    
129
    synnefo_ci = SynnefoCI(config_file=options.config_file,
130
                           build_id=options.build_id,
131
                           cloud=options.kamaki_cloud)
132

    
133
    if getattr(options, CREATE_SERVER_CMD, False):
134
        synnefo_ci.create_server(flavor=options.flavor,
135
                                 image=options.image,
136
                                 ssh_keys=options.ssh_keys)
137
        synnefo_ci.clone_repo(local_repo=options.local_repo)
138
    if getattr(options, BUILD_SYNNEFO_CMD, False):
139
        synnefo_ci.build_synnefo()
140
        if options.fetch_packages:
141
            dest = os.path.abspath(options.fetch_packages)
142
            synnefo_ci.fetch_packages(dest=dest)
143
    if getattr(options, BUILD_DOCS_SYNNEFO_CMD, False):
144
        synnefo_ci.build_documentation()
145
        if options.fetch_docs:
146
            dest = os.path.abspath(options.fetch_docs)
147
            synnefo_ci.fetch_documentation(dest=dest)
148
    if getattr(options, DEPLOY_SYNNEFO_CMD, False):
149
        synnefo_ci.deploy_synnefo(schema=options.schema)
150
    if getattr(options, TEST_SYNNEFO_CMD, False):
151
        synnefo_ci.unit_test()
152
    if getattr(options, RUN_BURNIN_CMD, False):
153
        synnefo_ci.run_burnin()
154
    if getattr(options, CREATE_X2GO_FILE, False):
155
        synnefo_ci.x2go_plugin(options.x2go_output)
156

    
157

    
158
if __name__ == "__main__":
159
    main()