Blame SOURCES/kvm-qemu-iotests-Test-I-O-limits-with-removable-media.patch

4a2fec
From 3725eae71ddcc6f053793a530c1f4e3a43e9c4df Mon Sep 17 00:00:00 2001
4a2fec
From: Stefan Hajnoczi <stefanha@redhat.com>
4a2fec
Date: Fri, 17 Nov 2017 11:19:07 +0100
4a2fec
Subject: [PATCH 08/15] qemu-iotests: Test I/O limits with removable media
4a2fec
4a2fec
RH-Author: Stefan Hajnoczi <stefanha@redhat.com>
4a2fec
Message-id: <20171117111908.8815-9-stefanha@redhat.com>
4a2fec
Patchwork-id: 77743
4a2fec
O-Subject: [RHV7.5 qemu-kvm-rhev PATCH 8/9] qemu-iotests: Test I/O limits with removable media
4a2fec
Bugzilla: 1492295
4a2fec
RH-Acked-by: John Snow <jsnow@redhat.com>
4a2fec
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
4a2fec
RH-Acked-by: Thomas Huth <thuth@redhat.com>
4a2fec
4a2fec
From: Alberto Garcia <berto@igalia.com>
4a2fec
4a2fec
This test hotplugs a CD drive to a VM and checks that I/O limits can
4a2fec
be set only when the drive has media inserted and that they are kept
4a2fec
when the media is replaced.
4a2fec
4a2fec
This also tests the removal of a device with valid I/O limits set but
4a2fec
no media inserted. This involves deleting and disabling the limits
4a2fec
of a BlockBackend without BlockDriverState, a scenario that has been
4a2fec
crashing until the fixes from the last couple of patches.
4a2fec
4a2fec
[Python PEP8 fixup: "Don't use spaces are the = sign when used to
4a2fec
indicate a keyword argument or a default parameter value"
4a2fec
--Stefan]
4a2fec
4a2fec
Signed-off-by: Alberto Garcia <berto@igalia.com>
4a2fec
Reviewed-by: Max Reitz <mreitz@redhat.com>
4a2fec
Message-id: 071eb397118ed207c5a7f01d58766e415ee18d6a.1510339534.git.berto@igalia.com
4a2fec
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
4a2fec
(cherry picked from commit 0761562687e0d8135310a94b1d3e08376387c027)
4a2fec
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
4a2fec
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
4a2fec
---
4a2fec
 tests/qemu-iotests/093     | 62 ++++++++++++++++++++++++++++++++++++++++++++++
4a2fec
 tests/qemu-iotests/093.out |  4 +--
4a2fec
 2 files changed, 64 insertions(+), 2 deletions(-)
4a2fec
4a2fec
diff --git a/tests/qemu-iotests/093 b/tests/qemu-iotests/093
4a2fec
index ef39972..5c36a5f 100755
4a2fec
--- a/tests/qemu-iotests/093
4a2fec
+++ b/tests/qemu-iotests/093
4a2fec
@@ -308,6 +308,68 @@ class ThrottleTestGroupNames(iotests.QMPTestCase):
4a2fec
             groupname = "group%d" % i
4a2fec
             self.verify_name(devname, groupname)
4a2fec
 
