Amos Kong writes: > In this test, execute run_guest_test() to setup bonding, ping guest from > host when repeatedly down/up interfaces, and check the lost packet ratio. > But this test always fail of lose packets, we maybe need adjust the > check_ratio in config file. >
I think some small packet loss during making one interface down is expected. And TCP session is better and easier to control for bonding test. > Signed-off-by: Feng Yang <[email protected]> > Signed-off-by: Amos Kong <[email protected]> > --- > 0 files changed, 0 insertions(+), 0 deletions(-) > > diff --git a/client/tests/kvm/scripts/bonding_setup.py > b/client/tests/kvm/scripts/bonding_setup.py > new file mode 100644 > index 0000000..bc50ea0 > --- /dev/null > +++ b/client/tests/kvm/scripts/bonding_setup.py > @@ -0,0 +1,30 @@ > +import os, re, commands > +eth_nums = 0 > +ifconfig_output = commands.getoutput("ifconfig") > +re_eth = "^eth[0-9]*" > +for ename in re.findall(re_eth, ifconfig_output): > + eth_config_file = "/etc/sysconfig/network-scripts/ifcfg-%s" % ename > + eth_config = """DEVICE=%s > +USERCTL=no > +ONBOOT=yes > +MASTER=bond0 > +SLAVE=yes > +BOOTPROTO=none > +""" % ename > + f = file(eth_config_file,'w') > + f.write(eth_config) > + f.close() > + > +bonding_config_file = "/etc/sysconfig/network-scripts/ifcfg-bond0" > +bond_config = """DEVICE=bond0 > +BOOTPROTO=dhcp > +ONBOOT=yes > +USERCTL=no > +""" > +f = file(bonding_config_file, "w") > +f.write(bond_config) > +f.close() > +os.system("modprobe bonding") > +os.system("service network restart") For safety, it's better to run this script through serial. > + > + > diff --git a/client/tests/kvm/tests/nic_bonding.py > b/client/tests/kvm/tests/nic_bonding.py > new file mode 100644 > index 0000000..1c6e674 > --- /dev/null > +++ b/client/tests/kvm/tests/nic_bonding.py > @@ -0,0 +1,93 @@ > +import logging, re, os, subprocess, time, commands > +from autotest_lib.client.common_lib import error > +from tests import guest_test > +import kvm_test_utils, kvm_subprocess, kvm_net_utils, kvm_utils Looks like your tree is not clean, you should use kvm_test_utils instead of kvm_net_utils. > + > +def run_nic_bonding(test, params, env): > + """ > + Nic bonding test in guest. > + > + 1) Start guest with four nic models. > + 2) Setup bond0 in guest by script bonding_setup.py. Better to test some basic function such as file transfer before testing the case of failure tolerance. > + 3) Run test.sh in guest to down/up all the interfaces > + 4) Ping bond0 of guest for setting times to check packet loss ratio. > + 5) Flood ping bond0 of guest for setting seconds. > + 6) Ping bond0 of guest for another setting times to check packet loss > ratio. > + 7) Run set_link monitor command in guest. > + 8) Ping bond0 of guest for setting times to check packet loss ratio. > + 9) Flood ping bond0 of guest for setting seconds. > + 10) Ping bond0 of guest for setting times to check packet loss ratio. > + > + @param test: Kvm test object. > + @param params: Dictionary with the test parameters. > + @param env: Dictionary with test environment. > + """ > + timeout = int(params.get("login_timeout", 1200)) > + vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) > + session = kvm_test_utils.wait_for_login(vm, 0, timeout, 0, 2, > serial=True) > + > + try: > + cmd_timeout = float(params.get("cmd_timeout", 1000)) > + guest_test.run_guest_test(test, params, env) > + o = session.get_command_output("ifconfig bond0", > timeout=cmd_timeout) > + if "bond0" not in o: > + raise error.TestFail("Fail to setup bond0 device!") > + > + re_ip = "inet addr:(\d{0,3}\.\d{0,3}\.\d{0,3}\.\d{0,3})" > + bond_ip = re.findall(re_ip, o)[0] > + eth_num = len(params.get("nics").split()) Is there any reason that we can't use vm.get_macaddress()? > + cmd = 'while true;do ' > + for i in range(eth_num): > + ethname = kvm_net_utils.get_linux_ifname(session, > + vm.get_mac_address(i)) > + cmd += 'ifconfig %s down;ifconfig %s up;' % (ethname, ethname) > + session.get_command_status_output("echo '%s done' > test.sh" % cmd) > + cmd = 'ps aux|grep "bash test.sh"|grep -v grep' How about using a dedicate thread to do this? And maybe use set_link is enough to do this kind of test. > + > + for i in range(10): > + session.get_command_output("bash test.sh&") > + time.sleep(5) > + if session.get_command_status(cmd) == 0: > + break; > + logging.info("Fail to run test.sh script in guest, try again!") > + if session.get_command_status(cmd) != 0: > + raise error.TestFail("Fail to launch test.sh in guest") > + > + check_ratio = params.get("check_ratio", 0) > + ping_times = float(params.get("ping_times", 1500)) > + flood_ping_time = float(params.get("flood_ping_time", 120)) > + > + def passed_ping_test(): > + logging.info("Ping the guest for %s times!" % ping_times) > + (s, o) = kvm_net_utils.ping(dest=bond_ip, count=ping_times, > + timeout=cmd_timeout) > + loss_ratio = kvm_net_utils.get_loss_ratio(o) > + if loss_ratio < 0: > + logging.error("Fail to get packets loss ratio!") > + return False > + elif loss_ratio > check_ratio: > + logging.error("%s%% packet are lost!" % loss_ratio) > + return False > + else: > + return True > + > + if not passed_ping_test(): > + raise error.TestFail("Ping test failed.") > + logging.info("Flood ping the guest for %s seconds!" % > flood_ping_time) > + kvm_net_utils.ping(dest=bond_ip, flood=True, > timeout=flood_ping_time) > + if not passed_ping_test(): > + raise error.TestFail("Ping test failed.") > + > + cmd = "set_link %s.0 down" % params.get("nic_model") > + vm.monitor.cmd(cmd, timeout=cmd_timeout) > + > + if not passed_ping_test(): > + raise error.TestFail("Ping test failed.") > + logging.info("Flood ping the guest for %s seconds!" % > flood_ping_time) > + kvm_net_utils.ping(dest=bond_ip, flood=True, > timeout=flood_ping_time) > + if not passed_ping_test(): > + raise error.TestFail("Ping test failed.") > + > + finally: > + session.close() > + vm.destroy() > diff --git a/client/tests/kvm/tests_base.cfg.sample > b/client/tests/kvm/tests_base.cfg.sample > index 87fd51d..df8216e 100644 > --- a/client/tests/kvm/tests_base.cfg.sample > +++ b/client/tests/kvm/tests_base.cfg.sample > @@ -539,6 +539,19 @@ variants: > filesize = 512 > nic_mode = tap > > + - nic_bonding: > + type = nic_bonding > + nics += ' nic2 nic3 nic4' > + image_snapshot = yes > + cmd_timeout = 360 > + interpreter = "python" > + guest_script = "scripts/bonding_setup.py" This script does not work for non-redhat guests, please limit it to redhat guests. > + test_timeout = 1000 > + dst_rsc_path = "/root/bonding_setup.py" > + rsc_args = "" > + ping_times = 1500 > + flood_ping_time = 120 > + > - physical_resources_check: install setup unattended_install.cdrom > type = physical_resources_check > catch_uuid_cmd = dmidecode | awk -F: '/UUID/ {print $2}' > _______________________________________________ Autotest mailing list [email protected] http://test.kernel.org/cgi-bin/mailman/listinfo/autotest
