Skip to contentSkip to conversation

KVM-test: Add subtest: usb

RFC PATCH In review Amos Kong 2 participants 6 messages Jul 29, 2011 – Aug 3, 2011 KVM

lore
Share & tools
lore

Amos Kong

author
#0 lore raw

RFC PATCH 1/1 KVM-test: Add subtest: usb

This test adds a usb storage for the guest, and do some check from monitor and inside the guest.
It's not very stable, could you help to review if something is wrong?

@ qemu-kvm -drive file='vm.qcow2',index=0,if=virtio,cache=none
-device usb-ehci,id=ehci
-drive file='/tmp/kvm_autotest_root/images/usbdevice.qcow2',if=none,cache=none,id=usb2.1 -device usb-storage,bus=ehci.0,drive=usb2.1,port=2
12:42:16 INFO | (qemu) *** EHCI support is under development ***

CC Gerd Hoffmann <[email protected]>
---
 client/tests/kvm/tests/usb.py          |   49 ++++++++++++++++++++++++++++++++
 client/tests/kvm/tests_base.cfg.sample |   15 ++++++++++
 2 files changed, 64 insertions(+), 0 deletions(-)
 create mode 100644 client/tests/kvm/tests/usb.py
client/tests/kvm/tests/usb.py new file +49 -0
new file mode 100644
index 0000000..2134820
@@ -0,0 +1,49 @@
+import logging
+from autotest_lib.client.common_lib import error
+
+
[email protected]_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.get_command_output("lsusb")
+    #no bus specified, default using "usb.0" for "usb-storage"
+    if "ID 0000:0000" not in output:
+        logging.debug(output)
+        raise error.TestFail("No 'ID 0000:0000' in the output of 'lsusb'")
+
+    output = session.get_command_output("fdisk -l")
+    if params.get("fdisk_string") not in output:
+        logging.debug(output)
+        raise error.TestFail("Could not realise the usb device")
+
+    error.context("Formating usb disk")
+    dev_list = session.get_command_output("ls /dev/sd[a-z]")
+    session.cmd("yes |mkfs %s" % dev_list.split()[-1],
+                timeout=int(params.get("format_timeout")))
+
+    error.context("Checking if exist I/O error in dmesg")
+    output = session.get_command_output("dmesg")
+    if "Buffer I/O error" in output:
+        logging.debug(output)
+        raise error.TestFail("Exists I/O error when format usb device")
+    session.close()
client/tests/kvm/tests_base.cfg.sample +15 -0
index d597b52..41e2553 100644
@@ -1115,6 +1115,21 @@ variants:
         image_snapshot = yes
         only Linux
 
+    - 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 = "Units = cylinders of 20 * 512 = 10240 bytes"
+        only Linux
+
 
 # NICs
 variants:
#1 lore raw
Quoted 3 lines · Amos Kong

This test adds a usb storage for the guest, and do some check from monitor and inside the guest.
It's not very stable, could you help to review if something is wrong?

"Not stable" means what exactly?

client/tests/kvm/tests/usb.py line 32

Quoted 5 lines
client/tests/kvm/tests/usb.py new file +5 -0
+    output = session.get_command_output("lsusb")
+    #no bus specified, default using "usb.0" for "usb-storage"
+    if "ID 0000:0000" not in output:
+        logging.debug(output)
+        raise error.TestFail("No 'ID 0000:0000' in the output of 'lsusb'")

You can use "lsusb -v" here, then you get something better to match. Also lsusb does some more usb requests then. Should also check for errors in the lsusb output.

client/tests/kvm/tests/usb.py line 42

Quoted 9 lines
client/tests/kvm/tests/usb.py new file +9 -0
+    output = session.get_command_output("fdisk -l")
+    if params.get("fdisk_string") not in output:
+        logging.debug(output)
+        raise error.TestFail("Could not realise the usb device")
+
+    error.context("Formating usb disk")
+    dev_list = session.get_command_output("ls /dev/sd[a-z]")
+    session.cmd("yes |mkfs %s" % dev_list.split()[-1],
+                timeout=int(params.get("format_timeout")))

You can look at /dev/disk/by-path/ to figure which /dev/sd<x> the usb flashdrive is.

cheers,
Gerd

author
#2 lore raw

----- Original Message -----

Quoted 8 lines · Amos Kong
Quoted 5 lines

This test adds a usb storage for the guest, and do some check from monitor and
inside the guest.
It's not very stable, could you help to review if something is wrong?

"Not stable" means what exactly?

I found you had added new cmdline support of usb(ahci,usb2) for autotest. But it's not supported right now.

"12:42:16 INFO | (qemu) *** EHCI support is under development ***"

So I plan to use old options, "-usbdevice disk:format=qcow2:/tmp/usbdevice.qcow2". guest can identify the new disk.

Quoted 9 lines
Quoted 5 lines

+ output = session.get_command_output("lsusb")
+ #no bus specified, default using "usb.0" for "usb-storage"
+ if "ID 0000:0000" not in output:
+ logging.debug(output)
+ raise error.TestFail("No 'ID 0000:0000' in the output of 'lsusb'")

