提交 60184402 编写于 作者: Y Yiqiao Pu

Merge pull request #19 from humanux/vlan

tests.vlan: some issues fix
......@@ -16,3 +16,7 @@
cmd_type = ip
RHEL.5:
cmd_type = vconfig
variants:
- @vlan_connective_test:
- vlan_scalability_test:
do_maximal_test = yes
......@@ -30,8 +30,8 @@ def run(test, params, env):
Creates a vlan-device on iface by cmd that assigned by cmd_type
now only support 'ip' and 'vconfig'
"""
txt = "Create a vlan-device on interface %s with vlan id %s" % (iface,
v_id)
vlan_if = '%s.%s' % (iface, v_id)
txt = "Create vlan interface '%s' on %s" % (vlan_if, iface)
error.context(txt, logging.info)
if cmd_type == "vconfig":
cmd = "vconfig add %s %s" % (iface, v_id)
......@@ -40,19 +40,19 @@ def run(test, params, env):
cmd = "ip link add link %s %s type vlan id %s " % (iface,
v_name, v_id)
else:
err_msg = "Unexpected vlan operation command: %s" % cmd_type
err_msg = "Unexpected vlan operation command: %s, " % cmd_type
err_msg += "only support 'ip' and 'vconfig' now"
raise error.TestError(err_msg)
session.cmd(cmd)
def set_ip_vlan(session, v_id, ip, iface="eth0"):
def set_ip_vlan(session, v_id, vlan_ip, iface="eth0"):
"""
Set ip address of vlan interface
"""
iface = "%s.%s" % (iface, v_id)
txt = "Set ip to '%s' for interface '%s'" % (iface, ip)
txt = "Assign IP '%s' to vlan interface '%s'" % (vlan_ip, iface)
error.context(txt, logging.info)
session.cmd("ifconfig %s %s" % (iface, ip))
session.cmd("ifconfig %s %s" % (iface, vlan_ip))
def set_arp_ignore(session):
"""
......@@ -73,56 +73,65 @@ def run(test, params, env):
elif cmd_type == "ip":
rem_vlan_cmd = "ip link delete %s" % v_iface
else:
err_msg = "Unexpected vlan operation command: %s" % cmd_type
err_msg = "Unexpected vlan operation command: %s, " % cmd_type
err_msg += "only support 'ip' and 'vconfig' now"
raise error.TestError(err_msg)
send_cmd = "[ -e /proc/net/vlan/%s ] && %s" % (v_iface, rem_vlan_cmd)
error.context("Remove the vlan-device '%s'." % v_iface, logging.info)
error.context("Remove vlan interface '%s'." % v_iface, logging.info)
return session.cmd_status(send_cmd)
def nc_transfer(src, dst):
"""
Transfer file by netcat
"""
nc_port = utils_misc.find_free_port(1025, 5334, vm_ip[dst])
listen_cmd = params.get("listen_cmd")
send_cmd = params.get("send_cmd")
#listen in dst
listen_cmd = listen_cmd % (nc_port, "receive")
session[dst].sendline(listen_cmd)
sessions[dst].sendline(listen_cmd)
time.sleep(2)
# send file from src to dst
send_cmd = send_cmd % (vlan_ip[dst], str(nc_port), "file")
session[src].cmd(send_cmd, timeout=60)
sessions[src].cmd(send_cmd, timeout=60)
try:
session[dst].read_up_to_prompt(timeout=60)
sessions[dst].read_up_to_prompt(timeout=60)
except aexpect.ExpectError:
#kill server
session_ctl[dst].cmd_output_safe("killall -9 nc")
raise error.TestFail("Fail to receive file"
" from vm%s to vm%s" % (src + 1, dst + 1))
# check MD5 message digest of receive file in dst
output = session[dst].cmd_output("md5sum receive").strip()
output = sessions[dst].cmd_output("md5sum receive").strip()
digest_receive = re.findall(r'(\w+)', output)[0]
if digest_receive == digest_origin[src]:
logging.info("file succeed received in vm %s", vlan_ip[dst])
logging.info("File succeed received in vm %s", vlan_ip[dst])
else:
logging.info("digest_origin is %s", digest_origin[src])
logging.info("digest_receive is %s", digest_receive)
logging.info("Digest_origin is %s", digest_origin[src])
logging.info("Digest_receive is %s", digest_receive)
raise error.TestFail("File transferred differ from origin")
session[dst].cmd("rm -f receive")
sessions[dst].cmd("rm -f receive")
def flood_ping(src, dst):
"""
Flood ping test
# we must use a dedicated session because the aexpect
# does not have the other method to interrupt the process in
# the guest rather than close the session.
error.context("Flood ping from %s interface %s to %s" % (vm[src].name,
"""
error.context("Flood ping from %s interface %s to %s" % (vms[src].name,
ifname[src], vlan_ip[dst]), logging.info)
session_flood = vm[src].wait_for_login(timeout=60)
session_flood = vms[src].wait_for_login(timeout=60)
utils_test.ping(vlan_ip[dst], flood=True,
interface=ifname[src],
session=session_flood, timeout=10)
session_flood.close()
vm = []
session = []
vms = []
sessions = []
session_ctl = []
ifname = []
vm_ip = []
digest_origin = []
......@@ -130,97 +139,104 @@ def run(test, params, env):
ip_unit = ['1', '2']
subnet = params.get("subnet", "192.168")
vlan_num = int(params.get("vlan_num", 5))
maximal = int(params.get("maximal"))
file_size = params.get("file_size", 4094)
maximal = int(params.get("maximal", 4094))
file_size = params.get("file_size", 4096)
cmd_type = params.get("cmd_type", "ip")
login_timeout = int(params.get("login_timeout", 360))
vm.append(env.get_vm(params["main_vm"]))
vm.append(env.get_vm("vm2"))
for vm_ in vm:
vms.append(env.get_vm(params["main_vm"]))
vms.append(env.get_vm("vm2"))
for vm_ in vms:
vm_.verify_alive()
for i in range(2):
session.append(vm[i].wait_for_login(timeout=login_timeout))
if not session[i]:
raise error.TestError("Could not log into guest %s" % vm[i].name)
logging.info("Logged in %s successful" % vm[i].name)
ifname.append(utils_net.get_linux_ifname(session[i],
vm[i].get_mac_address()))
for vm_index, vm in enumerate(vms):
error.base_context("Prepare test env on %s" % vm.name)
session = vm.wait_for_login(timeout=login_timeout)
if not session:
err_msg = "Could not log into guest %s" % vm.name
raise error.TestError(err_msg)
sessions.append(session)
logging.info("Logged in %s successful" % vm.name)
session_ctl.append(vm.wait_for_login(timeout=login_timeout))
ifname.append(utils_net.get_linux_ifname(session,
vm.get_mac_address()))
# get guest ip
vm_ip.append(vm[i].get_address())
vm_ip.append(vm.get_address())
# produce sized file in vm
dd_cmd = "dd if=/dev/urandom of=file bs=1024k count=%s"
session[i].cmd(dd_cmd % file_size)
dd_cmd = "dd if=/dev/urandom of=file bs=1M count=%s"
session.cmd(dd_cmd % file_size)
# record MD5 message digest of file
output = session[i].cmd("md5sum file", timeout=60)
digest_origin.append(re.findall(r'(\w+)', output)[0])
md5sum_output = session.cmd("md5sum file", timeout=60)
digest_origin.append(re.findall(r'(\w+)', md5sum_output)[0])
# stop firewall in vm
session[i].cmd("service iptables stop; true")
session.cmd_output_safe("iptables -F; service iptables stop; true")
error.context("Load 8021q module in guest %s" % vm.name,
logging.info)
session.cmd_output_safe("modprobe 8021q")
error.context("load 8021q module in guest %s" % vm[i].name,
error.context("Setup vlan environment in guest %s" % vm.name,
logging.info)
session[i].cmd("modprobe 8021q")
for vlan_i in range(1, vlan_num + 1):
add_vlan(session, vlan_i, ifname[vm_index], cmd_type)
v_ip = "%s.%s.%s" % (subnet, vlan_i, ip_unit[vm_index])
set_ip_vlan(session, vlan_i, v_ip, ifname[vm_index])
set_arp_ignore(session)
try:
for i in range(2):
logging.info("Setup vlan environment in guest %s" % vm[i].name)
for vlan_i in range(1, vlan_num + 1):
add_vlan(session[i], vlan_i, ifname[i], cmd_type)
v_ip = "%s.%s.%s" % (subnet, vlan_i, ip_unit[i])
set_ip_vlan(session[i], vlan_i, v_ip, ifname[i])
set_arp_ignore(session[i])
for vlan in range(1, vlan_num + 1):
error.context("Test for vlan %s" % vlan, logging.info)
error.base_context("Test for vlan %s" % vlan, logging.info)
error.context("Ping test between vlans", logging.info)
interface = ifname[0] + '.' + str(vlan)
for vlan2 in range(1, vlan_num + 1):
for i in range(2):
interface = ifname[i] + '.' + str(vlan)
dest = subnet + '.' + \
str(vlan2) + '.' + ip_unit[(i + 1) % 2]
s, o = utils_test.ping(dest, count=2,
interface=interface,
session=session[i], timeout=30)
if ((vlan == vlan2) ^ (s == 0)):
raise error.TestFail("%s ping %s unexpected" %
(interface, dest))
vlan_ip[0] = subnet + '.' + str(vlan) + '.' + ip_unit[0]
vlan_ip[1] = subnet + '.' + str(vlan) + '.' + ip_unit[1]
for vm_index, vm in enumerate(vms):
for vlan2 in range(1, vlan_num + 1):
interface = ifname[vm_index] + '.' + str(vlan)
dest = ".".join((subnet, str(vlan2),
ip_unit[(vm_index + 1) % 2]))
status, output = utils_test.ping(dest, count=2,
interface=interface, session=sessions[vm_index],
timeout=30)
if ((vlan == vlan2) ^ (status == 0)):
err_msg = "%s ping %s unexpected, " % (interface, dest)
err_msg += "error info: %s" % output
raise error.TestFail(err_msg)
error.context("Flood ping between vlans", logging.info)
vlan_ip[0] = ".".join((subnet, str(vlan), ip_unit[0]))
vlan_ip[1] = ".".join((subnet, str(vlan), ip_unit[1]))
flood_ping(0, 1)
flood_ping(1, 0)
error.context("Transferring data through nc", logging.info)
error.context("Transferring data between vlans by nc",
logging.info)
nc_transfer(0, 1)
nc_transfer(1, 0)
finally:
for vlan in range(1, vlan_num + 1):
logging.info("rem vlan: %s", vlan)
rem_vlan(session[0], vlan, ifname[0], cmd_type)
rem_vlan(session[1], vlan, ifname[1], cmd_type)
#If client can not connect the nc server, need kill the server.
for session in session_ctl:
session.cmd_output_safe("killall -9 nc")
error.base_context("Remove vlan")
for vm_index, vm in enumerate(vms):
for vlan in range(1, vlan_num + 1):
rem_vlan(sessions[vm_index], vlan, ifname[vm_index], cmd_type)
# Plumb/unplumb maximal number of vlan interfaces
i = 1
s = 0
try:
error.context("Testing the plumb of vlan interface", logging.info)
for i in range(1, maximal + 1):
add_vlan(session[0], i, ifname[0], cmd_type)
finally:
for j in range(1, i + 1):
s = s or rem_vlan(session[0], j, ifname[0], cmd_type)
if s == 0:
logging.info("maximal interface plumb test done")
else:
logging.error("maximal interface plumb test failed")
session[0].close()
session[1].close()
if params.get("do_maximal_test", "no") == "yes":
try:
error.base_context("Vlan scalability test")
error.context("Testing the plumb of vlan interface", logging.info)
for vlan_index in range(1, maximal + 1):
add_vlan(sessions[0], vlan_index, ifname[0], cmd_type)
vlan_added = vlan_index
if vlan_added != maximal:
raise error.TestFail("Maximal interface plumb test failed")
finally:
for vlan_index in range(1, vlan_added + 1):
if not rem_vlan(sessions[0], vlan_index, ifname[0], cmd_type):
logging.error("Remove vlan %s failed" % vlan_index)
sessions.extend(session_ctl)
for sess in sessions:
if sess:
sess.close()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册