summaryrefslogtreecommitdiffstats
path: root/vstf/vstf/controller/vstfadm.py
blob: 068ab2e02ced8c9d675babd18e04b8e280728437 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
import sys
import logging
import json
from vstf.common.vstfcli import VstfParser
from vstf.common import cliutil, constants, unix, message
from vstf.common.log import setup_logging
import vstf.common.constants as cst
import pprint

CONN = None


def print_stdout(msg):
    # out = json.dumps(message.get_body(message.decode(msg)), indent=2)
    out = message.get_body(message.decode(msg))
    pprint.pprint(out, indent=2)


def call(msg):
    """msg must be a dict"""
    msg = message.add_context(msg, corr=message.gen_corrid())
    CONN.send(message.encode(msg))
    return message.decode(CONN.recv())


def make_msg(method, **kwargs):
    return {"method": method, "args": kwargs}


@cliutil.arg("--host", dest="host", default="", action="store", help="list nic devices of specified host")
def do_list_devs(args):
    """List the host's all netdev."""
    ret = call(make_msg("list_devs", host=args.host))
    print_stdout(ret)


@cliutil.arg("--host", dest="host", action="store", default=None,
             help="which host to run src_install.")
@cliutil.arg("--config_file", dest="config_file", action="store", default=None,
             help="the git repo config.")
def do_src_install(args):
    """work agent to pull source code and compile.
    use git as underlying mechanism, please make sure the host has access to git repo.
    """
    ret = call(make_msg("src_install", host=args.host, config_file=args.config_file))
    print_stdout(ret)


@cliutil.arg("--host", dest="host", action="store", default=None,
             help="which host to build, must exists in your config file, use default[None] value to build all hosts.")
@cliutil.arg("--model", dest="model", action="store", choices=('Tn', 'Ti', 'Tu', 'Tnv'),
             help="which model to build, if specified, the according config file /etc/vstf/env/{model}.json must exist.")
@cliutil.arg("--config_file", dest="config_file", action="store", default=None,
             help="if specified, the config file will replace the default config file from /etc/vstf/env.")
def do_apply_model(args):
    """Apply model to the host."""
    ret = call(make_msg("apply_model", host=args.host, model=args.model, config_file=args.config_file))
    print_stdout(ret)


@cliutil.arg("--host", dest="host", action="store", default=None,
             help="to which host you wish to create images")
@cliutil.arg("--config_file", dest="config_file", action="store", default=None,
             help="configuration file for image creation.")
def do_create_images(args):
    """create images on host, images are configed by configuration file."""
    ret = call(make_msg("create_images", host=args.host, config_file=args.config_file))
    print_stdout(ret)


@cliutil.arg("--host", dest="host", action="store", default=None,
             help="to which host you wish to clean images")
@cliutil.arg("--config_file", dest="config_file", action="store", default=None,
             help="configuration file for images.")
def do_clean_images(args):
    """clean images on host, images are configed by configuration file."""
    ret = call(make_msg("clean_images", host=args.host, config_file=args.config_file))
    print_stdout(ret)


@cliutil.arg("--host", dest="host", action="store", default=None,
             help="which host to clean, must exists in your config file, use default[None] value to clean all hosts.")
@cliutil.arg("--model", dest="model", action="store", choices=('Tn', 'Ti', 'Tu', 'Tnv'),
             help="if specified, the according config file /etc/vstf/env/{model}.json must exist.")
@cliutil.arg("--config_file", dest="config_file", action="store", default=None,
             help="if specified, the config file will replace the default config file from /etc/vstf/env.")
def do_disapply_model(args):
    """Apply model to the host."""
    ret = call(make_msg("disapply_model", host=args.host, model=args.model, config_file=args.config_file))
    print_stdout(ret)


@cliutil.arg("--host", dest="host", action="store", help="collect host information about cpu/mem etc")
def do_collect_host_info(args):
    """Show the host's CPU/MEN info"""
    ret = call(make_msg("collect_host_info", target=args.host))
    print_stdout(ret)


def do_show_tasks(args):
    """List history performance test tasks. Can be used by report cmd to generate reports.
    """
    ret = call(make_msg("list_tasks"))
    print_stdout(ret)


@cliutil.arg("case", action="store", help="test case like Ti-1, Tn-1, Tnv-1, Tu-1, see case definition in documents")
@cliutil.arg("tool", action="store", choices=cst.TOOLS, )
@cliutil.arg("protocol", action="store", choices=cst.TPROTOCOLS, )
@cliutil.arg("profile", action="store", choices=cst.PROFILES, )
@cliutil.arg("type", action="store", choices=cst.TTYPES)
@cliutil.arg("sizes", action="store", default="64", help='test size list "64 128"')
@cliutil.arg("--affctl", action="store_true", help="when affctl is True, it will do affctl before testing")
def do_perf_test(args):
    """Runs a quick single software performance test without envbuild and generating reports.
    Outputs the result to the stdout immediately."""
    case_info = {
        'case': args.case,
        'tool': args.tool,
        'protocol': args.protocol,
        'profile': args.profile,
        'type': args.type,
        'sizes': map(lambda x: int(x), args.sizes.strip().split())
    }
    ret = call(make_msg("run_perf_cmd",
                        case=case_info,
                        rpath=cst.REPORT_DEFAULTS,
                        affctl=args.affctl,
                        build_on=False,
                        save_on=False,
                        report_on=False,
                        mail_on=False
                        ))
    print_stdout(ret)


@cliutil.arg("-rpath",
             help="path of result",
             default=cst.REPORT_DEFAULTS,
             action="store")
@cliutil.arg("--report_off",
             help="when report_off is True, it will not generate the report",
             action="store_true")
@cliutil.arg("--mail_off",
             help="when mail_off is True, it will not send mail",
             action="store_true")
@cliutil.arg("--affctl",
             help="when affctl is True, it will do affctl before testing",
             action="store_true")
def do_batch_perf_test(args):
    """run soft performance test cases defined in /etc/vstf/perf/sw_perf.batch-settings"""
    ret = call(make_msg("run_perf_file",
                        affctl=args.affctl,
                        rpath=args.rpath,
                        report_on=not args.report_off,
                        mail_on=not args.mail_off
                        ))
    print_stdout(ret)


@cliutil.arg('-rpath',
             action='store',
             default=cst.REPORT_DEFAULTS,
             help=" the path name of test results  ")
@cliutil.arg("--mail_off",
             help="when mail_off is True, it will not send mail",
             action="store_true")
@cliutil.arg("--taskid",
             help="report depend of a history task id",
             default=-1,
             action="store")
def do_report(args):
    """generate the report from the database"""
    ret = call(make_msg("report",
                        rpath=args.rpath,
                        mail_off=args.mail_off,
                        taskid=args.taskid
                        ))
    print_stdout(ret)


@cliutil.arg("--conner",
             dest="conner",
             action="store",
             help="tester")
@cliutil.arg("--measurand",
             dest="measurand",
             action="store",
             help="tested")
@cliutil.arg("-m", "--model",
             dest="model",
             action="store",
             help="Test scene name : Tnv")
@cliutil.arg("-e", "--virtenv",
             dest="virtenv",
             action="store",
             help="virt env_build number(s): [1-8]")
@cliutil.arg("-q", "--queues",
             dest="queues",
             action="store",
             help="VM nic queues.")
@cliutil.arg("-f", "--flows",
             dest="flows",
             action="store",
             help="Flow queue(s) : [1-8]")
@cliutil.arg("-v", "--vlans",
             dest="vlans",
             action="store_true",
             help="vlan setting : 100-150;200-250")
@cliutil.arg("-d", "--direct",
             dest="direct",
             action="store",
             choices=["single", "double"],
             help="Flow Direction")
@cliutil.arg("-b", "--bind",
             dest="strategy",
             action="store",
             help="CPU bind strategy :  1 | 2 | 3 ")
@cliutil.arg("--config_file",
             dest="config_file",
             default='/etc/vstf/spirent/optimize.ini',
             action="store",
             help="config file for optimize.")
@cliutil.arg("--strategyfile",
             dest="strategyfile",
             default='/etc/vstf/spirent/strategy.ini',
             action="store",
             help="config file for strategy.")
def do_spirent_test(args):
    ret = call(make_msg("perf_test",
                        plugin="spirent",
                        conner=args.conner,
                        measurand=args.measurand,
                        virtenv=args.virtenv,
                        queues=args.queues,
                        direct=args.direct,
                        flows=args.flows,
                        strategy=args.strategy,
                        model=args.model,
                        vlans=args.vlans,
                        configfile=args.config_file,
                        strategyfile=args.strategyfile))
    print_stdout(ret)


@cliutil.arg("--host", dest="host", action="store", default=None,
             help="which host to list affctl info")
def do_affctl_list(args):
    ret = call(make_msg("affctl_list", host=args.host))
    print_stdout(ret)


def main():
    parser = VstfParser(prog="vstfadm", description="vstf administration")
    parser.set_subcommand_parser(sys.modules[__name__], "functions")
    args = parser.parse_args()
    if args.func is None:
        sys.exit(-1)
    setup_logging(level=logging.DEBUG, log_file="/var/log/vstf/vstf-adm.log", clevel=logging.INFO)
    # connect to manage
    global CONN
    try:
        CONN = unix.UdpClient()
        CONN.connect(constants.sockaddr)
    except Exception as e:
        raise e

    args.func(args)
    # call functions of manage
    sys.exit(CONN.close())