summaryrefslogtreecommitdiffstats
path: root/testsuites/vstf/vstf_scripts/vstf/controller/fabricant.py
blob: 3f6978e46fd554ed3dc9521079fc471a315225f2 (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
##############################################################################
# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################

from vstf.rpc_frame_work import constant as const
import vstf.common.constants as cst


class Fabricant(object):

    def __init__(self, target, conn):
        self.conn = conn
        self.target = target

        self.all_commands = self.declare_commands
        self.instance_commands()

    @property
    def declare_commands(self):
        driver = {
            "install_drivers",
            "clean_drivers",
            "autoneg_on",
            "autoneg_off",
            "autoneg_query"}

        builder = {"build_env", "clean_env"}

        cpu = {"affctl_load", "affctl_list", "run_cpuwatch", "kill_cpuwatch"}

        perf = {"perf_run", "run_vnstat", "kill_vnstat", "force_clean"}

        device_mgr = {
            "get_device_detail",
            "list_nic_devices",
            "get_device_verbose"}

        netns = {"clean_all_namespace", "config_dev", "recover_dev", "ping"}

        collect = {"collect_host_info"}

        cmdline = {"execute"}

        spirent = {
            "send_packet",
            "stop_flow",
            "mac_learning",
            "run_rfc2544suite",
            "run_rfc2544_throughput",
            "run_rfc2544_frameloss",
            "run_rfc2544_latency"}

        equalizer = {
            "get_numa_core",
            "get_nic_numa",
            "get_nic_interrupt_proc",
            "get_vm_info",
            "bind_cpu",
            "catch_thread_info"}

        return driver | cpu | builder | perf | device_mgr | netns | cmdline | collect | spirent | equalizer

    def instance_commands(self):
        for command in self.all_commands:
            setattr(self, command, self.__transfer_msg(command))

    def __transfer_msg(self, command):
        def infunc(timeout=cst.TIMEOUT, **kwargs):
            msg = self.conn.make_msg(command, **kwargs)
            if self.target:
                return self.conn.call(msg, self.target, timeout)
            return None

        infunc.__name__ = command
        return infunc