1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
13 from vstf.common.vstfcli import VstfParser
14 from vstf.common import cliutil, constants, unix, message
15 from vstf.common.log import setup_logging
16 import vstf.common.constants as cst
22 def print_stdout(msg):
23 # out = json.dumps(message.get_body(message.decode(msg)), indent=2)
24 out = message.get_body(message.decode(msg))
25 pprint.pprint(out, indent=2)
29 """msg must be a dict"""
30 msg = message.add_context(msg, corr=message.gen_corrid())
31 CONN.send(message.encode(msg))
32 return message.decode(CONN.recv())
35 def make_msg(method, **kwargs):
36 return {"method": method, "args": kwargs}
39 @cliutil.arg("--host", dest="host", default="", action="store",
40 help="list nic devices of specified host")
41 def do_list_devs(args):
42 """List the host's all netdev."""
43 ret = call(make_msg("list_devs", host=args.host))
47 @cliutil.arg("--host", dest="host", action="store", default=None,
48 help="which host to run src_install.")
49 @cliutil.arg("--config_file", dest="config_file", action="store", default=None,
50 help="the git repo config.")
51 def do_src_install(args):
52 """work agent to pull source code and compile.
53 use git as underlying mechanism, please make sure the host has access to git repo.
59 config_file=args.config_file))
68 help="which host to build, must exists in your config file, use default[None] value to build all hosts.")
78 help="which model to build, if specified, the according config file /etc/vstf/env/{model}.json must exist.")
84 help="if specified, the config file will replace the default config file from /etc/vstf/env.")
85 def do_apply_model(args):
86 """Apply model to the host."""
92 config_file=args.config_file))
96 @cliutil.arg("--host", dest="host", action="store", default=None,
97 help="to which host you wish to create images")
98 @cliutil.arg("--config_file", dest="config_file", action="store", default=None,
99 help="configuration file for image creation.")
100 def do_create_images(args):
101 """create images on host, images are configed by configuration file."""
106 config_file=args.config_file))
110 @cliutil.arg("--host", dest="host", action="store", default=None,
111 help="to which host you wish to clean images")
112 @cliutil.arg("--config_file", dest="config_file", action="store", default=None,
113 help="configuration file for images.")
114 def do_clean_images(args):
115 """clean images on host, images are configed by configuration file."""
120 config_file=args.config_file))
129 help="which host to clean, must exists in your config file, use default[None] value to clean all hosts.")
139 help="if specified, the according config file /etc/vstf/env/{model}.json must exist.")
145 help="if specified, the config file will replace the default config file from /etc/vstf/env.")
146 def do_disapply_model(args):
147 """Apply model to the host."""
153 config_file=args.config_file))
157 @cliutil.arg("--host", dest="host", action="store",
158 help="collect host information about cpu/mem etc")
159 def do_collect_host_info(args):
160 """Show the host's CPU/MEN info"""
161 ret = call(make_msg("collect_host_info", target=args.host))
165 def do_show_tasks(args):
166 """List history performance test tasks. Can be used by report cmd to generate reports.
168 ret = call(make_msg("list_tasks"))
175 help="test case like Ti-1, Tn-1, Tnv-1, Tu-1, see case definition in documents")
176 @cliutil.arg("tool", action="store", choices=cst.TOOLS)
177 @cliutil.arg("protocol", action="store", choices=cst.TPROTOCOLS)
178 @cliutil.arg("type", action="store", choices=cst.TTYPES)
183 help='test size list "64 128"')
187 help="when affctl is True, it will do affctl before testing")
188 def do_perf_test(args):
189 """Runs a quick single software performance test without envbuild and generating reports.
190 Outputs the result to the stdout immediately."""
194 'protocol': args.protocol,
196 'sizes': map(lambda x: int(x), args.sizes.strip().split())
198 ret = call(make_msg("run_perf_cmd",
200 rpath=cst.REPORT_DEFAULTS,
210 @cliutil.arg("-rpath",
211 help="path of result",
212 default=cst.REPORT_DEFAULTS,
214 @cliutil.arg("--report_off",
215 help="when report_off is True, it will not generate the report",
217 @cliutil.arg("--mail_off",
218 help="when mail_off is True, it will not send mail",
220 @cliutil.arg("--affctl",
221 help="when affctl is True, it will do affctl before testing",
223 def do_batch_perf_test(args):
224 """run soft performance test cases defined in /etc/vstf/perf/sw_perf.batch-settings"""
225 ret = call(make_msg("run_perf_file",
228 report_on=not args.report_off,
229 mail_on=not args.mail_off
234 @cliutil.arg('-rpath',
236 default=cst.REPORT_DEFAULTS,
237 help=" the path name of test results ")
238 @cliutil.arg("--mail_off",
239 help="when mail_off is True, it will not send mail",
241 @cliutil.arg("--taskid",
242 help="report depend of a history task id",
246 """generate the report from the database"""
247 ret = call(make_msg("report",
249 mail_off=args.mail_off,
255 @cliutil.arg("--conner",
259 @cliutil.arg("--measurand",
263 @cliutil.arg("-m", "--model",
266 help="Test scene name : Tnv")
267 @cliutil.arg("-e", "--virtenv",
270 help="virt env_build number(s): [1-8]")
271 @cliutil.arg("-q", "--queues",
274 help="VM nic queues.")
275 @cliutil.arg("-f", "--flows",
278 help="Flow queue(s) : [1-8]")
279 @cliutil.arg("-v", "--vlans",
282 help="vlan setting : 100-150;200-250")
283 @cliutil.arg("-d", "--direct",
286 choices=["single", "double"],
287 help="Flow Direction")
288 @cliutil.arg("-b", "--bind",
291 help="CPU bind strategy : 1 | 2 | 3 ")
292 @cliutil.arg("--config_file",
294 default='/etc/vstf/spirent/optimize.ini',
296 help="config file for optimize.")
297 @cliutil.arg("--strategyfile",
299 default='/etc/vstf/spirent/strategy.ini',
301 help="config file for strategy.")
302 def do_spirent_test(args):
303 ret = call(make_msg("perf_test",
306 measurand=args.measurand,
307 virtenv=args.virtenv,
311 strategy=args.strategy,
314 configfile=args.config_file,
315 strategyfile=args.strategyfile))
319 @cliutil.arg("--host", dest="host", action="store", default=None,
320 help="which host to list affctl info")
321 def do_affctl_list(args):
322 ret = call(make_msg("affctl_list", host=args.host))
326 @cliutil.arg("head", action="store", help="ip of head")
327 @cliutil.arg("tail", action="store", help="ip of tail")
328 def do_settings(args):
329 ret = call(make_msg("settings", head=args.head, tail=args.tail))
334 parser = VstfParser(prog="vstfadm", description="vstf administration")
335 parser.set_subcommand_parser(sys.modules[__name__], "functions")
336 args = parser.parse_args()
337 if args.func is None:
341 log_file="/var/log/vstf/vstf-adm.log",
346 CONN = unix.UdpClient()
347 CONN.connect(constants.sockaddr)
348 except Exception as e:
352 # call functions of manage
353 sys.exit(CONN.close())