You can use "lsusb -v" here, then you get something better to match. Also lsusb does some more usb requests then. Should also check for errors in the lsusb output.

Thanks for your comments, will send V2 later.

Quoted 10 lines
Quoted 9 lines

+ output = session.get_command_output("fdisk -l")
+ if params.get("fdisk_string") not in output:
+ logging.debug(output)
+ raise error.TestFail("Could not realise the usb device") +
+ error.context("Formating usb disk")
+ dev_list = session.get_command_output("ls /dev/sd[a-z]")
+ session.cmd("yes |mkfs %s" % dev_list.split()[-1],
+ timeout=int(params.get("format_timeout")))

Quoted 2 lines

You can look at /dev/disk/by-path/ to figure which /dev/sd<x> the usb flashdrive is.

ok.

Quoted 2 lines

cheers,
Gerd

#3 lore raw

Hi,

Quoted 4 lines

I found you had added new cmdline support of usb(ahci,usb2) for autotest. But it's not supported right now.

"12:42:16 INFO | (qemu) *** EHCI support is under development ***"

It should work fine nevertheless. EHCI still lacks some stuff such as migration support, thats why I didn't remove that banner yet.

Quoted 1 line

So I plan to use old options, "-usbdevice disk:format=qcow2:/tmp/usbdevice.qcow2".

That will give you a flashdrive on a UHCI (USB 1.1) port instead of EHCI (USB 2.0). Will be slower. Should work just fine too.

cheers,
Gerd

author
#4 lore raw

PATCH v2 1/1 KVM-test: Add subtest: usb

In reply to Gerd Hoffmann

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

CC Gerd Hoffmann <[email protected]>
---
 client/tests/kvm/tests/usb.py          |   50 ++++++++++++++++++++++++++++++++
 client/tests/kvm/tests_base.cfg.sample |    9 ++++++
 2 files changed, 59 insertions(+), 0 deletions(-)
 create mode 100644 client/tests/kvm/tests/usb.py
client/tests/kvm/tests/usb.py new file +50 -0
new file mode 100644
index 0000000..d1849de
@@ -0,0 +1,50 @@
+import logging
+from autotest_lib.client.common_lib import error
+
+
[email protected]_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.get_command_output("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.get_command_output("fdisk -l")
+    if params.get("fdisk_string") not in output:
+        logging.debug(output)
+        raise error.TestFail("Could not realise the usb device")
+
+    error.context("Formating usb disk")
+    devname = session.get_command_output("ls /dev/disk/by-path/*|grep usb")
+    session.cmd("yes |mkfs %s" % devname,
+                timeout=int(params.get("format_timeout")))
+
+    error.context("Checking if exist I/O error in dmesg")
+    output = session.get_command_output("dmesg")
+    if "Buffer I/O error" in output:
+        logging.debug(output)
+        raise error.TestFail("Exists I/O error when format usb device")
+    session.close()
client/tests/kvm/tests_base.cfg.sample +9 -0
index d597b52..a4e9a93 100644
@@ -1115,6 +1115,15 @@ variants:
         image_snapshot = yes
         only Linux
 
+    - usb: install setup image_copy unattended_install.cdrom
+        type = usb
+        kill_vm = yes
+        format_timeout = 400
+        extra_params += " -usbdevice disk:format=qcow2:/tmp/usbdevice.qcow2"
+        pre_command += "qemu-img create -f qcow2 /tmp/usbdevice.qcow2 10M;"
+        fdisk_string = "Units = cylinders of 20 * 512 = 10240 bytes"
+        only Linux
+
 
 # NICs
 variants:
author
#5 lore raw

PATCH v3 1/1 KVM-test: Add subtest: usb

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

CC Gerd Hoffmann <[email protected]>
---
 client/tests/kvm/tests/usb.py          |   50 ++++++++++++++++++++++++++++++++
 client/tests/kvm/tests_base.cfg.sample |   15 ++++++++++
 2 files changed, 65 insertions(+), 0 deletions(-)
 create mode 100644 client/tests/kvm/tests/usb.py
client/tests/kvm/tests/usb.py new file +50 -0
new file mode 100644
index 0000000..d1849de
@@ -0,0 +1,50 @@
+import logging
+from autotest_lib.client.common_lib import error
+
+
[email protected]_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.get_command_output("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.get_command_output("fdisk -l")
+    if params.get("fdisk_string") not in output:
+        logging.debug(output)
+        raise error.TestFail("Could not realise the usb device")
+
+    error.context("Formating usb disk")
+    devname = session.get_command_output("ls /dev/disk/by-path/*|grep usb")
+    session.cmd("yes |mkfs %s" % devname,
+                timeout=int(params.get("format_timeout")))
+
+    error.context("Checking if exist I/O error in dmesg")
+    output = session.get_command_output("dmesg")
+    if "Buffer I/O error" in output:
+        logging.debug(output)
+        raise error.TestFail("Exists I/O error when format usb device")
+    session.close()
client/tests/kvm/tests_base.cfg.sample +15 -0
index ccc17f6..1392898 100644
@@ -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 = "Units = cylinders of 20 * 512 = 10240 bytes"
+        only Linux
+
 
 # NICs
 variants: