On Tue, Nov 02, 2010 at 02:26:57PM +0800, Jason Wang wrote: > Jason, thanks for you comments.
> 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. Then execute file transfer test between guest > > and host. > > > > Changes from v1: > > - Add file transfer test > > - Setup bonding by serial > > - Fix bonding_setup.py > > > > 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..dd5550a > > --- /dev/null > > +++ b/client/tests/kvm/scripts/bonding_setup.py > > @@ -0,0 +1,31 @@ > > +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 > > +NETWORKING_IPV6=no > > +ONBOOT=yes > > +USERCTL=no > > +""" > > +f = file(bonding_config_file, "w") > > +f.write(bond_config) > > +f.close() > > +os.system("modprobe bonding") > > +os.system("service NetworkManager stop") > > +os.system("service network restart") > > diff --git a/client/tests/kvm/tests/nic_bonding.py > b/client/tests/kvm/tests/nic_bonding.py > > new file mode 100644 > > index 0000000..5a49a93 > > --- /dev/null > > +++ b/client/tests/kvm/tests/nic_bonding.py > > @@ -0,0 +1,89 @@ > > +import logging, re, os, subprocess, time, commands > > +from autotest_lib.client.common_lib import error > > +from tests import guest_test, file_transfer > > +import kvm_test_utils, kvm_subprocess, kvm_net_utils, kvm_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. > > + 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. > > + 11) Execute file transfer test between guest and host. > > + > > + @param test: Kvm test object. > > + @param params: Dictionary with the test parameters. > > + @param env: Dictionary with test environment. > > + """ > > + guest_test.run_guest_test(test, params, env) > > + timeout = int(params.get("login_timeout", 1200)) > > + vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) > > + > > + session_serial = kvm_test_utils.wait_for_login(vm, 0, timeout, 0, 2, > > + serial=True) > > + try: > > + o = session_serial.get_command_output("ifconfig bond0") > > + try: > > + re_ip = "inet addr:(\d{0,3}\.\d{0,3}\.\d{0,3}\.\d{0,3})" > > + bond_ip = re.findall(re_ip, o)[0] > > + except IndexError: > > + logging.debug(o) > > + raise error.TestFail("Fail to setup bond0 device!") > > Again, I think we could get the address through vm.get_address(), you > can try using the mac address of first nic. When we boot up a guest with 'nic1 nic2 nic3 nic4', guest produces four new interface 'eth$(n+1) eth$(n+2) eth$(n+3) eth$(n+4)'. The initialization of nics doesn't completed one by one. 'eth$(n+j)' doesn't always correspond to 'nicj', so we conld not insure the 'index' of real 'first' nic. bonding_setup.py is executed by run_guest_test(), we could not know guest's macS before booting up a guest. So I think the original method would be better. > > + > > + cmd = 'while true;do ' > > + output = session_serial.get_command_output("ifconfig -a") > > + logging.debug(output) > > + for ethname in re.findall("\n(eth\d+)", output): > > + cmd += 'ifconfig %s down;ifconfig %s up;' % (ethname, ethname) > > + session_serial.get_command_status_output("echo '%s done' > > test.sh" > > + % cmd) > > + if session_serial.get_command_status("bash test.sh&") != 0: > > + raise error.TestFail("Fail to launch test.sh in > > guest") > > We do some basic test before testing high availability. Ok, I'll add file_transfer test before repeatedly up/down interfaces. 'file_transfer.run_file_transfer(test, params, env)' > > + > > + 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=ping_times * 2) > > + 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 > > + 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.") > > I also think file transfer is better the just ping becuase it's more > suitable to test and verify. For ping, you need to decide a packet > loss value, but for file transfer, we just expect the it succeeded in time. We can test both of them (ping and file_transfer) in this case. > > + > > + cmd = "set_link %s.0 down" % params.get("nic_model") > > + vm.monitor.cmd(cmd) > > A better way to do this is add a id property to each nic which could > be also re-used in hotplug tests. And using set_link is better than > use ifconfig down becuase qemu may stop the backend which is a `real` > link status changed. it's also unique. "%s.%d" % (params.get("nic_model"), index) > > + > > + 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.") > > + > > + file_transfer.run_file_transfer(test, params, env) > > + > > + finally: > > + session_serial.close() > > + vm.destroy() > > diff --git a/client/tests/kvm/tests_base.cfg.sample > b/client/tests/kvm/tests_base.cfg.sample > > index 7b5aac2..412987b 100644 > > --- a/client/tests/kvm/tests_base.cfg.sample > > +++ b/client/tests/kvm/tests_base.cfg.sample > > @@ -540,6 +540,22 @@ variants: > > filesize = 512 > > nic_mode = tap > > > > + - nic_bonding: > > + type = nic_bonding > > + nics += ' nic2 nic3 nic4' > > + image_snapshot = yes > > + interpreter = "python" > > + guest_script = "scripts/bonding_setup.py" > > + dst_rsc_path = "/root/bonding_setup.py" > > + rsc_args = "" > > + serial_login = yes > > + test_timeout = 1000 > > + ping_times = 1500 > > + flood_ping_time = 120 > > + filesize = 4000 > > + transfer_timeout = 1000 > > + transfer_type = remote > > An alternative is to hard-coded this attributes for transfer in case itself. The transfer time is effected by the test environment (cpu/mem/load/... of guest and host), reserve them to config file would be better. > > - 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
