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", help="list nic devices of specified host")
40 def do_list_devs(args):
41 """List the host's all netdev."""
42 ret = call(make_msg("list_devs", host=args.host))
46 @cliutil.arg("--host", dest="host", action="store", default=None,
47 help="which host to run src_install.")
48 @cliutil.arg("--config_file", dest="config_file", action="store", default=None,
49 help="the git repo config.")
50 def do_src_install(args):
51 """work agent to pull source code and compile.
52 use git as underlying mechanism, please make sure the host has access to git repo.
54 ret = call(make_msg("src_install", host=args.host, config_file=args.config_file))
58 @cliutil.arg("--host", dest="host", action="store", default=None,
59 help="which host to build, must exists in your config file, use default[None] value to build all hosts.")
60 @cliutil.arg("--model", dest="model", action="store", choices=('Tn', 'Ti', 'Tu', 'Tnv'),
61 help="which model to build, if specified, the according config file /etc/vstf/env/{model}.json must exist.")
62 @cliutil.arg("--config_file", dest="config_file", action="store", default=None,
63 help="if specified, the config file will replace the default config file from /etc/vstf/env.")
64 def do_apply_model(args):
65 """Apply model to the host."""
66 ret = call(make_msg("apply_model", host=args.host, model=args.model, config_file=args.config_file))
70 @cliutil.arg("--host", dest="host", action="store", default=None,
71 help="to which host you wish to create images")
72 @cliutil.arg("--config_file", dest="config_file", action="store", default=None,
73 help="configuration file for image creation.")
74 def do_create_images(args):
75 """create images on host, images are configed by configuration file."""
76 ret = call(make_msg("create_images", host=args.host, config_file=args.config_file))
80 @cliutil.arg("--host", dest="host", action="store", default=None,
81 help="to which host you wish to clean images")
82 @cliutil.arg("--config_file", dest="config_file", action="store", default=None,
83 help="configuration file for images.")
84 def do_clean_images(args):
85 """clean images on host, images are configed by configuration file."""
86 ret = call(make_msg("clean_images", host=args.host, config_file=args.config_file))
90 @cliutil.arg("--host", dest="host", action="store", default=None,
91 help="which host to clean, must exists in your config file, use default[None] value to clean all hosts.")
92 @cliutil.arg("--model", dest="model", action="store", choices=('Tn', 'Ti', 'Tu', 'Tnv'),
93 help="if specified, the according config file /etc/vstf/env/{model}.json must exist.")
94 @cliutil.arg("--config_file", dest="config_file", action="store", default=None,
95 help="if specified, the config file will replace the default config file from /etc/vstf/env.")
96 def do_disapply_model(args):
97 """Apply model to the host."""
98 ret = call(make_msg("disapply_model", host=args.host, model=args.model, config_file=args.config_file))
102 @cliutil.arg("--host", dest="host", action="store", help="collect host information about cpu/mem etc")
103 def do_collect_host_info(args):
104 """Show the host's CPU/MEN info"""
105 ret = call(make_msg("collect_host_info", target=args.host))
109 def do_show_tasks(args):
110 """List history performance test tasks. Can be used by report cmd to generate reports.
112 ret = call(make_msg("list_tasks"))
116 @cliutil.arg("case", action="store", help="test case like Ti-1, Tn-1, Tnv-1, Tu-1, see case definition in documents")
117 @cliutil.arg("tool", action="store", choices=cst.TOOLS)
118 @cliutil.arg("protocol", action="store", choices=cst.TPROTOCOLS)
119 @cliutil.arg("type", action="store", choices=cst.TTYPES)
120 @cliutil.arg("sizes", action="store", default="64", help='test size list "64 128"')
121 @cliutil.arg("--affctl", action="store_true", help="when affctl is True, it will do affctl before testing")
122 def do_perf_test(args):
123 """Runs a quick single software performance test without envbuild and generating reports.
124 Outputs the result to the stdout immediately."""
128 'protocol': args.protocol,
130 'sizes': map(lambda x: int(x), args.sizes.strip().split())
132 ret = call(make_msg("run_perf_cmd",
134 rpath=cst.REPORT_DEFAULTS,
144 @cliutil.arg("-rpath",
145 help="path of result",
146 default=cst.REPORT_DEFAULTS,
148 @cliutil.arg("--report_off",
149 help="when report_off is True, it will not generate the report",
151 @cliutil.arg("--mail_off",
152 help="when mail_off is True, it will not send mail",
154 @cliutil.arg("--affctl",
155 help="when affctl is True, it will do affctl before testing",
157 def do_batch_perf_test(args):
158 """run soft performance test cases defined in /etc/vstf/perf/sw_perf.batch-settings"""
159 ret = call(make_msg("run_perf_file",
162 report_on=not args.report_off,
163 mail_on=not args.mail_off
168 @cliutil.arg('-rpath',
170 default=cst.REPORT_DEFAULTS,
171 help=" the path name of test results ")
172 @cliutil.arg("--mail_off",
173 help="when mail_off is True, it will not send mail",
175 @cliutil.arg("--taskid",
176 help="report depend of a history task id",
180 """generate the report from the database"""
181 ret = call(make_msg("report",
183 mail_off=args.mail_off,
189 @cliutil.arg("--conner",
193 @cliutil.arg("--measurand",
197 @cliutil.arg("-m", "--model",
200 help="Test scene name : Tnv")
201 @cliutil.arg("-e", "--virtenv",
204 help="virt env_build number(s): [1-8]")
205 @cliutil.arg("-q", "--queues",
208 help="VM nic queues.")
209 @cliutil.arg("-f", "--flows",
212 help="Flow queue(s) : [1-8]")
213 @cliutil.arg("-v", "--vlans",
216 help="vlan setting : 100-150;200-250")
217 @cliutil.arg("-d", "--direct",
220 choices=["single", "double"],
221 help="Flow Direction")
222 @cliutil.arg("-b", "--bind",
225 help="CPU bind strategy : 1 | 2 | 3 ")
226 @cliutil.arg("--config_file",
228 default='/etc/vstf/spirent/optimize.ini',
230 help="config file for optimize.")
231 @cliutil.arg("--strategyfile",
233 default='/etc/vstf/spirent/strategy.ini',
235 help="config file for strategy.")
236 def do_spirent_test(args):
237 ret = call(make_msg("perf_test",
240 measurand=args.measurand,
241 virtenv=args.virtenv,
245 strategy=args.strategy,
248 configfile=args.config_file,
249 strategyfile=args.strategyfile))
253 @cliutil.arg("--host", dest="host", action="store", default=None,
254 help="which host to list affctl info")
255 def do_affctl_list(args):
256 ret = call(make_msg("affctl_list", host=args.host))
260 @cliutil.arg("head", action="store", help="ip of head")
261 @cliutil.arg("tail", action="store", help="ip of tail")
262 def do_settings(args):
263 ret = call(make_msg("settings", head=args.head, tail=args.tail))
268 parser = VstfParser(prog="vstfadm", description="vstf administration")
269 parser.set_subcommand_parser(sys.modules[__name__], "functions")
270 args = parser.parse_args()
271 if args.func is None:
273 setup_logging(level=logging.DEBUG, log_file="/var/log/vstf/vstf-adm.log", clevel=logging.INFO)
277 CONN = unix.UdpClient()
278 CONN.connect(constants.sockaddr)
279 except Exception as e:
283 # call functions of manage
284 sys.exit(CONN.close())