JIRA: BOTTLENECKS-29
[bottlenecks.git] / vstf / vstf / controller / fabricant.py
1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
3 #
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 ##############################################################################
9
10 from vstf.rpc_frame_work import constant as const
11 import vstf.common.constants as cst
12
13
14 class Fabricant(object):
15     def __init__(self, target, conn):
16         self.conn = conn
17         self.target = target
18
19         self.all_commands = self.declare_commands
20         self.instance_commands()
21
22     @property
23     def declare_commands(self):
24         driver = {"install_drivers", "clean_drivers", "autoneg_on", "autoneg_off", "autoneg_query"}
25
26         builder = {"build_env", "clean_env"}
27
28         cpu = {"affctl_load", "affctl_list", "run_cpuwatch", "kill_cpuwatch"}
29
30         perf = {"perf_run", "run_vnstat", "kill_vnstat", "force_clean"}
31
32         device_mgr = {"get_device_detail", "list_nic_devices", "get_device_verbose"}
33
34         netns = {"clean_all_namespace", "config_dev", "recover_dev", "ping"}
35
36         collect = {"collect_host_info"}
37
38         cmdline = {"execute"}
39
40         spirent = {"send_packet", "stop_flow", "mac_learning", "run_rfc2544suite", "run_rfc2544_throughput",
41                    "run_rfc2544_frameloss", "run_rfc2544_latency"}
42
43         equalizer = {"get_numa_core", "get_nic_numa", "get_nic_interrupt_proc", "get_vm_info", "bind_cpu",
44                      "catch_thread_info"}
45
46         return driver | cpu | builder | perf | device_mgr | netns | cmdline | collect | spirent | equalizer
47
48     def instance_commands(self):
49         for command in self.all_commands:
50             setattr(self, command, self.__transfer_msg(command))
51
52     def __transfer_msg(self, command):
53         def infunc(timeout=cst.TIMEOUT, **kwargs):
54             msg = self.conn.make_msg(command, **kwargs)
55             if self.target:
56                 return self.conn.call(msg, self.target, timeout)
57             return None
58
59         infunc.__name__ = command
60         return infunc