Statistics
| Branch: | Tag: | Revision:

root / ci / snf-ci @ 85bcc8da

History | View | Annotate | Download (3.2 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 debian packages for Synnefo in the 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
    parser.add_option("--fetch-packages", dest="fetch_packages",
54
                      action="store_true", default=False,
55
                      help="Download the debian packages that were created"
56
                           " during the '%s' step." % BUILD_SYNNEFO_CMD)
57

    
58
    (options, args) = parser.parse_args()
59

    
60
    if len(args) != 1:
61
        msg = "ERROR: Command takes exactly one argument"
62
        parser.print_help()
63
        print
64
        print msg
65
        return
66

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

    
80
    cleanup_config = command in CLEAN_CONFIG_CMDS
81
    synnefo_ci = SynnefoCI(config_file=options.config_file,
82
                           cleanup_config=cleanup_config,
83
                           cloud=options.kamaki_cloud)
84

    
85
    if getattr(options, CREATE_SERVER_CMD, False):
86
        synnefo_ci.create_server(flavor_id=options.flavor,
87
                                 image_id=options.image)
88
        synnefo_ci.clone_repo()
89
    if getattr(options, BUILD_SYNNEFO_CMD, False):
90
        synnefo_ci.build_synnefo()
91
    if options.fetch_packages:
92
        synnefo_ci.fetch_packages()
93
    if getattr(options, DEPLOY_SYNNEFO_CMD, False):
94
        synnefo_ci.deploy_synnefo()
95
    if getattr(options, TEST_SYNNEFO_CMD, False):
96
        synnefo_ci.unit_test()
97
    if getattr(options, RUN_BURNIN_CMD, False):
98
        synnefo_ci.run_burnin()
99

    
100

    
101
if __name__ == "__main__":
102
    main()