4a2fec
+class ThrottleTestRemovableMedia(iotests.QMPTestCase):
4a2fec
+    def setUp(self):
4a2fec
+        self.vm = iotests.VM()
4a2fec
+        if iotests.qemu_default_machine == 's390-ccw-virtio':
4a2fec
+            self.vm.add_device("virtio-scsi-ccw,id=virtio-scsi")
4a2fec
+        else:
4a2fec
+            self.vm.add_device("virtio-scsi-pci,id=virtio-scsi")
4a2fec
+        self.vm.launch()
4a2fec
+
4a2fec
+    def tearDown(self):
4a2fec
+        self.vm.shutdown()
4a2fec
+
4a2fec
+    def test_removable_media(self):
4a2fec
+        # Add a couple of dummy nodes named cd0 and cd1
4a2fec
+        result = self.vm.qmp("blockdev-add", driver="null-aio",
4a2fec
+                             node_name="cd0")
4a2fec
+        self.assert_qmp(result, 'return', {})
4a2fec
+        result = self.vm.qmp("blockdev-add", driver="null-aio",
4a2fec
+                             node_name="cd1")
4a2fec
+        self.assert_qmp(result, 'return', {})
4a2fec
+
4a2fec
+        # Attach a CD drive with cd0 inserted
4a2fec
+        result = self.vm.qmp("device_add", driver="scsi-cd",
4a2fec
+                             id="dev0", drive="cd0")
4a2fec
+        self.assert_qmp(result, 'return', {})
4a2fec
+
4a2fec
+        # Set I/O limits
4a2fec
+        args = { "id": "dev0", "iops": 100, "iops_rd": 0, "iops_wr": 0,
4a2fec
+                                "bps":  50,  "bps_rd": 0,  "bps_wr": 0 }
4a2fec
+        result = self.vm.qmp("block_set_io_throttle", conv_keys=False, **args)
4a2fec
+        self.assert_qmp(result, 'return', {})
4a2fec
+
4a2fec
+        # Check that the I/O limits have been set
4a2fec
+        result = self.vm.qmp("query-block")
4a2fec
+        self.assert_qmp(result, 'return[0]/inserted/iops', 100)
4a2fec
+        self.assert_qmp(result, 'return[0]/inserted/bps',   50)
4a2fec
+
4a2fec
+        # Now eject cd0 and insert cd1
4a2fec
+        result = self.vm.qmp("blockdev-open-tray", id='dev0')
4a2fec
+        self.assert_qmp(result, 'return', {})
4a2fec
+        result = self.vm.qmp("x-blockdev-remove-medium", id='dev0')
4a2fec
+        self.assert_qmp(result, 'return', {})
4a2fec
+        result = self.vm.qmp("x-blockdev-insert-medium", id='dev0', node_name='cd1')
4a2fec
+        self.assert_qmp(result, 'return', {})
4a2fec
+
4a2fec
+        # Check that the I/O limits are still the same
4a2fec
+        result = self.vm.qmp("query-block")
4a2fec
+        self.assert_qmp(result, 'return[0]/inserted/iops', 100)
4a2fec
+        self.assert_qmp(result, 'return[0]/inserted/bps',   50)
4a2fec
+
4a2fec
+        # Eject cd1
4a2fec
+        result = self.vm.qmp("x-blockdev-remove-medium", id='dev0')
4a2fec
+        self.assert_qmp(result, 'return', {})
4a2fec
+
4a2fec
+        # Check that we can't set limits if the device has no medium
4a2fec
+        result = self.vm.qmp("block_set_io_throttle", conv_keys=False, **args)
4a2fec
+        self.assert_qmp(result, 'error/class', 'GenericError')
4a2fec
+
4a2fec
+        # Remove the CD drive
4a2fec
+        result = self.vm.qmp("device_del", id='dev0')
4a2fec
+        self.assert_qmp(result, 'return', {})
4a2fec
+
4a2fec
 
4a2fec
 if __name__ == '__main__':
4a2fec
     iotests.main(supported_fmts=["raw"])
4a2fec
diff --git a/tests/qemu-iotests/093.out b/tests/qemu-iotests/093.out
4a2fec
index 2f7d390..594c16f 100644
4a2fec
--- a/tests/qemu-iotests/093.out
4a2fec
+++ b/tests/qemu-iotests/093.out
4a2fec
@@ -1,5 +1,5 @@
4a2fec
-.......
4a2fec
+........
4a2fec
 ----------------------------------------------------------------------
4a2fec
-Ran 7 tests
4a2fec
+Ran 8 tests
4a2fec
 
4a2fec
 OK
4a2fec
-- 
4a2fec
1.8.3.1
4a2fec