Statistics
| Branch: | Tag: | Revision:

root / ci / snf-ci @ ac7b865d

History | View | Annotate | Download (7.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
import utils
11
from optparse import OptionParser
12

    
13
CREATE_SERVER_CMD = "create"
14
DELETE_SERVER_CMD = "delete"
15
BUILD_SYNNEFO_CMD = "build"
16
BUILD_DOCS_SYNNEFO_CMD = "docs"
17
DEPLOY_SYNNEFO_CMD = "deploy"
18
TEST_SYNNEFO_CMD = "test"
19
RUN_BURNIN_CMD = "burnin"
20
CREATE_X2GO_FILE = "x2goplugin"
21
SHELL_CONNECT = "shell"
22
ALL_CMDS = "all"
23

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

    
33
AVAILABLE_COMMANDS = [
34
    CREATE_X2GO_FILE,
35
    DELETE_SERVER_CMD,
36
    SHELL_CONNECT,
37
] + COMMANDS_IN_ALL_MODE
38

    
39
USAGE = """usage: %%prog [options] command[,command...]
40

    
41
command:
42
    * %s: Create the slave server
43
    * %s: Create debian packages for Synnefo in the created server
44
    * %s: Create documentation for Synnefo in the created server
45
    * %s: Deploy Synnefo in created server
46
    * %s: Run Synnefo unittests
47
    * %s: Run snf-burnin in the deployed Synnefo
48
    * %s: Create x2go plugin file
49
    * %s: Delete the slave server
50
    * %s: Connect to the server using ssh
51

    
52
    * %s: Run all the available commands
53
""" % tuple([CREATE_SERVER_CMD,
54
             BUILD_SYNNEFO_CMD,
55
             BUILD_DOCS_SYNNEFO_CMD,
56
             DEPLOY_SYNNEFO_CMD,
57
             TEST_SYNNEFO_CMD,
58
             RUN_BURNIN_CMD,
59
             CREATE_X2GO_FILE,
60
             DELETE_SERVER_CMD,
61
             SHELL_CONNECT,
62
             ALL_CMDS])
63

    
64

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

    
116
    (options, args) = parser.parse_args()
117

    
118
    # ----------------------------------
119
    # Check arguments
120
    if len(args) != 1:
121
        msg = "ERROR: Command takes exactly one argument"
122
        parser.print_help()
123
        print
124
        print msg
125
        return
126

    
127
    commands = args[0]
128
    if commands == ALL_CMDS:
129
        for cmd in COMMANDS_IN_ALL_MODE:
130
            setattr(options, cmd, True)
131

    
132
    else:
133
        commands = commands.split(",")
134
        for command in commands:
135
            if command not in AVAILABLE_COMMANDS:
136
                msg = "ERROR: Unknown command: %s" % command
137
                parser.print_help()
138
                print
139
                print msg
140
                return
141
            else:
142
                setattr(options, command, True)
143

    
144
    # ----------------------------------
145
    # Initialize SynnefoCi
146
    utils.USE_COLORS = options.use_colors
147
    synnefo_ci = utils.SynnefoCI(config_file=options.config_file,
148
                                 build_id=options.build_id,
149
                                 cloud=options.kamaki_cloud)
150

    
151
    # ----------------------------------
152
    # Run commands
153
    if getattr(options, CREATE_SERVER_CMD, False):
154
        synnefo_ci.create_server(flavor=options.flavor,
155
                                 image=options.image,
156
                                 ssh_keys=options.ssh_keys,
157
                                 server_name=options.server_name)
158
        synnefo_ci.clone_repo(local_repo=options.local_repo)
159
    if getattr(options, BUILD_SYNNEFO_CMD, False):
160
        synnefo_ci.build_packages()
161
        if options.fetch_packages:
162
            dest = os.path.abspath(options.fetch_packages)
163
            synnefo_ci.fetch_packages(dest=dest)
164
    if getattr(options, BUILD_DOCS_SYNNEFO_CMD, False):
165
        synnefo_ci.build_documentation()
166
        if options.fetch_docs:
167
            dest = os.path.abspath(options.fetch_docs)
168
            synnefo_ci.fetch_documentation(dest=dest)
169
    if getattr(options, DEPLOY_SYNNEFO_CMD, False):
170
        synnefo_ci.deploy_synnefo(schema=options.schema)
171
    if getattr(options, TEST_SYNNEFO_CMD, False):
172
        synnefo_ci.unit_test()
173
    if getattr(options, RUN_BURNIN_CMD, False):
174
        synnefo_ci.run_burnin()
175
    if getattr(options, CREATE_X2GO_FILE, False):
176
        synnefo_ci.x2go_plugin(options.x2go_output)
177
    if getattr(options, DELETE_SERVER_CMD, False):
178
        synnefo_ci.destroy_server()
179
    if getattr(options, SHELL_CONNECT, False):
180
        synnefo_ci.shell_connect()
181

    
182

    
183
if __name__ == "__main__":
184
    main()