From patchwork Wed Aug 3 21:06:05 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: 1032432 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 p73L6IQ4013399 for ; Wed, 3 Aug 2011 21:06:18 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755316Ab1HCVGM (ORCPT ); Wed, 3 Aug 2011 17:06:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36715 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752956Ab1HCVGK (ORCPT ); Wed, 3 Aug 2011 17:06:10 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p73L69pP021000 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 3 Aug 2011 17:06:09 -0400 Received: from freedom.redhat.com (vpn-8-156.rdu.redhat.com [10.11.8.156]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p73L67Bg015078; Wed, 3 Aug 2011 17:06:08 -0400 From: Lucas Meneghel Rodrigues To: autotest@test.kernel.org Cc: kvm@vger.kernel.org, Amos Kong , Gerd Hoffmann Subject: [PATCH] KVM-test: Add subtest: usb v4 Date: Wed, 3 Aug 2011 18:06:05 -0300 Message-Id: <1312405565-32444-1-git-send-email-lmr@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 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]); Wed, 03 Aug 2011 21:06:19 +0000 (UTC) From: Amos Kong This test adds a usb storage for the guest, and do some check from monitor and inside the guest. Changes from v1: - use old options to add a usb disk to guest '-usbdevice disk:format=qcow2:/tmp/usbdevice.qcow2' - identify device name of new disk by '/dev/disk/by-path/' - match device with the detail output of 'lsusb -v' - create disk image by pre_cmd Changes from v2: - reuse the new interface to add a usb disk to guest - report a rh-bug 727725 Changes from v3: - Use a better string matching pattern for fdisk output - Mount USB device, copy file to it, unmount, mount again and then compare the md5sum of both files CC: Gerd Hoffmann Signed-off-by: Amos Kong Acked-by: Gerd Hoffmann --- client/tests/kvm/tests/usb.py | 90 ++++++++++++++++++++++++++++++++ client/tests/kvm/tests_base.cfg.sample | 15 +++++ 2 files changed, 105 insertions(+), 0 deletions(-) create mode 100644 client/tests/kvm/tests/usb.py diff --git a/client/tests/kvm/tests/usb.py b/client/tests/kvm/tests/usb.py new file mode 100644 index 0000000..4d4aa30 --- /dev/null +++ b/client/tests/kvm/tests/usb.py @@ -0,0 +1,90 @@ +import logging, os +from autotest_lib.client.common_lib import error + + +@error.context_aware +def run_usb(test, params, env): + """ + Test usb device of guest + + 1) create a image file by qemu-img + 2) boot up a guest add this file as a usb device + 3) check usb device information by execute monitor/guest command + + @param test: kvm test object + @param params: Dictionary with the test parameters + @param env: Dictionary with test environment. + """ + vm = env.get_vm(params["main_vm"]) + vm.create() + + session = vm.wait_for_login(timeout=int(params.get("login_timeout", 360))) + + output = vm.monitor.cmd("info usb") + if "Product QEMU USB MSD" not in output: + logging.debug(output) + raise error.TestFail("Could not find mass storage device") + + output = session.cmd("lsusb -v") + # No bus specified, default using "usb.0" for "usb-storage" + for i in ["ID 0000:0000", "Mass Storage", "SCSI", "QEMU USB HARDDRIVE"]: + if i not in output: + logging.debug(output) + raise error.TestFail("No '%s' in the output of 'lsusb -v'" % i) + + output = session.cmd("fdisk -l") + if params.get("fdisk_string") not in output: + for line in output.splitlines(): + logging.debug(line) + raise error.TestFail("Could not detect the usb device on fdisk output") + + error.context("Formatting USB disk") + devname = session.cmd("ls /dev/disk/by-path/* | grep usb").strip() + session.cmd("yes | mkfs %s" % devname, + timeout=int(params.get("format_timeout"))) + + error.context("Mounting USB disk") + session.cmd("mount %s /mnt" % devname) + + error.context("Creating comparison file") + c_file = '/tmp/usbfile' + session.cmd("dd if=/dev/random of=%s bs=1M count=1" % c_file) + + error.context("Copying %s to USB disk" % c_file) + session.cmd("cp %s /mnt" % c_file) + + error.context("Unmounting USB disk before file comparison") + session.cmd("umount %s" % devname) + + error.context("Mounting USB disk for file comparison") + session.cmd("mount %s /mnt" % devname) + + error.context("Determining md5sum for file on root fs and in USB disk") + md5_root = session.cmd("md5sum %s" % c_file).strip() + md5_usb = session.cmd("md5sum /mnt/%s" % os.path.basename(c_file)).strip() + md5_root = md5_root.split()[0] + md5_usb = md5_usb.split()[0] + + error.context("") + if md5_root != md5_usb: + raise error.TestError("MD5 mismatch between file on root fs and on " + "USB disk") + + error.context("Unmounting USB disk after file comparison") + session.cmd("umount %s" % devname) + + error.context("Checking if there are I/O error messages in dmesg") + output = session.get_command_output("dmesg") + io_error_msg = [] + for line in output.splitlines(): + if "Buffer I/O error" in line: + io_error_msg.append(line) + + if io_error_msg: + e_msg = "IO error found on guest's dmesg when formatting USB device" + logging.error(e_msg) + for line in io_error_msg: + logging.error(line) + raise error.TestFail(e_msg) + + session.close() diff --git a/client/tests/kvm/tests_base.cfg.sample b/client/tests/kvm/tests_base.cfg.sample index ccc17f6..5012a46 100644 --- a/client/tests/kvm/tests_base.cfg.sample +++ b/client/tests/kvm/tests_base.cfg.sample @@ -1122,6 +1122,21 @@ variants: kill_vm_gracefully = no # Do not define test variants below shutdown + - usb: install setup image_copy unattended_install.cdrom + type = usb + kill_vm = yes + format_timeout = 400 + images += " stg" + image_name_stg = "usbdevice" + image_format_stg = "qcow2" + image_boot_stg = no + drive_format_stg = "usb2" + drive_index_stg = 1 + create_image_stg = yes + image_size_stg = 10M + fdisk_string = "10 MB, 10485760 bytes" + only Linux + # NICs variants: