Statistics
| Branch: | Tag: | Revision:

root / ci / snf-ci @ e2dc37b2

History | View | Annotate | Download (3.4 kB)

1
#!/usr/bin/env python
2

    
3
"""
4
"""
5
import os
6
from utils import SynnefoCI
7
from optparse import OptionParser
8

    
9
CREATE_SERVER_CMD = "create"
10
BUILD_SYNNEFO_CMD = "build"
11
DEPLOY_SYNNEFO_CMD = "deploy"
12
TEST_SYNNEFO_CMD = "test"
13
RUN_BURNIN_CMD = "burnin"
14
ALL_CMDS = "all"
15

    
16
AVAILABLE_COMMANDS = [
17
    CREATE_SERVER_CMD,
18
    BUILD_SYNNEFO_CMD,
19
    DEPLOY_SYNNEFO_CMD,
20
    TEST_SYNNEFO_CMD,
21
    RUN_BURNIN_CMD,
22
]
23

    
24
CLEAN_CONFIG_CMDS = [CREATE_SERVER_CMD, ALL_CMDS]
25

    
26
USAGE = """usage: %%prog [options] command
27

    
28
command:
29
    * %s: Create the slave server
30
    * %s: Create debian packages for Synnefo in the created server
31
    * %s: Deploy Synnefo in created server
32
    * %s: Run Synnefo unittests
33
    * %s: Run snf-burnin in the deployed Synnefo
34

    
35
    * %s: Run all the available commands
36
""" % tuple([CREATE_SERVER_CMD,
37
             BUILD_SYNNEFO_CMD,
38
             DEPLOY_SYNNEFO_CMD,
39
             TEST_SYNNEFO_CMD,
40
             RUN_BURNIN_CMD,
41
             ALL_CMDS])
42

    
43

    
44
def main():
45
    parser = OptionParser(usage=USAGE)
46
    parser.add_option("--conf", dest="config_file", default=None,
47
                      help="Configuration file for SynnefoCI script"),
48
    parser.add_option("-c", "--cloud", dest="kamaki_cloud", default=None,
49
                      help="Use specified cloud, as is in .kamakirc"),
50
    parser.add_option("-f", "--flavor", dest="flavor", default=None,
51
                      help="Name of flavor to use for the server.")
52
    parser.add_option("-i", "--image", dest="image", default=None,
53
                      help="UUID of image to use for the server.")
54
    parser.add_option("--fetch-packages", dest="fetch_packages",
55
                      default=None,
56
                      help="Download the debian packages that were created"
57
                           " during the '%s' step in this directory" %
58
                           BUILD_SYNNEFO_CMD)
59
    parser.add_option("--schema", dest="schema", default=None,
60
                      help="Schema for snf-deploy.")
61

    
62
    (options, args) = parser.parse_args()
63

    
64
    if len(args) != 1:
65
        msg = "ERROR: Command takes exactly one argument"
66
        parser.print_help()
67
        print
68
        print msg
69
        return
70

    
71
    command = args[0]
72
    if command == ALL_CMDS:
73
        for cmd in AVAILABLE_COMMANDS:
74
            setattr(options, cmd, True)
75
    elif command not in AVAILABLE_COMMANDS:
76
        msg = "ERROR: Unknown command: %s" % command
77
        parser.print_help()
78
        print
79
        print msg
80
        return
81
    else:
82
        setattr(options, command, True)
83

    
84
    cleanup_config = command in CLEAN_CONFIG_CMDS
85
    synnefo_ci = SynnefoCI(config_file=options.config_file,
86
                           cleanup_config=cleanup_config,
87
                           cloud=options.kamaki_cloud)
88

    
89
    if getattr(options, CREATE_SERVER_CMD, False):
90
        synnefo_ci.create_server(flavor_id=options.flavor,
91
                                 image_id=options.image)
92
        synnefo_ci.clone_repo()
93
    if getattr(options, BUILD_SYNNEFO_CMD, False):
94
        synnefo_ci.build_synnefo()
95
    if options.fetch_packages:
96
        dest = os.path.abspath(options.fetch_packages)
97
        synnefo_ci.fetch_packages(dest=dest)
98
    if getattr(options, DEPLOY_SYNNEFO_CMD, False):
99
        synnefo_ci.deploy_synnefo(schema=options.schema)
100
    if getattr(options, TEST_SYNNEFO_CMD, False):
101
        synnefo_ci.unit_test()
102
    if getattr(options, RUN_BURNIN_CMD, False):
103
        synnefo_ci.run_burnin()
104

    
105

    
106
if __name__ == "__main__":
107
    main()