Statistics
| Branch: | Tag: | Revision:

root / ci / snf-ci @ e2db4a57

History | View | Annotate | Download (2.8 kB)

1
#!/usr/bin/env python
2

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

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

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

    
23
CLEAN_CONFIG_CMDS = [CREATE_SERVER_CMD, ALL_CMDS]
24

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

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

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

    
42

    
43
def main():
44
    parser = OptionParser(usage=USAGE)
45
    parser.add_option("--conf", dest="config_file", default=None,
46
                      help="Configuration file for SynnefoCI script"),
47
    parser.add_option("-c", "--cloud", dest="kamaki_cloud", default=None,
48
                      help="Use specified cloud, as is in .kamakirc"),
49
    parser.add_option("-f", "--flavor", dest="flavor", default=None,
50
                      help="Name of flavor to use for the server.")
51
    parser.add_option("-i", "--image", dest="image", default=None,
52
                      help="UUID of image to use for the server.")
53

    
54
    (options, args) = parser.parse_args()
55

    
56
    if len(args) != 1:
57
        msg = "ERROR: Command takes exactly one argument"
58
        parser.print_help()
59
        print
60
        print msg
61
        return
62

    
63
    command = args[0]
64
    if command == ALL_CMDS:
65
        for cmd in AVAILABLE_COMMANDS:
66
            setattr(options, cmd, True)
67
    elif command not in AVAILABLE_COMMANDS:
68
        msg = "ERROR: Unknown command: %s" % command
69
        parser.print_help()
70
        print
71
        print msg
72
        return
73
    else:
74
        setattr(options, command, True)
75

    
76
    cleanup_config = command in CLEAN_CONFIG_CMDS
77
    synnefo_ci = SynnefoCI(config_file=options.config_file,
78
                           cleanup_config=cleanup_config,
79
                           cloud=options.kamaki_cloud)
80

    
81
    if getattr(options, CREATE_SERVER_CMD, False):
82
        synnefo_ci.create_server(flavor_id=options.flavor,
83
                                 image_id=options.image)
84
        synnefo_ci.clone_repo()
85
    if getattr(options, BUILD_SYNNEFO_CMD, False):
86
        synnefo_ci.build_synnefo()
87
    if getattr(options, DEPLOY_SYNNEFO_CMD, False):
88
        synnefo_ci.deploy_synnefo()
89
    if getattr(options, TEST_SYNNEFO_CMD, False):
90
        synnefo_ci.unit_test()
91
    if getattr(options, RUN_BURNIN_CMD, False):
92
        synnefo_ci.run_burnin()
93

    
94

    
95
if __name__ == "__main__":
96
    main()