OLD | NEW |
1 import logging, time, re | 1 import logging, time, re |
2 from autotest_lib.client.common_lib import error | 2 from autotest_lib.client.common_lib import error |
3 import kvm_test_utils, kvm_utils, kvm_subprocess | 3 from autotest_lib.client.virt import virt_utils, virt_test_utils, aexpect |
4 | 4 |
5 | 5 |
6 def run_vlan(test, params, env): | 6 def run_vlan(test, params, env): |
7 """ | 7 """ |
8 Test 802.1Q vlan of NIC, config it by vconfig command. | 8 Test 802.1Q vlan of NIC, config it by vconfig command. |
9 | 9 |
10 1) Create two VMs. | 10 1) Create two VMs. |
11 2) Setup guests in 10 different vlans by vconfig and using hard-coded | 11 2) Setup guests in 10 different vlans by vconfig and using hard-coded |
12 ip address. | 12 ip address. |
13 3) Test by ping between same and different vlans of two VMs. | 13 3) Test by ping between same and different vlans of two VMs. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 def set_arp_ignore(session, iface="eth0"): | 46 def set_arp_ignore(session, iface="eth0"): |
47 ignore_cmd = "echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore" | 47 ignore_cmd = "echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore" |
48 session.cmd(ignore_cmd) | 48 session.cmd(ignore_cmd) |
49 | 49 |
50 def rem_vlan(session, v_id, iface="eth0"): | 50 def rem_vlan(session, v_id, iface="eth0"): |
51 rem_vlan_cmd = "if [[ -e /proc/net/vlan/%s ]];then vconfig rem %s;fi" | 51 rem_vlan_cmd = "if [[ -e /proc/net/vlan/%s ]];then vconfig rem %s;fi" |
52 iface = "%s.%s" % (iface, v_id) | 52 iface = "%s.%s" % (iface, v_id) |
53 return session.cmd_status(rem_vlan_cmd % (iface, iface)) | 53 return session.cmd_status(rem_vlan_cmd % (iface, iface)) |
54 | 54 |
55 def nc_transfer(src, dst): | 55 def nc_transfer(src, dst): |
56 nc_port = kvm_utils.find_free_port(1025, 5334, vm_ip[dst]) | 56 nc_port = virt_utils.find_free_port(1025, 5334, vm_ip[dst]) |
57 listen_cmd = params.get("listen_cmd") | 57 listen_cmd = params.get("listen_cmd") |
58 send_cmd = params.get("send_cmd") | 58 send_cmd = params.get("send_cmd") |
59 | 59 |
60 #listen in dst | 60 #listen in dst |
61 listen_cmd = listen_cmd % (nc_port, "receive") | 61 listen_cmd = listen_cmd % (nc_port, "receive") |
62 session[dst].sendline(listen_cmd) | 62 session[dst].sendline(listen_cmd) |
63 time.sleep(2) | 63 time.sleep(2) |
64 #send file from src to dst | 64 #send file from src to dst |
65 send_cmd = send_cmd % (vlan_ip[dst], str(nc_port), "file") | 65 send_cmd = send_cmd % (vlan_ip[dst], str(nc_port), "file") |
66 session[src].cmd(send_cmd, timeout=60) | 66 session[src].cmd(send_cmd, timeout=60) |
67 try: | 67 try: |
68 session[dst].read_up_to_prompt(timeout=60) | 68 session[dst].read_up_to_prompt(timeout=60) |
69 except kvm_subprocess.ExpectError: | 69 except aexpect.ExpectError: |
70 raise error.TestFail ("Fail to receive file" | 70 raise error.TestFail ("Fail to receive file" |
71 " from vm%s to vm%s" % (src+1, dst+1)) | 71 " from vm%s to vm%s" % (src+1, dst+1)) |
72 #check MD5 message digest of receive file in dst | 72 #check MD5 message digest of receive file in dst |
73 output = session[dst].cmd_output("md5sum receive").strip() | 73 output = session[dst].cmd_output("md5sum receive").strip() |
74 digest_receive = re.findall(r'(\w+)', output)[0] | 74 digest_receive = re.findall(r'(\w+)', output)[0] |
75 if digest_receive == digest_origin[src]: | 75 if digest_receive == digest_origin[src]: |
76 logging.info("file succeed received in vm %s", vlan_ip[dst]) | 76 logging.info("file succeed received in vm %s", vlan_ip[dst]) |
77 else: | 77 else: |
78 logging.info("digest_origin is %s", digest_origin[src]) | 78 logging.info("digest_origin is %s", digest_origin[src]) |
79 logging.info("digest_receive is %s", digest_receive) | 79 logging.info("digest_receive is %s", digest_receive) |
80 raise error.TestFail("File transfered differ from origin") | 80 raise error.TestFail("File transfered differ from origin") |
81 session[dst].cmd_output("rm -f receive") | 81 session[dst].cmd_output("rm -f receive") |
82 | 82 |
83 for i in range(2): | 83 for i in range(2): |
84 session.append(vm[i].wait_for_login( | 84 session.append(vm[i].wait_for_login( |
85 timeout=int(params.get("login_timeout", 360)))) | 85 timeout=int(params.get("login_timeout", 360)))) |
86 if not session[i] : | 86 if not session[i] : |
87 raise error.TestError("Could not log into guest(vm%d)" % i) | 87 raise error.TestError("Could not log into guest(vm%d)" % i) |
88 logging.info("Logged in") | 88 logging.info("Logged in") |
89 | 89 |
90 ifname.append(kvm_test_utils.get_linux_ifname(session[i], | 90 ifname.append(virt_test_utils.get_linux_ifname(session[i], |
91 vm[i].get_mac_address())) | 91 vm[i].get_mac_address())) |
92 #get guest ip | 92 #get guest ip |
93 vm_ip.append(vm[i].get_address()) | 93 vm_ip.append(vm[i].get_address()) |
94 | 94 |
95 #produce sized file in vm | 95 #produce sized file in vm |
96 dd_cmd = "dd if=/dev/urandom of=file bs=1024k count=%s" | 96 dd_cmd = "dd if=/dev/urandom of=file bs=1024k count=%s" |
97 session[i].cmd(dd_cmd % file_size) | 97 session[i].cmd(dd_cmd % file_size) |
98 #record MD5 message digest of file | 98 #record MD5 message digest of file |
99 output = session[i].cmd("md5sum file", timeout=60) | 99 output = session[i].cmd("md5sum file", timeout=60) |
100 digest_origin.append(re.findall(r'(\w+)', output)[0]) | 100 digest_origin.append(re.findall(r'(\w+)', output)[0]) |
(...skipping 14 matching lines...) Expand all Loading... |
115 | 115 |
116 for vlan in range(1, vlan_num+1): | 116 for vlan in range(1, vlan_num+1): |
117 logging.info("Test for vlan %s", vlan) | 117 logging.info("Test for vlan %s", vlan) |
118 | 118 |
119 logging.info("Ping between vlans") | 119 logging.info("Ping between vlans") |
120 interface = ifname[0] + '.' + str(vlan) | 120 interface = ifname[0] + '.' + str(vlan) |
121 for vlan2 in range(1, vlan_num+1): | 121 for vlan2 in range(1, vlan_num+1): |
122 for i in range(2): | 122 for i in range(2): |
123 interface = ifname[i] + '.' + str(vlan) | 123 interface = ifname[i] + '.' + str(vlan) |
124 dest = subnet +'.'+ str(vlan2)+ '.' + ip_unit[(i+1)%2] | 124 dest = subnet +'.'+ str(vlan2)+ '.' + ip_unit[(i+1)%2] |
125 s, o = kvm_test_utils.ping(dest, count=2, | 125 s, o = virt_test_utils.ping(dest, count=2, |
126 interface=interface, | 126 interface=interface, |
127 session=session[i], timeout=30) | 127 session=session[i], timeout=30) |
128 if ((vlan == vlan2) ^ (s == 0)): | 128 if ((vlan == vlan2) ^ (s == 0)): |
129 raise error.TestFail ("%s ping %s unexpected" % | 129 raise error.TestFail ("%s ping %s unexpected" % |
130 (interface, dest)) | 130 (interface, dest)) |
131 | 131 |
132 vlan_ip[0] = subnet + '.' + str(vlan) + '.' + ip_unit[0] | 132 vlan_ip[0] = subnet + '.' + str(vlan) + '.' + ip_unit[0] |
133 vlan_ip[1] = subnet + '.' + str(vlan) + '.' + ip_unit[1] | 133 vlan_ip[1] = subnet + '.' + str(vlan) + '.' + ip_unit[1] |
134 | 134 |
135 logging.info("Flood ping") | 135 logging.info("Flood ping") |
136 def flood_ping(src, dst): | 136 def flood_ping(src, dst): |
137 # we must use a dedicated session becuase the kvm_subprocess | 137 # we must use a dedicated session becuase the aexpect |
138 # does not have the other method to interrupt the process in | 138 # does not have the other method to interrupt the process in |
139 # the guest rather than close the session. | 139 # the guest rather than close the session. |
140 session_flood = vm[src].wait_for_login(timeout=60) | 140 session_flood = vm[src].wait_for_login(timeout=60) |
141 kvm_test_utils.ping(vlan_ip[dst], flood=True, | 141 virt_test_utils.ping(vlan_ip[dst], flood=True, |
142 interface=ifname[src], | 142 interface=ifname[src], |
143 session=session_flood, timeout=10) | 143 session=session_flood, timeout=10) |
144 session_flood.close() | 144 session_flood.close() |
145 | 145 |
146 flood_ping(0, 1) | 146 flood_ping(0, 1) |
147 flood_ping(1, 0) | 147 flood_ping(1, 0) |
148 | 148 |
149 logging.info("Transfering data through nc") | 149 logging.info("Transfering data through nc") |
150 nc_transfer(0, 1) | 150 nc_transfer(0, 1) |
151 nc_transfer(1, 0) | 151 nc_transfer(1, 0) |
(...skipping 14 matching lines...) Expand all Loading... |
166 finally: | 166 finally: |
167 for j in range (1, i+1): | 167 for j in range (1, i+1): |
168 s = s or rem_vlan(session[0], j, ifname[0]) | 168 s = s or rem_vlan(session[0], j, ifname[0]) |
169 if s == 0: | 169 if s == 0: |
170 logging.info("maximal interface plumb test done") | 170 logging.info("maximal interface plumb test done") |
171 else: | 171 else: |
172 logging.error("maximal interface plumb test failed") | 172 logging.error("maximal interface plumb test failed") |
173 | 173 |
174 session[0].close() | 174 session[0].close() |
175 session[1].close() | 175 session[1].close() |
OLD | NEW |