Amos Kong writes:
 > KVM-test: Add a new bonding subtest
 > 
 > From: Amos Kong <[email protected]>
 > 
 > In this test, execute bonding_setup.py to setup bonding of guest, do
 > basic transfer test, and repeatedly put down/up interfaces by set_link for
 > testing high availability.
 > 
 > there is a known issue of serial login, load another patch
 > (http://patchwork.test.kernel.org/patch/2720/)
 > when you test bonding test script.
 > 
 > Changes from v1:
 > - Add file transfer test
 > - Setup bonding by serial
 > - Fix bonding_setup.py
 > 
 > Changes from v2:
 > - Drop ping test
 > - Assign mac of nic1 to bond0
 > - Do some basic test before testing high availability
 > - Repeatedly down/up link by monitor cmd
 > 
 > Signed-off-by: Feng Yang <[email protected]>
 > Signed-off-by: Amos Kong <[email protected]>
 > ---
 >  client/tests/kvm/scripts/bonding_setup.py |   35 ++++++++++++++++++
 >  client/tests/kvm/tests/nic_bonding.py     |   57 
 > +++++++++++++++++++++++++++++
 >  client/tests/kvm/tests_base.cfg.sample    |   11 ++++++
 >  3 files changed, 103 insertions(+), 0 deletions(-)
 >  create mode 100644 client/tests/kvm/scripts/bonding_setup.py
 >  create mode 100644 client/tests/kvm/tests/nic_bonding.py
 > 
 > diff --git a/client/tests/kvm/scripts/bonding_setup.py 
 > b/client/tests/kvm/scripts/bonding_setup.py
 > new file mode 100644
 > index 0000000..9f228af
 > --- /dev/null
 > +++ b/client/tests/kvm/scripts/bonding_setup.py
 > @@ -0,0 +1,35 @@
 > +import os, re, commands, sys
 > +
 > +if len(sys.argv) != 2:
 > +    sys.exit()
 > +mac = sys.argv[1]
 > +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
 > +MACADDR=%s
 > +""" % mac
 > +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..26a2cd3
 > --- /dev/null
 > +++ b/client/tests/kvm/tests/nic_bonding.py
 > @@ -0,0 +1,57 @@
 > +import logging, time, commands, threading

commands is never used in this case.

 > +from autotest_lib.client.common_lib import error
 > +from tests import file_transfer
 > +import kvm_test_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) Execute file transfer test between guest and host.
 > +    4) Repeatedly put down/up interfaces by set_link
 > +    5) 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.
 > +    """
 > +    def control_link_loop(vm, termination_event):
 > +        logging.info("Repeatedly put down/up interfaces by set_link")
 > +        while True:
 > +            for i in range(len(params.get("nics").split())):
 > +                linkname = "%s.%s" % (params.get("nic_model"), i)

Better solution here is to generate a id for each nic devices and use
kvm_utils.get_subdict_names() to enumerate the nics.

 > +                cmd = "set_link %s down" % linkname
 > +                vm.monitor.cmd(cmd)
 > +                time.sleep(1)
 > +                cmd = "set_link %s up" % linkname
 > +                vm.monitor.cmd(cmd)
 > +            if termination_event.isSet():
 > +                break
 > +
 > +    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)
 > +    script_path = kvm_utils.get_path(test.bindir, 
 > "scripts/bonding_setup.py")
 > +    vm.copy_files_to(script_path, "/tmp/bonding_setup.py")
 > +    cmd = "python /tmp/bonding_setup.py %s" % vm.get_mac_address()
 > +    s, o = session_serial.get_command_status_output(cmd)

Looks like your bonding_setup.py never fail. You need to return
non-zero value when something was wrong during the setup.

 > +    if s != 0:
 > +        logging.debug(o)
 > +        raise error.TestFail("Fail to setup bonding")
 > +
 > +    termination_event = threading.Event()
 > +    t = threading.Thread(target=control_link_loop,
 > +                         args=(vm, termination_event))
 > +    try:
 > +        logging.info("Do some basic test before testing high availability")
 > +        file_transfer.run_file_transfer(test, params, env)
 > +        t.start()
 > +        logging.info("Do file transfer testing")
 > +        file_transfer.run_file_transfer(test, params, env)
 > +    finally:
 > +        termination_event.set()
 > +        t.join(10)
 > +        session_serial.close()
 > diff --git a/client/tests/kvm/tests_base.cfg.sample 
 > b/client/tests/kvm/tests_base.cfg.sample
 > index 2ae7f78..d0759b5 100644
 > --- a/client/tests/kvm/tests_base.cfg.sample
 > +++ b/client/tests/kvm/tests_base.cfg.sample
 > @@ -541,6 +541,17 @@ variants:
 >          filesize = 512
 >          nic_mode = tap
 >  
 > +    - nic_bonding:
 > +        type = nic_bonding
 > +        nics += ' nic2 nic3 nic4'
 > +        image_snapshot = yes
 > +        serial_login = yes
 > +        test_timeout = 1000
 > +        filesize = 4000
 > +        transfer_timeout = 1000
 > +        transfer_type = remote
 > +    kill_vm = yes

Indentation issue.

 > +
 >      - 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

Reply via email to