public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* KVM test: Cdrom test
@ 2012-05-26  7:59 Lukáš Doktor
  2012-05-26  7:59 ` [PATCH 1/3] KVM test: cdrom_test bugfixes Lukáš Doktor
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Lukáš Doktor @ 2012-05-26  7:59 UTC (permalink / raw)
  To: autotest, kvm, kvm-autotest, lmr, ldoktor, jzupka

Hello guys,

this is a repaired version of cdrom_test, the problems were mainly device names and symlinks.

As a bonus it fixes bugs in virtio_scsi and usb_cdrom cdrom device definition in qemu_cmd.

tested on F16 using ide, virtio_scsi, ahci and usb_cdrom, using QMP and humanmonitor. (virtio_scsi and usb_stick are failing with IO errors in dmesg)

See the pull request:
https://github.com/autotest/autotest/pull/361

Regards,
Lukáš

_______________________________________________
Autotest mailing list
Autotest@test.kernel.org
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] KVM test: cdrom_test bugfixes
  2012-05-26  7:59 KVM test: Cdrom test Lukáš Doktor
@ 2012-05-26  7:59 ` Lukáš Doktor
  2012-05-26  7:59 ` [PATCH 2/3] virt.kvm_vm: Fix virtio_scsi cdrom in qemu_cmd Lukáš Doktor
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Lukáš Doktor @ 2012-05-26  7:59 UTC (permalink / raw)
  To: autotest, kvm, kvm-autotest, lmr, ldoktor, jzupka

* fix another issues with symlinks and abs-paths
* detect the right cdrom device
* fix issue with locked cdrom (workaround not needed)
* improve comments and code-style (pylint)

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>
---
 client/tests/kvm/tests/cdrom.py |  151 +++++++++++++++++++--------------------
 client/virt/subtests.cfg.sample |    6 +-
 2 files changed, 79 insertions(+), 78 deletions(-)

diff --git a/client/tests/kvm/tests/cdrom.py b/client/tests/kvm/tests/cdrom.py
index 82aaa34..089150b 100644
--- a/client/tests/kvm/tests/cdrom.py
+++ b/client/tests/kvm/tests/cdrom.py
@@ -18,22 +18,31 @@ def run_cdrom(test, params, env):
 
     1) Boot up a VM with one iso.
     2) Check if VM identifies correctly the iso file.
-    3) Eject cdrom using monitor and change with another iso several times.
-    4) Eject cdrom in guest and check tray status reporting.
-    5) Try to format cdrom and check the return string.
-    6) Mount cdrom device.
-    7) Copy file from cdrom and compare files using diff.
-    8) Umount and mount several times.
+    3) * If cdrom_test_autounlock is set, verifies that device is unlocked
+       <300s after boot
+    4) Eject cdrom using monitor and change with another iso several times.
+    5) Eject cdrom in guest and check tray status reporting.
+    6) Try to format cdrom and check the return string.
+    7) Mount cdrom device.
+    8) Copy file from cdrom and compare files using diff.
+    9) Umount and mount several times.
 
     @param test: kvm test object
     @param params: Dictionary with the test parameters
     @param env: Dictionary with test environment.
+
+    @param cfg: workaround_eject_time - Some versions of qemu are unable to
+                                        eject CDROM directly after insert
+    @param cfg: cdrom_test_autounlock - Test whether guest OS unlocks cdrom
+                                        after boot (<300s after VM is booted)
     """
     def master_cdroms(params):
         """ Creates 'new' cdrom with one file on it """
         error.context("creating test cdrom")
         os.chdir(test.tmpdir)
         cdrom_cd1 = params.get("cdrom_cd1")
+        if not os.path.isabs(cdrom_cd1):
+            cdrom_cd1 = os.path.join(test.bindir, cdrom_cd1)
         cdrom_dir = os.path.realpath(os.path.dirname(cdrom_cd1))
         utils.run("dd if=/dev/urandom of=orig bs=10M count=1")
         utils.run("dd if=/dev/urandom of=new bs=10M count=1")
@@ -41,44 +50,47 @@ def run_cdrom(test, params, env):
         utils.run("mkisofs -o %s/new.iso new" % cdrom_dir)
         return "%s/new.iso" % cdrom_dir
 
-
     def cleanup_cdroms(cdrom_dir):
         """ Removes created cdrom """
         error.context("cleaning up temp cdrom images")
         os.remove("%s/new.iso" % cdrom_dir)
 
-
-    def get_cdrom_info():
+    def get_block_info(re_device='[^\n][^:]+'):
         """ Gets device string and file from kvm-monitor """
         blocks = vm.monitor.info("block")
-        (device, file) = (None, None)
+        devices = []
+        files = []
         if isinstance(blocks, str):
-            try:
-                device = re.findall("(\w+\d+-cd\d+): .*", blocks)[0]
-            except IndexError:
-                device = None
-            try:
-                file = re.findall("\w+\d+-cd\d+: .*file=(\S*) ", blocks)[0]
-                file = os.path.realpath(file)
-            except IndexError:
-                file = None
+            devices = re.findall('(%s): .*' % re_device, blocks)
+            if devices:
+                for dev in devices:
+                    cdfile = re.findall('%s: .*file=(\S*) ' % dev, blocks)
+                    if cdfile:
+                        cdfile = os.path.realpath(cdfile[0])
+                    else:
+                        cdfile = None
+                    files.append(cdfile)
         else:
             for block in blocks:
-                d = block['device']
-                try:
-                    device = re.findall("(\w+\d+-cd\d+)", d)[0]
-                except IndexError:
-                    device = None
-                    continue
-                try:
-                    file = block['inserted']['file']
-                    file = os.path.realpath(file)
-                except KeyError:
-                    file = None
-                break
-        logging.debug("Device name: %s, ISO: %s", device, file)
-        return (device, file)
-
+                if re.match(re_device, block['device']):
+                    devices.append(block['device'])
+                    try:
+                        cdfile = block['inserted']['file']
+                        if cdfile:
+                            cdfile = os.path.realpath(cdfile)
+                    except KeyError:
+                        cdfile = None
+                    files.append(cdfile)
+        return (devices, files)
+
+    def get_cdrom_info(device):
+        """
+        @param device: qemu monitor device
+        @return: file associated with $device device
+        """
+        (_, cdfile) = get_block_info(device)
+        logging.debug("Device name: %s, ISO: %s", device, cdfile[0])
+        return cdfile[0]
 
     def check_cdrom_locked(cdrom):
         """ Checks whether the cdrom is locked """
@@ -95,7 +107,6 @@ def run_cdrom(test, params, env):
                     return block['locked']
         return False
 
-
     def check_cdrom_tray(cdrom):
         """ Checks whether the tray is opend """
         blocks = vm.monitor.info("block")
@@ -112,18 +123,12 @@ def run_cdrom(test, params, env):
                     return block['tray_open']
         raise error.TestNAError('cdrom tray reporting not supported')
 
-
     def eject_cdrom(device, monitor):
         """ Ejects the cdrom using kvm-monitor """
         if isinstance(monitor, kvm_monitor.HumanMonitor):
             monitor.cmd("eject %s" % device)
         elif isinstance(monitor, kvm_monitor.QMPMonitor):
-            try:
-                monitor.cmd("eject", args={'device': device})
-            except kvm_monitor.QMPCmdError, details:
-                if workaround_locked_cdrom == 1:    # no workaround, raise err
-                    raise details
-
+            monitor.cmd("eject", args={'device': device})
 
     def change_cdrom(device, target, monitor):
         """ Changes the medium using kvm-monitor """
@@ -132,27 +137,23 @@ def run_cdrom(test, params, env):
         elif isinstance(monitor, kvm_monitor.QMPMonitor):
             monitor.cmd("change", args={'device': device, 'target': target})
 
-
     cdrom_new = master_cdroms(params)
     cdrom_dir = os.path.dirname(cdrom_new)
     vm = env.get_vm(params["main_vm"])
-    if vm.is_dead() or vm.needs_restart(vm.name, params, vm.root_dir):
-        vm.create()
+    vm.create()
 
-    # Some versions of qemu won't unlock CDROM
-    if params.get('workaround_locked_cdrom', 'no') == 'yes':
-        workaround_locked_cdrom = 20
-    else:
-        workaround_locked_cdrom = 1
     # Some versions of qemu are unable to eject CDROM directly after insert
     workaround_eject_time = float(params.get('workaround_eject_time', 0))
 
     session = vm.wait_for_login(timeout=int(params.get("login_timeout", 360)))
-    cdrom_orig = os.path.realpath(params.get("cdrom_cd1"))
+    cdrom_orig = params.get("cdrom_cd1")
+    if not os.path.isabs(cdrom_orig):
+        cdrom_orig = os.path.join(test.bindir, cdrom_orig)
+    cdrom_orig = os.path.realpath(cdrom_orig)
     cdrom = cdrom_orig
     output = session.get_command_output("ls /dev/cdrom*")
     cdrom_dev_list = re.findall("/dev/cdrom-\w+|/dev/cdrom\d*", output)
-    logging.debug("cdrom_dev_list: %s" % cdrom_dev_list)
+    logging.debug("cdrom_dev_list: %s", cdrom_dev_list)
 
     cdrom_dev = ""
     test_cmd = "dd if=%s of=/dev/null bs=1 count=1"
@@ -167,26 +168,28 @@ def run_cdrom(test, params, env):
         raise error.TestFail("Could not find a valid cdrom device")
 
     error.context("Detecting the existence of a cdrom")
-    (device, file) = get_cdrom_info()
-    if file != cdrom:
+    cdfile = ''
+    (_device, _file) = get_block_info()
+    for i in range(len(_file)):
+        if _file[i] == cdrom:
+            cdfile = _file[i]
+            device = _device[i]
+    if cdfile != cdrom:
         raise error.TestFail("Could not find a valid cdrom device")
 
     session.get_command_output("umount %s" % cdrom_dev)
-    if workaround_locked_cdrom is not 1:
+    if params.get('cdrom_test_autounlock') == 'yes':
         error.context("Trying to unlock the cdrom")
-        if not virt_utils.wait_for(lambda: not check_cdrom_locked(file), 300):
+        if not virt_utils.wait_for(lambda: not check_cdrom_locked(cdfile),
+                                   300):
             raise error.TestFail("Device %s could not be unlocked" % device)
 
     max_times = int(params.get("max_times", 100))
     error.context("Eject the cdrom in monitor %s times" % max_times)
     for i in range(1, max_times):
-        for _ in range(workaround_locked_cdrom):
-            eject_cdrom(device, vm.monitor)
-            (device, file) = get_cdrom_info()
-            if file is None:
-                break
-            time.sleep(1)
-        if file is not None:
+        session.cmd('eject %s' % cdrom_dev)
+        eject_cdrom(device, vm.monitor)
+        if get_cdrom_info(device) is not None:
             raise error.TestFail("Device %s was not ejected (%s)" % (cdrom, i))
 
         cdrom = cdrom_new
@@ -194,10 +197,10 @@ def run_cdrom(test, params, env):
         if i % 2 == 0:
             cdrom = cdrom_orig
         change_cdrom(device, cdrom, vm.monitor)
-        (device, file) = get_cdrom_info()
-        if file != cdrom:
+        if get_cdrom_info(device) != cdrom:
             raise error.TestFail("It wasn't possible to change cdrom %s (%s)"
                                   % (cdrom, i))
+        time.sleep(workaround_eject_time)
 
     error.context('Eject the cdrom in guest %s times' % max_times)
     for i in range(1, max_times):
@@ -245,20 +248,16 @@ def run_cdrom(test, params, env):
 
     error.context("Cleanup")
     # Return the cdrom_orig
-    (device, file) = get_cdrom_info()
-    if file != cdrom_orig:
-        for _ in range(workaround_locked_cdrom):
-            eject_cdrom(device, vm.monitor)
-            (device, file) = get_cdrom_info()
-            if file is None:
-                break
-            time.sleep(1)
-        if file is not None:
+    cdfile = get_cdrom_info(device)
+    if cdfile != cdrom_orig:
+        time.sleep(workaround_eject_time)
+        session.cmd('eject %s' % cdrom_dev)
+        eject_cdrom(device, vm.monitor)
+        if get_cdrom_info(device) is not None:
             raise error.TestFail("Device %s was not ejected (%s)" % (cdrom, i))
 
         change_cdrom(device, cdrom_orig, vm.monitor)
-        (device, file) = get_cdrom_info()
-        if file != cdrom_orig:
+        if get_cdrom_info(device) != cdrom_orig:
             raise error.TestFail("It wasn't possible to change cdrom %s (%s)"
                                   % (cdrom, i))
 
diff --git a/client/virt/subtests.cfg.sample b/client/virt/subtests.cfg.sample
index 5b9af12..8f3987f 100644
--- a/client/virt/subtests.cfg.sample
+++ b/client/virt/subtests.cfg.sample
@@ -1749,8 +1749,10 @@ variants:
         start_vm = no
         kill_vm_on_error = yes
         max_times = 20
-        workaround_locked_cdrom = yes
-        workaround_eject_time = 2
+        # test whether cdrom is unlocked <300s after boot
+        cdrom_test_autounlock = no
+        # wait before eject $cdrom (let OS initialize cdrom ...)
+        workaround_eject_time = 0
 
     - floppy_test: install setup image_copy unattended_install.cdrom
         only Linux
-- 
1.7.7.6

_______________________________________________
Autotest mailing list
Autotest@test.kernel.org
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] virt.kvm_vm: Fix virtio_scsi cdrom in qemu_cmd
  2012-05-26  7:59 KVM test: Cdrom test Lukáš Doktor
  2012-05-26  7:59 ` [PATCH 1/3] KVM test: cdrom_test bugfixes Lukáš Doktor
