From patchwork Mon Sep 5 19:43:34 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Meneghel Rodrigues X-Patchwork-Id: 1125382 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p85Jhjxh028350 for ; Mon, 5 Sep 2011 19:43:49 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753584Ab1IETnm (ORCPT ); Mon, 5 Sep 2011 15:43:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:20320 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753476Ab1IETnl (ORCPT ); Mon, 5 Sep 2011 15:43:41 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p85JheVe019698 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 5 Sep 2011 15:43:40 -0400 Received: from freedom.local.com (vpn-11-168.rdu.redhat.com [10.11.11.168]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p85JhbdN032620; Mon, 5 Sep 2011 15:43:38 -0400 From: Lucas Meneghel Rodrigues To: autotest@test.kernel.org Cc: kvm@vger.kernel.org, Lucas Meneghel Rodrigues , Jiri Zupka Subject: [PATCH] KVM test: Add test for regression found killing guest during netload v2 Date: Mon, 5 Sep 2011 16:43:34 -0300 Message-Id: <1315251814-22728-1-git-send-email-lmr@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Mon, 05 Sep 2011 19:43:49 +0000 (UTC) This patch contain two tests: 1) Try kill guest when guest netwok is under loading. 2) Try kill guest after multiple adding and removing network drivers. Changes from v1: * Use --color=never on ls command to correctly determine nw drivers Signed-off-by: Jiri Zupka --- client/tests/kvm/subtests.cfg.sample | 18 ++++ client/virt/tests/netstress_kill_guest.py | 148 +++++++++++++++++++++++++++++ 2 files changed, 166 insertions(+), 0 deletions(-) create mode 100644 client/virt/tests/netstress_kill_guest.py diff --git a/client/tests/kvm/subtests.cfg.sample b/client/tests/kvm/subtests.cfg.sample index f1e2765..9d9dbba 100644 --- a/client/tests/kvm/subtests.cfg.sample +++ b/client/tests/kvm/subtests.cfg.sample @@ -777,6 +777,24 @@ variants: transfer_type = remote kill_vm =yes + - netstress_kill_guest: install setup unattended_install.cdrom + only Linux + type = netstress_kill_guest + image_snapshot = yes + nic_mode = tap + # There should be enough vms for build topology. + variants: + -driver: + mode = driver + -load: + mode = load + netperf_files = netperf-2.4.5.tar.bz2 wait_before_data.patch + packet_size = 1500 + setup_cmd = "cd %s && tar xvfj netperf-2.4.5.tar.bz2 && cd netperf-2.4.5 && patch -p0 < ../wait_before_data.patch && ./configure && make" + clean_cmd = " while killall -9 netserver; do True test; done;" + netserver_cmd = %s/netperf-2.4.5/src/netserver + netperf_cmd = %s/netperf-2.4.5/src/netperf -t %s -H %s -l 60 -- -m %s + - physical_resources_check: install setup image_copy unattended_install.cdrom type = physical_resources_check catch_uuid_cmd = dmidecode | awk -F: '/UUID/ {print $2}' diff --git a/client/virt/tests/netstress_kill_guest.py b/client/virt/tests/netstress_kill_guest.py new file mode 100644 index 0000000..e7e0116 --- /dev/null +++ b/client/virt/tests/netstress_kill_guest.py @@ -0,0 +1,148 @@ +import logging, os, signal, re, time +from autotest_lib.client.common_lib import error +from autotest_lib.client.bin import utils +from autotest_lib.client.virt import aexpect, virt_utils + + +def run_netstress_kill_guest(test, params, env): + """ + Try stop network interface in VM when other VM try to communicate. + + @param test: kvm test object + @param params: Dictionary with the test parameters + @param env: Dictionary with test environment. + """ + def get_corespond_ip(ip): + """ + Get local ip address which is used for contact ip. + + @param ip: Remote ip + @return: Local corespond IP. + """ + result = utils.run("ip route get %s" % (ip)).stdout + ip = re.search("src (.+)", result) + if ip is not None: + ip = ip.groups()[0] + return ip + + + def get_ethernet_driver(session): + """ + Get driver of network cards. + + @param session: session to machine + """ + modules = [] + out = session.cmd("ls -l --color=never " + "/sys/class/net/*/device/driver/module") + for module in out.split("\n"): + modules.append(module.split("/")[-1]) + modules.remove("") + return set(modules) + + + def kill_and_check(vm): + vm_pid = vm.get_pid() + vm.destroy(gracefully=False) + time.sleep(2) + try: + os.kill(vm_pid, 0) + logging.error("VM is not dead") + raise error.TestFail("VM is not dead after sending signal 0 to it") + except OSError: + logging.info("VM is dead") + + + def netload_kill_problem(session_serial): + netperf_dir = os.path.join(os.environ['AUTODIR'], "tests/netperf2") + setup_cmd = params.get("setup_cmd") + clean_cmd = params.get("clean_cmd") + firewall_flush = "iptables -F" + + try: + utils.run(firewall_flush) + except: + logging.warning("Could not flush firewall rules on guest") + + try: + session_serial.cmd(firewall_flush) + except aexpect.ShellError: + logging.warning("Could not flush firewall rules on guest") + + for i in params.get("netperf_files").split(): + vm.copy_files_to(os.path.join(netperf_dir, i), "/tmp") + + guest_ip = vm.get_address(0) + server_ip = get_corespond_ip(guest_ip) + + logging.info("Setup and run netperf on host and guest") + session_serial.cmd(setup_cmd % "/tmp", timeout=200) + utils.run(setup_cmd % netperf_dir) + + try: + session_serial.cmd(clean_cmd) + except: + pass + session_serial.cmd(params.get("netserver_cmd") % "/tmp") + + utils.run(clean_cmd, ignore_status=True) + utils.run(params.get("netserver_cmd") % netperf_dir) + + server_netperf_cmd = params.get("netperf_cmd") % (netperf_dir, "TCP_STREAM", + guest_ip, params.get("packet_size", "1500")) + quest_netperf_cmd = params.get("netperf_cmd") % ("/tmp", "TCP_STREAM", + server_ip, params.get("packet_size", "1500")) + + tcpdump = env.get("tcpdump") + pid = None + if tcpdump: + # Stop the background tcpdump process + try: + pid = int(utils.system_output("pidof tcpdump")) + logging.debug("Stopping the background tcpdump") + os.kill(pid, signal.SIGSTOP) + except: + pass + + try: + logging.info("Start heavy network load host <=> guest.") + session_serial.sendline(quest_netperf_cmd) + utils.BgJob(server_netperf_cmd) + + #Wait for create big network usage. + time.sleep(10) + kill_and_check(vm) + + finally: + utils.run(clean_cmd, ignore_status=True) + if tcpdump and pid: + logging.debug("Resuming the background tcpdump") + logging.info("pid is %s" % pid) + os.kill(pid, signal.SIGCONT) + + + def netdriver_kill_problem(session_serial): + modules = get_ethernet_driver(session_serial) + logging.debug(modules) + for _ in range(50): + for module in modules: + session_serial.cmd("rmmod %s" % (module)) + time.sleep(0.2) + for module in modules: + session_serial.cmd("modprobe %s" % (module)) + time.sleep(0.2) + kill_and_check(vm) + + + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() + login_timeout = int(params.get("login_timeout", 360)) + session = vm.wait_for_login(timeout=login_timeout) + session.close() + session_serial = vm.wait_for_serial_login(timeout=login_timeout) + + mode = params.get("mode") + if mode == "driver": + netdriver_kill_problem(session_serial) + elif mode == "load": + netload_kill_problem(session_serial)