integration of DMM+lwip testscripts
[csit.git] / resources / libraries / python / DMM / SingleCliSer.py
1 # Copyright (c) 2018 Huawei Technologies Co.,Ltd.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
5 #
6 #     http://www.apache.org/licenses/LICENSE-2.0
7 #
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
13
14
15 """
16 This module exists to provide the vs_epoll ping test for DMM on topology nodes.
17 """
18 import time
19
20 from resources.libraries.python.ssh import exec_cmd_no_error
21 from resources.libraries.python.DMM.DMMConstants import DMMConstants as con
22 from resources.libraries.python.topology import Topology
23
24 class SingleCliSer(object):
25     """Test the DMM vs_epoll ping function."""
26
27     @staticmethod
28     def exec_the_base_vs_epoll_test(dut1_node, dut2_node,
29                                     dut1_if_name, dut2_if_name,
30                                     dut1_if_ip, dut2_if_ip):
31         """
32         Perform base vs_epoll test on DUT's.
33
34         :param dut1_node: Node to execute vs_epoll on.
35         :param dut2_node: Node to execute vc_common on.
36         :param dut1_if_name: DUT1 to DUT2 interface name.
37         :param dut2_if_name: DUT2 to DUT1 interface name.
38         :param dut1_if_ip: DUT1 to DUT2 interface ip.
39         :param dut2_if_ip: DUT2 to DUT1 interface ip.
40         :type dut1_node: dict
41         :type dut2_node: dict
42         :type dut1_if_name: str
43         :type dut2_if_name: str
44         :type dut1_if_ip: str
45         :type dut2_if_ip: str
46         """
47         cmd = 'cd {0}/{1} && ./run_dmm.sh {2} {3} {4} {5} ' \
48         .format(con.REMOTE_FW_DIR, con.DMM_SCRIPTS, 0, dut1_if_name,
49                 dut1_if_ip, dut2_if_ip)
50
51         cmd += '2>&1 | tee log_run_dmm.txt &'
52         exec_cmd_no_error(dut1_node, cmd)
53         time.sleep(10)
54
55         cmd = 'cd {0}/{1} && ./run_dmm.sh {2} {3} {4} {5} ' \
56         .format(con.REMOTE_FW_DIR, con.DMM_SCRIPTS, 1, dut2_if_name,
57                 dut1_if_ip, dut2_if_ip)
58
59         cmd += '2>&1 | tee log_run_dmm.txt'
60         exec_cmd_no_error(dut2_node, cmd)
61
62     @staticmethod
63     def get_the_test_result(dut_node):
64         """
65         After executing exec_the_base_vs_epoll_test, use this
66         to get the test result.
67
68         :param dut_node: Node to get the test result on.
69         :type dut_node: dict
70         :returns: Word count of "send 50000" in the log.
71         :rtype: str
72         """
73         cmd = 'cat {0}/{1}/log_run_dmm.txt | grep "send 50000" | wc -l' \
74         .format(con.REMOTE_FW_DIR, con.DMM_SCRIPTS)
75         (stdout, _) = exec_cmd_no_error(dut_node, cmd)
76         return stdout
77
78     @staticmethod
79     def echo_dmm_logs(dut_node):
80         """
81         Get the prerequisites installation log from DUT.
82
83         :param dut_node: Node to get the installation log on.
84         :type dut_node: dict
85         """
86         cmd = 'cat {0}/{1}/log_install_prereq.txt' \
87         .format(con.REMOTE_FW_DIR, con.DMM_SCRIPTS)
88         exec_cmd_no_error(dut_node, cmd)
89
90     @staticmethod
91     def exec_the_base_lwip_test(dut1_node, dut2_node,
92                                 dut1_if_name, dut2_if_name,
93                                 dut1_if_ip, dut2_if_ip):
94         """Test DMM with LWIP.
95
96         :param dut1_node: Node to execute vs_epoll on.
97         :param dut2_node: Node to execute vc_common on.
98         :param dut1_if_name: DUT1 to DUT2 interface name.
99         :param dut2_if_name: DUT2 to DUT1 interface name.
100         :param dut1_if_ip: DUT1 to DUT2 interface ip.
101         :param dut2_if_ip: DUT2 to DUT1 interface ip.
102         :type dut1_node: dict
103         :type dut2_node: dict
104         :type dut1_if_name: str
105         :type dut2_if_name: str
106         :type dut1_if_ip: str
107         :type dut2_if_ip: str
108         """
109         cmd = 'cd {0}/{1} && ./run_dmm_with_lwip.sh {2} {3} {4} {5} ' \
110             .format(con.REMOTE_FW_DIR, con.DMM_SCRIPTS, 0, dut1_if_name,
111                     dut1_if_ip, dut2_if_ip)
112
113         cmd += '2>&1 | tee log_run_dmm_with_lwip.txt &'
114         exec_cmd_no_error(dut1_node, cmd)
115         time.sleep(10)
116
117         cmd = 'cd {0}/{1} && ./run_dmm_with_lwip.sh {2} {3} {4} {5} ' \
118             .format(con.REMOTE_FW_DIR, con.DMM_SCRIPTS, 1, dut2_if_name,
119                     dut1_if_ip, dut2_if_ip)
120
121         cmd += '2>&1 | tee log_run_dmm_with_lwip.txt'
122         exec_cmd_no_error(dut2_node, cmd)
123
124     @staticmethod
125     def get_lwip_test_result(dut_node):
126         """
127         After executing exec_the_base_lwip_test, use this
128         to get the test result.
129
130         :param dut_node: Node to get the test result on.
131         :type dut_node: dict
132         :returns: Word count of "send 50" in the log.
133         :rtype: str
134         """
135         cmd = 'cat {0}/{1}/log_run_dmm_with_lwip.txt | grep "send 50" | wc -l' \
136         .format(con.REMOTE_FW_DIR, con.DMM_SCRIPTS)
137
138         (stdout, _) = exec_cmd_no_error(dut_node, cmd)
139         return stdout
140
141     @staticmethod
142     def echo_running_log(dut1_node, dut2_node):
143         """
144         Get the running log.
145
146         :param dut1_node: Node to get the running log on.
147         :param dut2_node: Node to get the running log on.
148         :type dut1_node: dict
149         :type dut2_node: dict
150         """
151         cmd = 'cat /var/log/nStack/running.log'
152         exec_cmd_no_error(dut1_node, cmd)
153         exec_cmd_no_error(dut2_node, cmd)
154
155     @staticmethod
156     def echo_dpdk_log(dut1_node, dut2_node):
157         """
158         Get the dpdk log.
159
160         :param dut1_node: Node to get the DPDK log on.
161         :param dut2_node: Node to get the DPDK log on.
162         :type dut1_node: dict
163         :type dut2_node: dict
164         """
165         cmd = 'cat /var/log/nstack-dpdk/nstack_dpdk.log'
166         exec_cmd_no_error(dut1_node, cmd)
167         exec_cmd_no_error(dut2_node, cmd)
168
169     @staticmethod
170     def dmm_get_interface_name(dut_node, dut_interface):
171         """
172         Get the interface name.
173
174         :param dut_node: Node to get the interface name on.
175         :param dut_interface: Interface key.
176         :type dut_node: dict
177         :type dut_interface: str
178         :returns: Interface name.
179         :rtype: str
180         """
181         mac = Topology.get_interface_mac(dut_node, dut_interface)
182         cmd = 'ifconfig -a | grep {0}'.format(mac)
183         (stdout, _) = exec_cmd_no_error(dut_node, cmd)
184         interface_name = stdout.split(' ', 1)[0]
185         return interface_name
186
187     @staticmethod
188     def set_dmm_interface_address(dut_node, ifname, ip_addr, ip4_prefix):
189         """
190         Flush ip, set ip, set interface up.
191
192         :param dut_node: Node to set the interface address on.
193         :param ifname: Interface name.
194         :param ip_addr: IP address to configure.
195         :param ip4_prefix: Prefix length.
196         :type dut_node: dict
197         :type ifname: str
198         :type ip_addr: str
199         :type ip4_prefix: int
200         """
201         cmd = 'sudo ip -4 addr flush dev {}'.format(ifname)
202         exec_cmd_no_error(dut_node, cmd)
203         cmd = 'sudo ip addr add {}/{} dev {}'\
204             .format(ip_addr, ip4_prefix, ifname)
205         exec_cmd_no_error(dut_node, cmd)
206         cmd = 'sudo ip link set {0} up'.format(ifname)
207         exec_cmd_no_error(dut_node, cmd)