@ 2012-05-26  7:59 ` Lukáš Doktor
  2012-05-26  7:59 ` [PATCH 3/3] virt.kvm_vm: Fix usb2 " Lukáš Doktor
  2012-05-26 22:01 ` KVM test: Cdrom test Lucas Meneghel Rodrigues
  3 siblings, 0 replies; 5+ messages in thread
From: Lukáš Doktor @ 2012-05-26  7:59 UTC (permalink / raw)
  To: autotest, kvm, kvm-autotest, lmr, ldoktor, jzupka

fixes incorrect bus name for virtio_scsi cdroms.

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>
---
 client/virt/kvm_vm.py |   18 ++++++------------
 1 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/client/virt/kvm_vm.py b/client/virt/kvm_vm.py
index 19d016f..6bc1ae6 100644
--- a/client/virt/kvm_vm.py
+++ b/client/virt/kvm_vm.py
@@ -272,7 +272,7 @@ class VM(virt_vm.BaseVM):
         def add_smp(help, smp):
             return " -smp %s" % smp
 
-        def add_cdrom(help, filename, index=None, format=None):
+        def add_cdrom(help, filename, index=None, format=None, bus=None):
             if has_option(help, "drive"):
                 name = None;
                 dev = "";
@@ -290,8 +290,9 @@ class VM(virt_vm.BaseVM):
                 if format is not None and format.startswith("scsi-"):
                     # handles scsi-{hd, cd, disk, block, generic} targets
                     name = "virtio-scsi-cd%s" % index
-                    dev += (" -device %s,drive=%s,bus=virtio_scsi_pci.0" %
+                    dev += (" -device %s,drive=%s" %
                             (format, name))
+                    dev += _add_option("bus", "virtio_scsi_pci%d.0" % bus)
                     format = "none"
                     index = None
                 cmd = " -drive file='%s',media=cdrom" % filename
@@ -853,18 +854,11 @@ class VM(virt_vm.BaseVM):
             cd_format = params.get("cd_format", "")
             cdrom_params = params.object_params(cdrom)
             iso = cdrom_params.get("cdrom")
+            bus = None
             if cd_format == "ahci" and not have_ahci:
                 qemu_cmd += " -device ahci,id=ahci"
                 have_ahci = True
-            if cd_format.startswith("scsi-"):
-                bus = cdrom_params.get("drive_bus")
-                if bus and bus not in virtio_scsi_pcis:
-                    qemu_cmd += " -device virtio-scsi,id=%s" % bus
-                    virtio_scsi_pcis.append(bus)
-                elif not virtio_scsi_pcis:
-                    qemu_cmd += " -device virtio-scsi,id=virtio_scsi_pci0"
-                    virtio_scsi_pcis.append("virtio_scsi_pci0")
-            if cd_format.startswith("scsi-"):
+            if cd_format and cd_format.startswith("scsi-"):
                 try:
                     bus = int(cdrom_params.get("drive_bus", 0))
                 except ValueError:
@@ -876,7 +870,7 @@ class VM(virt_vm.BaseVM):
             if iso:
                 qemu_cmd += add_cdrom(help, virt_utils.get_path(root_dir, iso),
                                       cdrom_params.get("drive_index"),
-                                      cd_format)
+                                      cd_format, bus)
 
         # We may want to add {floppy_otps} parameter for -fda
         # {fat:floppy:}/path/. However vvfat is not usually recommended.
-- 
1.7.7.6

_______________________________________________
Autotest mailing list
Autotest@test.kernel.org
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] virt.kvm_vm: Fix usb2 cdrom in qemu_cmd
  2012-05-26  7:59 KVM test: Cdrom test Lukáš Doktor
  2012-05-26  7:59 ` [PATCH 1/3] KVM test: cdrom_test bugfixes Lukáš Doktor
  2012-05-26  7:59 ` [PATCH 2/3] virt.kvm_vm: Fix virtio_scsi cdrom in qemu_cmd Lukáš Doktor
@ 2012-05-26  7:59 ` Lukáš Doktor
  2012-05-26 22:01 ` KVM test: Cdrom test Lucas Meneghel Rodrigues
  3 siblings, 0 replies; 5+ messages in thread
From: Lukáš Doktor @ 2012-05-26  7:59 UTC (permalink / raw)
  To: autotest, kvm, kvm-autotest, lmr, ldoktor, jzupka

fixes missing bus and port for usb2 cdroms.

Signed-off-by: Lukáš Doktor <ldoktor@redhat.com>
---
 client/virt/guest-hw.cfg.sample |    2 ++
 client/virt/kvm_vm.py           |   12 +++++++++---
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/client/virt/guest-hw.cfg.sample b/client/virt/guest-hw.cfg.sample
index 655ac9b..d6a5ae2 100644
--- a/client/virt/guest-hw.cfg.sample
+++ b/client/virt/guest-hw.cfg.sample
@@ -75,6 +75,8 @@ variants:
         usb_type_default-ehci = usb-ehci
     - usb_cdrom:
         cd_format=usb2
+        usbs += " default-ehci-cd"
+        usb_type_default-ehci-cd = usb-ehci
     - xenblk:
         # placeholder
 
diff --git a/client/virt/kvm_vm.py b/client/virt/kvm_vm.py
index 6bc1ae6..fcd3233 100644
--- a/client/virt/kvm_vm.py
+++ b/client/virt/kvm_vm.py
@@ -272,7 +272,8 @@ class VM(virt_vm.BaseVM):
         def add_smp(help, smp):
             return " -smp %s" % smp
 
-        def add_cdrom(help, filename, index=None, format=None, bus=None):
+        def add_cdrom(help, filename, index=None, format=None, bus=None,
+                      port=None):
             if has_option(help, "drive"):
                 name = None;
                 dev = "";
@@ -283,8 +284,10 @@ class VM(virt_vm.BaseVM):
                     index = None
                 if format == "usb2":
                     name = "usb2.%s" % index
-                    dev += " -device usb-storage,bus=ehci.0,drive=%s" % name
-                    dev += ",port=%d" % (int(index) + 1)
+                    dev += " -device usb-storage"
+                    dev += _add_option("bus", bus)
+                    dev += _add_option("port", port)
+                    dev += _add_option("drive", name)
                     format = "none"
                     index = None
                 if format is not None and format.startswith("scsi-"):
@@ -855,6 +858,9 @@ class VM(virt_vm.BaseVM):
             cdrom_params = params.object_params(cdrom)
             iso = cdrom_params.get("cdrom")
             bus = None
+            port = None
+            if cd_format == "usb2":
+                bus, port = get_free_usb_port(image_name, "ehci")
             if cd_format == "ahci" and not have_ahci:
                 qemu_cmd += " -device ahci,id=ahci"
                 have_ahci = True
-- 
1.7.7.6

_______________________________________________
Autotest mailing list
Autotest@test.kernel.org
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: KVM test: Cdrom test
  2012-05-26  7:59 KVM test: Cdrom test Lukáš Doktor
                   ` (2 preceding siblings ...)
  2012-05-26  7:59 ` [PATCH 3/3] virt.kvm_vm: Fix usb2 " Lukáš Doktor
@ 2012-05-26 22:01 ` Lucas Meneghel Rodrigues
  3 siblings, 0 replies; 5+ messages in thread
