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.

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

Changes from v3:
- Fix indentation issue in config file
- Return 1 when not assign macaddr to bonding_setup.py

Signed-off-by: Feng Yang <[email protected]>
Signed-off-by: Amos Kong <[email protected]>
---
 client/tests/kvm/scripts/bonding_setup.py |   37 +++++++++++++++++++
 client/tests/kvm/tests/nic_bonding.py     |   57 +++++++++++++++++++++++++++++
 client/tests/kvm/tests_base.cfg.sample    |   11 ++++++
 3 files changed, 105 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..f2d4be9
--- /dev/null
+++ b/client/tests/kvm/scripts/bonding_setup.py
@@ -0,0 +1,37 @@
+import os, re, commands, sys
+"""This script is used to setup bonding, macaddr of bond0 should be assigned by
+argv1"""
+
+if len(sys.argv) != 2:
+    sys.exit(1)
+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..3b1fc8c
--- /dev/null
+++ b/client/tests/kvm/tests/nic_bonding.py
@@ -0,0 +1,57 @@
+import logging, time, threading
+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)
+                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)
+    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..2104af6 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
+
     - 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