OLD | NEW |
1 import logging, re | 1 import logging, re |
2 from autotest_lib.client.common_lib import error | 2 from autotest_lib.client.common_lib import error |
3 from autotest_lib.client.bin import utils | 3 from autotest_lib.client.bin import utils |
4 import kvm_test_utils, kvm_utils, kvm_subprocess | 4 from autotest_lib.client.virt import virt_test_utils, virt_utils, aexpect |
5 | 5 |
6 | 6 |
7 def run_ethtool(test, params, env): | 7 def run_ethtool(test, params, env): |
8 """ | 8 """ |
9 Test offload functions of ethernet device by ethtool | 9 Test offload functions of ethernet device by ethtool |
10 | 10 |
11 1) Log into a guest. | 11 1) Log into a guest. |
12 2) Initialize the callback of sub functions. | 12 2) Initialize the callback of sub functions. |
13 3) Enable/disable sub function of NIC. | 13 3) Enable/disable sub function of NIC. |
14 4) Execute callback function. | 14 4) Execute callback function. |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 dd_cmd = ("dd if=/dev/urandom of=%s bs=1M count=%s" % | 100 dd_cmd = ("dd if=/dev/urandom of=%s bs=1M count=%s" % |
101 (filename, params.get("filesize"))) | 101 (filename, params.get("filesize"))) |
102 failure = (False, "Failed to create file using dd, cmd: %s" % dd_cmd) | 102 failure = (False, "Failed to create file using dd, cmd: %s" % dd_cmd) |
103 logging.info("Creating file in source host, cmd: %s", dd_cmd) | 103 logging.info("Creating file in source host, cmd: %s", dd_cmd) |
104 tcpdump_cmd = "tcpdump -lep -s 0 tcp -vv port ssh" | 104 tcpdump_cmd = "tcpdump -lep -s 0 tcp -vv port ssh" |
105 if src == "guest": | 105 if src == "guest": |
106 tcpdump_cmd += " and src %s" % guest_ip | 106 tcpdump_cmd += " and src %s" % guest_ip |
107 copy_files_from = vm.copy_files_from | 107 copy_files_from = vm.copy_files_from |
108 try: | 108 try: |
109 session.cmd_output(dd_cmd, timeout=360) | 109 session.cmd_output(dd_cmd, timeout=360) |
110 except kvm_subprocess.ShellCmdError, e: | 110 except aexpect.ShellCmdError, e: |
111 return failure | 111 return failure |
112 else: | 112 else: |
113 tcpdump_cmd += " and dst %s" % guest_ip | 113 tcpdump_cmd += " and dst %s" % guest_ip |
114 copy_files_from = vm.copy_files_to | 114 copy_files_from = vm.copy_files_to |
115 try: | 115 try: |
116 utils.system(dd_cmd) | 116 utils.system(dd_cmd) |
117 except error.CmdError, e: | 117 except error.CmdError, e: |
118 return failure | 118 return failure |
119 | 119 |
120 # only capture the new tcp port after offload setup | 120 # only capture the new tcp port after offload setup |
121 original_tcp_ports = re.findall("tcp.*:(\d+).*%s" % guest_ip, | 121 original_tcp_ports = re.findall("tcp.*:(\d+).*%s" % guest_ip, |
122 utils.system_output("/bin/netstat -nap")) | 122 utils.system_output("/bin/netstat -nap")) |
123 for i in original_tcp_ports: | 123 for i in original_tcp_ports: |
124 tcpdump_cmd += " and not port %s" % i | 124 tcpdump_cmd += " and not port %s" % i |
125 logging.debug("Listen using command: %s", tcpdump_cmd) | 125 logging.debug("Listen using command: %s", tcpdump_cmd) |
126 session2.sendline(tcpdump_cmd) | 126 session2.sendline(tcpdump_cmd) |
127 if not kvm_utils.wait_for( | 127 if not virt_utils.wait_for( |
128 lambda:session.cmd_status("pgrep tcpdump") == 0, 30): | 128 lambda:session.cmd_status("pgrep tcpdump") == 0, 30): |
129 return (False, "Tcpdump process wasn't launched") | 129 return (False, "Tcpdump process wasn't launched") |
130 | 130 |
131 logging.info("Start to transfer file") | 131 logging.info("Start to transfer file") |
132 try: | 132 try: |
133 copy_files_from(filename, filename) | 133 copy_files_from(filename, filename) |
134 except kvm_utils.SCPError, e: | 134 except virt_utils.SCPError, e: |
135 return (False, "File transfer failed (%s)" % e) | 135 return (False, "File transfer failed (%s)" % e) |
136 logging.info("Transfer file completed") | 136 logging.info("Transfer file completed") |
137 session.cmd("killall tcpdump") | 137 session.cmd("killall tcpdump") |
138 try: | 138 try: |
139 tcpdump_string = session2.read_up_to_prompt(timeout=60) | 139 tcpdump_string = session2.read_up_to_prompt(timeout=60) |
140 except kvm_subprocess.ExpectError: | 140 except aexpect.ExpectError: |
141 return (False, "Fail to read tcpdump's output") | 141 return (False, "Fail to read tcpdump's output") |
142 | 142 |
143 if not compare_md5sum(filename): | 143 if not compare_md5sum(filename): |
144 return (False, "Files' md5sum mismatched") | 144 return (False, "Files' md5sum mismatched") |
145 return (True, tcpdump_string) | 145 return (True, tcpdump_string) |
146 | 146 |
147 | 147 |
148 def tx_callback(status="on"): | 148 def tx_callback(status="on"): |
149 s, o = transfer_file(src="guest") | 149 s, o = transfer_file(src="guest") |
150 if not s: | 150 if not s: |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 vm = env.get_vm(params["main_vm"]) | 183 vm = env.get_vm(params["main_vm"]) |
184 vm.verify_alive() | 184 vm.verify_alive() |
185 session = vm.wait_for_login(timeout=int(params.get("login_timeout", 360))) | 185 session = vm.wait_for_login(timeout=int(params.get("login_timeout", 360))) |
186 # Let's just error the test if we identify that there's no ethtool installed | 186 # Let's just error the test if we identify that there's no ethtool installed |
187 session.cmd("ethtool -h") | 187 session.cmd("ethtool -h") |
188 session2 = vm.wait_for_login(timeout=int(params.get("login_timeout", 360))) | 188 session2 = vm.wait_for_login(timeout=int(params.get("login_timeout", 360))) |
189 mtu = 1514 | 189 mtu = 1514 |
190 feature_status = {} | 190 feature_status = {} |
191 filename = "/tmp/ethtool.dd" | 191 filename = "/tmp/ethtool.dd" |
192 guest_ip = vm.get_address() | 192 guest_ip = vm.get_address() |
193 ethname = kvm_test_utils.get_linux_ifname(session, vm.get_mac_address(0)) | 193 ethname = virt_test_utils.get_linux_ifname(session, vm.get_mac_address(0)) |
194 supported_features = params.get("supported_features") | 194 supported_features = params.get("supported_features") |
195 if supported_features: | 195 if supported_features: |
196 supported_features = supported_features.split() | 196 supported_features = supported_features.split() |
197 else: | 197 else: |
198 supported_features = [] | 198 supported_features = [] |
199 test_matrix = { | 199 test_matrix = { |
200 # type:(callback, (dependence), (exclude) | 200 # type:(callback, (dependence), (exclude) |
201 "tx": (tx_callback, (), ()), | 201 "tx": (tx_callback, (), ()), |
202 "rx": (rx_callback, (), ()), | 202 "rx": (rx_callback, (), ()), |
203 "sg": (tx_callback, ("tx",), ()), | 203 "sg": (tx_callback, ("tx",), ()), |
(...skipping 22 matching lines...) Expand all Loading... |
226 logging.error("Fail to disable %s", f_type) | 226 logging.error("Fail to disable %s", f_type) |
227 success = False | 227 success = False |
228 if not callback(status="off"): | 228 if not callback(status="off"): |
229 raise error.TestFail("Test failed, %s: off", f_type) | 229 raise error.TestFail("Test failed, %s: off", f_type) |
230 if not success: | 230 if not success: |
231 raise error.TestError("Enable/disable offload function fail") | 231 raise error.TestError("Enable/disable offload function fail") |
232 finally: | 232 finally: |
233 ethtool_restore_params() | 233 ethtool_restore_params() |
234 session.close() | 234 session.close() |
235 session2.close() | 235 session2.close() |
OLD | NEW |