Statistics
| Branch: | Tag: | Revision:

root / ci / snf-ci @ 3fbbd85d

History | View | Annotate | Download (2.6 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("-c", "--cloud", dest="kamaki_cloud", default=None,
46
                      help="Use specified cloud, as is in .kamakirc"),
47
    parser.add_option("-f", "--flavor", dest="flavor", default=None,
48
                      help="Name of flavor to use for the server.")
49
    parser.add_option("-i", "--image", dest="image", default=None,
50
                      help="UUID of image to use for the server.")
51

    
52
    (options, args) = parser.parse_args()
53

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

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

    
74
    cleanup_config = command in CLEAN_CONFIG_CMDS
75
    synnefo_ci = SynnefoCI(cleanup_config=cleanup_config,
76
                           cloud=options.kamaki_cloud)
77

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

    
91

    
92
if __name__ == "__main__":
93
    main()