4 from vstf.common.vstfcli import VstfParser
5 from vstf.common import cliutil, constants, unix, message
6 from vstf.common.log import setup_logging
7 import vstf.common.constants as cst
13 def print_stdout(msg):
14 # out = json.dumps(message.get_body(message.decode(msg)), indent=2)
15 out = message.get_body(message.decode(msg))
16 pprint.pprint(out, indent=2)
20 """msg must be a dict"""
21 msg = message.add_context(msg, corr=message.gen_corrid())
22 CONN.send(message.encode(msg))
23 return message.decode(CONN.recv())
26 def make_msg(method, **kwargs):
27 return {"method": method, "args": kwargs}
30 @cliutil.arg("--host", dest="host", default="", action="store", help="list nic devices of specified host")
31 def do_list_devs(args):
32 """List the host's all netdev."""
33 ret = call(make_msg("list_devs", host=args.host))
37 @cliutil.arg("--host", dest="host", action="store", default=None,
38 help="which host to run src_install.")
39 @cliutil.arg("--config_file", dest="config_file", action="store", default=None,
40 help="the git repo config.")
41 def do_src_install(args):
42 """work agent to pull source code and compile.
43 use git as underlying mechanism, please make sure the host has access to git repo.
45 ret = call(make_msg("src_install", host=args.host, config_file=args.config_file))
49 @cliutil.arg("--host", dest="host", action="store", default=None,
50 help="which host to build, must exists in your config file, use default[None] value to build all hosts.")
51 @cliutil.arg("--model", dest="model", action="store", choices=('Tn', 'Ti', 'Tu', 'Tnv'),
52 help="which model to build, if specified, the according config file /etc/vstf/env/{model}.json must exist.")
53 @cliutil.arg("--config_file", dest="config_file", action="store", default=None,
54 help="if specified, the config file will replace the default config file from /etc/vstf/env.")
55 def do_apply_model(args):
56 """Apply model to the host."""
57 ret = call(make_msg("apply_model", host=args.host, model=args.model, config_file=args.config_file))
61 @cliutil.arg("--host", dest="host", action="store", default=None,
62 help="to which host you wish to create images")
63 @cliutil.arg("--config_file", dest="config_file", action="store", default=None,
64 help="configuration file for image creation.")
65 def do_create_images(args):
66 """create images on host, images are configed by configuration file."""
67 ret = call(make_msg("create_images", host=args.host, config_file=args.config_file))
71 @cliutil.arg("--host", dest="host", action="store", default=None,
72 help="to which host you wish to clean images")
73 @cliutil.arg("--config_file", dest="config_file", action="store", default=None,
74 help="configuration file for images.")
75 def do_clean_images(args):
76 """clean images on host, images are configed by configuration file."""
77 ret = call(make_msg("clean_images", host=args.host, config_file=args.config_file))
81 @cliutil.arg("--host", dest="host", action="store", default=None,
82 help="which host to clean, must exists in your config file, use default[None] value to clean all hosts.")
83 @cliutil.arg("--model", dest="model", action="store", choices=('Tn', 'Ti', 'Tu', 'Tnv'),
84 help="if specified, the according config file /etc/vstf/env/{model}.json must exist.")
85 @cliutil.arg("--config_file", dest="config_file", action="store", default=None,
86 help="if specified, the config file will replace the default config file from /etc/vstf/env.")
87 def do_disapply_model(args):
88 """Apply model to the host."""
89 ret = call(make_msg("disapply_model", host=args.host, model=args.model, config_file=args.config_file))
93 @cliutil.arg("--host", dest="host", action="store", help="collect host information about cpu/mem etc")
94 def do_collect_host_info(args):
95 """Show the host's CPU/MEN info"""
96 ret = call(make_msg("collect_host_info", target=args.host))
100 def do_show_tasks(args):
101 """List history performance test tasks. Can be used by report cmd to generate reports.
103 ret = call(make_msg("list_tasks"))
107 @cliutil.arg("case", action="store", help="test case like Ti-1, Tn-1, Tnv-1, Tu-1, see case definition in documents")
108 @cliutil.arg("tool", action="store", choices=cst.TOOLS, )
109 @cliutil.arg("protocol", action="store", choices=cst.TPROTOCOLS, )
110 @cliutil.arg("profile", action="store", choices=cst.PROFILES, )
111 @cliutil.arg("type", action="store", choices=cst.TTYPES)
112 @cliutil.arg("sizes", action="store", default="64", help='test size list "64 128"')
113 @cliutil.arg("--affctl", action="store_true", help="when affctl is True, it will do affctl before testing")
114 def do_perf_test(args):
115 """Runs a quick single software performance test without envbuild and generating reports.
116 Outputs the result to the stdout immediately."""
120 'protocol': args.protocol,
121 'profile': args.profile,
123 'sizes': map(lambda x: int(x), args.sizes.strip().split())
125 ret = call(make_msg("run_perf_cmd",
127 rpath=cst.REPORT_DEFAULTS,
137 @cliutil.arg("-rpath",
138 help="path of result",
139 default=cst.REPORT_DEFAULTS,
141 @cliutil.arg("--report_off",
142 help="when report_off is True, it will not generate the report",
144 @cliutil.arg("--mail_off",
145 help="when mail_off is True, it will not send mail",
147 @cliutil.arg("--affctl",
148 help="when affctl is True, it will do affctl before testing",
150 def do_batch_perf_test(args):
151 """run soft performance test cases defined in /etc/vstf/perf/sw_perf.batch-settings"""
152 ret = call(make_msg("run_perf_file",
155 report_on=not args.report_off,
156 mail_on=not args.mail_off
161 @cliutil.arg('-rpath',
163 default=cst.REPORT_DEFAULTS,
164 help=" the path name of test results ")
165 @cliutil.arg("--mail_off",
166 help="when mail_off is True, it will not send mail",
168 @cliutil.arg("--taskid",
169 help="report depend of a history task id",
173 """generate the report from the database"""
174 ret = call(make_msg("report",
176 mail_off=args.mail_off,
182 @cliutil.arg("--conner",
186 @cliutil.arg("--measurand",
190 @cliutil.arg("-m", "--model",
193 help="Test scene name : Tnv")
194 @cliutil.arg("-e", "--virtenv",
197 help="virt env_build number(s): [1-8]")
198 @cliutil.arg("-q", "--queues",
201 help="VM nic queues.")
202 @cliutil.arg("-f", "--flows",
205 help="Flow queue(s) : [1-8]")
206 @cliutil.arg("-v", "--vlans",
209 help="vlan setting : 100-150;200-250")
210 @cliutil.arg("-d", "--direct",
213 choices=["single", "double"],
214 help="Flow Direction")
215 @cliutil.arg("-b", "--bind",
218 help="CPU bind strategy : 1 | 2 | 3 ")
219 @cliutil.arg("--config_file",
221 default='/etc/vstf/spirent/optimize.ini',
223 help="config file for optimize.")
224 @cliutil.arg("--strategyfile",
226 default='/etc/vstf/spirent/strategy.ini',
228 help="config file for strategy.")
229 def do_spirent_test(args):
230 ret = call(make_msg("perf_test",
233 measurand=args.measurand,
234 virtenv=args.virtenv,
238 strategy=args.strategy,
241 configfile=args.config_file,
242 strategyfile=args.strategyfile))
246 @cliutil.arg("--host", dest="host", action="store", default=None,
247 help="which host to list affctl info")
248 def do_affctl_list(args):
249 ret = call(make_msg("affctl_list", host=args.host))
254 parser = VstfParser(prog="vstfadm", description="vstf administration")
255 parser.set_subcommand_parser(sys.modules[__name__], "functions")
256 args = parser.parse_args()
257 if args.func is None:
259 setup_logging(level=logging.DEBUG, log_file="/var/log/vstf/vstf-adm.log", clevel=logging.INFO)
263 CONN = unix.UdpClient()
264 CONN.connect(constants.sockaddr)
265 except Exception as e:
269 # call functions of manage
270 sys.exit(CONN.close())