Statistics
| Branch: | Tag: | Revision:

root / ci / snf-ci @ f195386e

History | View | Annotate | Download (4.3 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
ALL_CMDS = "all"
20

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

    
30
CLEAN_CONFIG_CMDS = [CREATE_SERVER_CMD, ALL_CMDS]
31

    
32
USAGE = """usage: %%prog [options] command
33

    
34
command:
35
    * %s: Create the slave server
36
    * %s: Create debian packages for Synnefo in the created server
37
    * %s: Create documentation for Synnefo in the created server
38
    * %s: Deploy Synnefo in created server
39
    * %s: Run Synnefo unittests
40
    * %s: Run snf-burnin in the deployed Synnefo
41

    
42
    * %s: Run all the available commands
43
""" % tuple([CREATE_SERVER_CMD,
44
             BUILD_SYNNEFO_CMD,
45
             BUILD_DOCS_SYNNEFO_CMD,
46
             DEPLOY_SYNNEFO_CMD,
47
             TEST_SYNNEFO_CMD,
48
             RUN_BURNIN_CMD,
49
             ALL_CMDS])
50

    
51

    
52
def main():  # Too many branches. pylint: disable-msg=R0912
53
    """Parse command line options and run the specified actions"""
54
    parser = OptionParser(usage=USAGE)
55
    parser.add_option("-c", "--conf", dest="config_file", default=None,
56
                      help="Configuration file for SynnefoCI script")
57
    parser.add_option("--cloud", dest="kamaki_cloud", default=None,
58
                      help="Use specified cloud, as is in .kamakirc")
59
    parser.add_option("-f", "--flavor", dest="flavor", default=None,
60
                      help="Name of flavor to use for the server.")
61
    parser.add_option("-i", "--image", dest="image", default=None,
62
                      help="UUID of image to use for the server.")
63
    parser.add_option("--fetch-packages", dest="fetch_packages",
64
                      default=None,
65
                      help="Download the debian packages that were created"
66
                           " during the '%s' step in this directory" %
67
                           BUILD_SYNNEFO_CMD)
68
    parser.add_option("--fetch-docs", dest="fetch_docs",
69
                      default=None,
70
                      help="Download the documentation that was created"
71
                           " during the '%s' step in this directory" %
72
                           BUILD_DOCS_SYNNEFO_CMD)
73
    parser.add_option("--schema", dest="schema", default=None,
74
                      help="Schema for snf-deploy.")
75

    
76
    (options, args) = parser.parse_args()
77

    
78
    if len(args) != 1:
79
        msg = "ERROR: Command takes exactly one argument"
80
        parser.print_help()
81
        print
82
        print msg
83
        return
84

    
85
    command = args[0]
86
    if command == ALL_CMDS:
87
        for cmd in AVAILABLE_COMMANDS:
88
            setattr(options, cmd, True)
89
    elif command not in AVAILABLE_COMMANDS:
90
        msg = "ERROR: Unknown command: %s" % command
91
        parser.print_help()
92
        print
93
        print msg
94
        return
95
    else:
96
        setattr(options, command, True)
97

    
98
    cleanup_config = command in CLEAN_CONFIG_CMDS
99
    synnefo_ci = SynnefoCI(config_file=options.config_file,
100
                           cleanup_config=cleanup_config,
101
                           cloud=options.kamaki_cloud)
102

    
103
    if getattr(options, CREATE_SERVER_CMD, False):
104
        synnefo_ci.create_server(flavor_id=options.flavor,
105
                                 image_id=options.image)
106
        synnefo_ci.clone_repo()
107
    if getattr(options, BUILD_SYNNEFO_CMD, False):
108
        synnefo_ci.build_synnefo()
109
        if options.fetch_packages:
110
            dest = os.path.abspath(options.fetch_packages)
111
            synnefo_ci.fetch_packages(dest=dest)
112
    if getattr(options, BUILD_DOCS_SYNNEFO_CMD, False):
113
        synnefo_ci.build_documentation()
114
        if options.fetch_docs:
115
            dest = os.path.abspath(options.fetch_docs)
116
            synnefo_ci.fetch_documentation(dest=dest)
117
    if getattr(options, DEPLOY_SYNNEFO_CMD, False):
118
        synnefo_ci.deploy_synnefo(schema=options.schema)
119
    if getattr(options, TEST_SYNNEFO_CMD, False):
120
        synnefo_ci.unit_test()
121
    if getattr(options, RUN_BURNIN_CMD, False):
122
        synnefo_ci.run_burnin()
123

    
124

    
125
if __name__ == "__main__":
126
    main()