From: Lucas Meneghel Rodrigues @ 2012-05-26 22:01 UTC (permalink / raw)
  To: Lukáš Doktor; +Cc: autotest, kvm-autotest, kvm

On Sat, 2012-05-26 at 09:59 +0200, Lukáš Doktor wrote:
> Hello guys,
> 
> this is a repaired version of cdrom_test, the problems were mainly device names and symlinks.
> 
> As a bonus it fixes bugs in virtio_scsi and usb_cdrom cdrom device definition in qemu_cmd.
> 
> tested on F16 using ide, virtio_scsi, ahci and usb_cdrom, using QMP and humanmonitor. (virtio_scsi and usb_stick are failing with IO errors in dmesg)
> 
> See the pull request:
> https://github.com/autotest/autotest/pull/361

As noted on github, this looks good and was applied to next. Thanks
Lukas!

> Regards,
> Lukáš
> 


_______________________________________________
Autotest mailing list
Autotest@test.kernel.org
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-05-26 22:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-26  7:59 KVM test: Cdrom test Lukáš Doktor
2012-05-26  7:59 ` [PATCH 1/3] KVM test: cdrom_test bugfixes Lukáš Doktor
2012-05-26  7:59 ` [PATCH 2/3] virt.kvm_vm: Fix virtio_scsi cdrom in qemu_cmd Lukáš Doktor
2012-05-26  7:59 ` [PATCH 3/3] virt.kvm_vm: Fix usb2 " Lukáš Doktor
2012-05-26 22:01 ` KVM test: Cdrom test Lucas Meneghel Rodrigues

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox