aboutsummaryrefslogtreecommitdiffstats
path: root/resources/libraries/python/DMM/SingleCliSer.py
blob: e96843ac360bdd53f9fd79f9bd594f9cd3183207 (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# Copyright (c) 2018 Huawei Technologies Co.,Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


"""
This module exists to provide the vs_epoll ping test for DMM on topology nodes.
"""
import time

from resources.libraries.python.ssh import exec_cmd_no_error
from resources.libraries.python.DMM.DMMConstants import DMMConstants as con
from resources.libraries.python.topology import Topology

class SingleCliSer(object):
    """Test the DMM vs_epoll ping function."""

    @staticmethod
    def exec_the_base_vs_epoll_test(dut1_node, dut2_node,
                                    dut1_if_name, dut2_if_name,
                                    dut1_if_ip, dut2_if_ip):
        """
        Perform base vs_epoll test on DUT's.

        :param dut1_node: Node to execute vs_epoll on.
        :param dut2_node: Node to execute vc_common on.
        :param dut1_if_name: DUT1 to DUT2 interface name.
        :param dut2_if_name: DUT2 to DUT1 interface name.
        :param dut1_if_ip: DUT1 to DUT2 interface ip.
        :param dut2_if_ip: DUT2 to DUT1 interface ip.
        :type dut1_node: dict
        :type dut2_node: dict
        :type dut1_if_name: str
        :type dut2_if_name: str
        :type dut1_if_ip: str
        :type dut2_if_ip: str
        """
        cmd = 'cd {0}/{1} && ./run_dmm.sh {2} {3} {4} {5} ' \
        .format(con.REMOTE_FW_DIR, con.DMM_SCRIPTS, 0, dut1_if_name,
                dut1_if_ip, dut2_if_ip)

        cmd += '2>&1 | tee log_run_dmm.txt &'
        exec_cmd_no_error(dut1_node, cmd)
        time.sleep(10)

        cmd = 'cd {0}/{1} && ./run_dmm.sh {2} {3} {4} {5} ' \
        .format(con.REMOTE_FW_DIR, con.DMM_SCRIPTS, 1, dut2_if_name,
                dut1_if_ip, dut2_if_ip)

        cmd += '2>&1 | tee log_run_dmm.txt'
        exec_cmd_no_error(dut2_node, cmd)

    @staticmethod
    def get_the_test_result(dut_node):
        """
        After executing exec_the_base_vs_epoll_test, use this
        to get the test result.

        :param dut_node: Node to get the test result on.
        :type dut_node: dict
        :returns: Word count of "send 50000" in the log.
        :rtype: str
        """
        cmd = 'cat {0}/{1}/log_run_dmm.txt | grep "send 50000" | wc -l' \
        .format(con.REMOTE_FW_DIR, con.DMM_SCRIPTS)
        (stdout, _) = exec_cmd_no_error(dut_node, cmd)
        return stdout

    @staticmethod
    def echo_dmm_logs(dut_node):
        """
        Get the prerequisites installation log from DUT.

        :param dut_node: Node to get the installation log on.
        :type dut_node: dict
        """
        cmd = 'cat {0}/{1}/log_install_prereq.txt' \
        .format(con.REMOTE_FW_DIR, con.DMM_SCRIPTS)
        exec_cmd_no_error(dut_node, cmd)

    @staticmethod
    def exec_the_base_lwip_test(dut1_node, dut2_node,
                                dut1_if_name, dut2_if_name,
                                dut1_if_ip, dut2_if_ip):
        """Test DMM with LWIP.

        :param dut1_node: Node to execute vs_epoll on.
        :param dut2_node: Node to execute vc_common on.
        :param dut1_if_name: DUT1 to DUT2 interface name.
        :param dut2_if_name: DUT2 to DUT1 interface name.
        :param dut1_if_ip: DUT1 to DUT2 interface ip.
        :param dut2_if_ip: DUT2 to DUT1 interface ip.
        :type dut1_node: dict
        :type dut2_node: dict
        :type dut1_if_name: str
        :type dut2_if_name: str
        :type dut1_if_ip: str
        :type dut2_if_ip: str
        """
        cmd = 'cd {0}/{1} && ./run_dmm_with_lwip.sh {2} {3} {4} {5} ' \
            .format(con.REMOTE_FW_DIR, con.DMM_SCRIPTS, 0, dut1_if_name,
                    dut1_if_ip, dut2_if_ip)

        cmd += '2>&1 | tee log_run_dmm_with_lwip.txt &'
        exec_cmd_no_error(dut1_node, cmd)
        time.sleep(10)

        cmd = 'cd {0}/{1} && ./run_dmm_with_lwip.sh {2} {3} {4} {5} ' \
            .format(con.REMOTE_FW_DIR, con.DMM_SCRIPTS, 1, dut2_if_name,
                    dut1_if_ip, dut2_if_ip)

        cmd += '2>&1 | tee log_run_dmm_with_lwip.txt'
        exec_cmd_no_error(dut2_node, cmd)

    @staticmethod
    def get_lwip_test_result(dut_node):
        """
        After executing exec_the_base_lwip_test, use this
        to get the test result.

        :param dut_node: Node to get the test result on.
        :type dut_node: dict
        :returns: Word count of "send 50" in the log.
        :rtype: str
        """
        cmd = 'cat {0}/{1}/log_run_dmm_with_lwip.txt | grep "send 50" | wc -l' \
        .format(con.REMOTE_FW_DIR, con.DMM_SCRIPTS)

        (stdout, _) = exec_cmd_no_error(dut_node, cmd)
        return stdout

    @staticmethod
    def echo_running_log(dut1_node, dut2_node):
        """
        Get the running log.

        :param dut1_node: Node to get the running log on.
        :param dut2_node: Node to get the running log on.
        :type dut1_node: dict
        :type dut2_node: dict
        """
        cmd = 'cat /var/log/nStack/running.log'
        exec_cmd_no_error(dut1_node, cmd)
        exec_cmd_no_error(dut2_node, cmd)

    @staticmethod
    def echo_dpdk_log(dut1_node, dut2_node):
        """
        Get the dpdk log.

        :param dut1_node: Node to get the DPDK log on.
        :param dut2_node: Node to get the DPDK log on.
        :type dut1_node: dict
        :type dut2_node: dict
        """
        cmd = 'cat /var/log/nstack-dpdk/nstack_dpdk.log'
        exec_cmd_no_error(dut1_node, cmd)
        exec_cmd_no_error(dut2_node, cmd)

    @staticmethod
    def dmm_get_interface_name(dut_node, dut_interface):
        """
        Get the interface name.

        :param dut_node: Node to get the interface name on.
        :param dut_interface: Interface key.
        :type dut_node: dict
        :type dut_interface: str
        :returns: Interface name.
        :rtype: str
        """
        mac = Topology.get_interface_mac(dut_node, dut_interface)
        cmd = 'ifconfig -a | grep {0}'.format(mac)
        (stdout, _) = exec_cmd_no_error(dut_node, cmd)
        interface_name = stdout.split(' ', 1)[0]
        return interface_name

    @staticmethod
    def set_dmm_interface_address(dut_node, ifname, ip_addr, ip4_prefix):
        """
        Flush ip, set ip, set interface up.

        :param dut_node: Node to set the interface address on.
        :param ifname: Interface name.
        :param ip_addr: IP address to configure.
        :param ip4_prefix: Prefix length.
        :type dut_node: dict
        :type ifname: str
        :type ip_addr: str
        :type ip4_prefix: int
        """
        cmd = 'sudo ip -4 addr flush dev {}'.format(ifname)
        exec_cmd_no_error(dut_node, cmd)
        cmd = 'sudo ip addr add {}/{} dev {}'\
            .format(ip_addr, ip4_prefix, ifname)
        exec_cmd_no_error(dut_node, cmd)
        cmd = 'sudo ip link set {0} up'.format(ifname)
        exec_cmd_no_error(dut_node, cmd)