Statistics
| Branch: | Tag: | Revision:

root / ci / snf-ci @ 04660f63

History | View | Annotate | Download (6.5 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
import utils
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
    parser.add_option("--no-colors", dest="use_colors",
103
                      default=True, action="store_false",
104
                      help="Don't use colorful output messages.")
105

    
106
    (options, args) = parser.parse_args()
107

    
108
    # ----------------------------------
109
    # Check arguments
110
    if len(args) != 1:
111
        msg = "ERROR: Command takes exactly one argument"
112
        parser.print_help()
113
        print
114
        print msg
115
        return
116

    
117
    commands = args[0]
118
    if commands == ALL_CMDS:
119
        for cmd in COMMANDS_IN_ALL_MODE:
120
            setattr(options, cmd, True)
121

    
122
    else:
123
        commands = commands.split(",")
124
        for command in commands:
125
            if command not in AVAILABLE_COMMANDS:
126
                msg = "ERROR: Unknown command: %s" % command
127
                parser.print_help()
128
                print
129
                print msg
130
                return
131
            else:
132
                setattr(options, command, True)
133

    
134
    # ----------------------------------
135
    # Initialize SynnefoCi
136
    utils.USE_COLORS = options.use_colors
137
    synnefo_ci = utils.SynnefoCI(config_file=options.config_file,
138
                                 build_id=options.build_id,
139
                                 cloud=options.kamaki_cloud)
140

    
141
    # ----------------------------------
142
    # Run commands
143
    if getattr(options, CREATE_SERVER_CMD, False):
144
        synnefo_ci.create_server(flavor=options.flavor,
145
                                 image=options.image,
146
                                 ssh_keys=options.ssh_keys)
147
        synnefo_ci.clone_repo(local_repo=options.local_repo)
148
    if getattr(options, BUILD_SYNNEFO_CMD, False):
149
        synnefo_ci.build_synnefo()
150
        if options.fetch_packages:
151
            dest = os.path.abspath(options.fetch_packages)
152
            synnefo_ci.fetch_packages(dest=dest)
153
    if getattr(options, BUILD_DOCS_SYNNEFO_CMD, False):
154
        synnefo_ci.build_documentation()
155
        if options.fetch_docs:
156
            dest = os.path.abspath(options.fetch_docs)
157
            synnefo_ci.fetch_documentation(dest=dest)
158
    if getattr(options, DEPLOY_SYNNEFO_CMD, False):
159
        synnefo_ci.deploy_synnefo(schema=options.schema)
160
    if getattr(options, TEST_SYNNEFO_CMD, False):
161
        synnefo_ci.unit_test()
162
    if getattr(options, RUN_BURNIN_CMD, False):
163
        synnefo_ci.run_burnin()
164
    if getattr(options, CREATE_X2GO_FILE, False):
165
        synnefo_ci.x2go_plugin(options.x2go_output)
166

    
167

    
168
if __name__ == "__main__":
169
    main()