snf-ci 3.39 KB
Newer Older
1
2
3
4
#!/usr/bin/env python

"""
"""
5
import os
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from utils import SynnefoCI
from optparse import OptionParser

CREATE_SERVER_CMD = "create"
BUILD_SYNNEFO_CMD = "build"
DEPLOY_SYNNEFO_CMD = "deploy"
TEST_SYNNEFO_CMD = "test"
RUN_BURNIN_CMD = "burnin"
ALL_CMDS = "all"

AVAILABLE_COMMANDS = [
    CREATE_SERVER_CMD,
    BUILD_SYNNEFO_CMD,
    DEPLOY_SYNNEFO_CMD,
    TEST_SYNNEFO_CMD,
    RUN_BURNIN_CMD,
]

CLEAN_CONFIG_CMDS = [CREATE_SERVER_CMD, ALL_CMDS]

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

command:
29
    * %s: Create the slave server
30
    * %s: Create debian packages for Synnefo in the created server
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
    * %s: Deploy Synnefo in created server
    * %s: Run Synnefo unittests
    * %s: Run snf-burnin in the deployed Synnefo

    * %s: Run all the available commands
""" % tuple([CREATE_SERVER_CMD,
             BUILD_SYNNEFO_CMD,
             DEPLOY_SYNNEFO_CMD,
             TEST_SYNNEFO_CMD,
             RUN_BURNIN_CMD,
             ALL_CMDS])


def main():
    parser = OptionParser(usage=USAGE)
46
47
    parser.add_option("--conf", dest="config_file", default=None,
                      help="Configuration file for SynnefoCI script"),
48
49
50
51
52
53
    parser.add_option("-c", "--cloud", dest="kamaki_cloud", default=None,
                      help="Use specified cloud, as is in .kamakirc"),
    parser.add_option("-f", "--flavor", dest="flavor", default=None,
                      help="Name of flavor to use for the server.")
    parser.add_option("-i", "--image", dest="image", default=None,
                      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
58
                           " during the '%s' step in this directory" %
                           BUILD_SYNNEFO_CMD)
59
60
    parser.add_option("--schema", dest="schema", default=None,
                      help="Schema for snf-deploy.")
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84

    (options, args) = parser.parse_args()

    if len(args) != 1:
        msg = "ERROR: Command takes exactly one argument"
        parser.print_help()
        print
        print msg
        return

    command = args[0]
    if command == ALL_CMDS:
        for cmd in AVAILABLE_COMMANDS:
            setattr(options, cmd, True)
    elif command not in AVAILABLE_COMMANDS:
        msg = "ERROR: Unknown command: %s" % command
        parser.print_help()
        print
        print msg
        return
    else:
        setattr(options, command, True)

    cleanup_config = command in CLEAN_CONFIG_CMDS
85
86
    synnefo_ci = SynnefoCI(config_file=options.config_file,
                           cleanup_config=cleanup_config,
87
88
89
90
91
92
93
94
                           cloud=options.kamaki_cloud)

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


if __name__ == "__main__":
    main()