Blame SOURCES/kvm-qemu-iotests-Check-autodel-behaviour-for-device_del.patch

9ae3a8
From 489749c38620620dced8e638c7f8d724cbb81943 Mon Sep 17 00:00:00 2001
9ae3a8
From: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Date: Thu, 7 Nov 2013 12:49:49 +0100
9ae3a8
Subject: [PATCH 58/87] qemu-iotests: Check autodel behaviour for device_del
9ae3a8
9ae3a8
RH-Author: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Message-id: <1383660558-32096-18-git-send-email-kwolf@redhat.com>
9ae3a8
Patchwork-id: 55397
9ae3a8
O-Subject: [RHEL-7.0 qemu-kvm PATCH 17/24] qemu-iotests: Check autodel behaviour for device_del
9ae3a8
Bugzilla: 978402
9ae3a8
RH-Acked-by: Fam Zheng <famz@redhat.com>
9ae3a8
RH-Acked-by: Max Reitz <mreitz@redhat.com>
9ae3a8
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
9ae3a8
9ae3a8
Block devices creates with -drive and drive_add should automatically
9ae3a8
disappear if the guest device is unplugged. blockdev-add ones shouldn't.
9ae3a8
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Reviewed-by: Max Reitz <mreitz@redhat.com>
9ae3a8
Reviewed-by: Eric Blake <eblake@redhat.com>
9ae3a8
(cherry picked from commit a9b43397a9782d028f45b63fb4affee164f85948)
9ae3a8
9ae3a8
Conflicts:
9ae3a8
	tests/qemu-iotests/group
9ae3a8
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 tests/qemu-iotests/067           |  133 ++++++++++++++++++++++++++++++++++++++
9ae3a8
 tests/qemu-iotests/067.out       |   80 +++++++++++++++++++++++
9ae3a8
 tests/qemu-iotests/common.filter |    8 ++
9ae3a8
 tests/qemu-iotests/group         |    1 +
9ae3a8
 4 files changed, 222 insertions(+), 0 deletions(-)
9ae3a8
 create mode 100644 tests/qemu-iotests/067
9ae3a8
 create mode 100644 tests/qemu-iotests/067.out
9ae3a8
9ae3a8
diff --git a/tests/qemu-iotests/067 b/tests/qemu-iotests/067
9ae3a8
new file mode 100644
9ae3a8
index 0000000..79dc38b
9ae3a8
--- /dev/null
9ae3a8
+++ b/tests/qemu-iotests/067
9ae3a8
@@ -0,0 +1,133 @@
9ae3a8
+#!/bin/bash
9ae3a8
+#
9ae3a8
+# Test automatic deletion of BDSes created by -drive/drive_add
9ae3a8
+#
9ae3a8
+# Copyright (C) 2013 Red Hat, Inc.
9ae3a8
+#
9ae3a8
+# This program is free software; you can redistribute it and/or modify
9ae3a8
+# it under the terms of the GNU General Public License as published by
9ae3a8
+# the Free Software Foundation; either version 2 of the License, or
9ae3a8
+# (at your option) any later version.
9ae3a8
+#
9ae3a8
+# This program is distributed in the hope that it will be useful,
9ae3a8
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
9ae3a8
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9ae3a8
+# GNU General Public License for more details.
9ae3a8
+#
9ae3a8
+# You should have received a copy of the GNU General Public License
9ae3a8
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
9ae3a8
+#
9ae3a8
+
9ae3a8
+# creator
9ae3a8
+owner=kwolf@redhat.com
9ae3a8
+
9ae3a8
+seq=`basename $0`
9ae3a8
+echo "QA output created by $seq"
9ae3a8
+
9ae3a8
+here=`pwd`
9ae3a8
+tmp=/tmp/$$
9ae3a8
+status=1	# failure is the default!
9ae3a8
+
9ae3a8
+# get standard environment, filters and checks
9ae3a8
+. ./common.rc
9ae3a8
+. ./common.filter
9ae3a8
+
9ae3a8
+_supported_fmt qcow2
9ae3a8
+_supported_proto file
9ae3a8
+_supported_os Linux
9ae3a8
+
9ae3a8
+function do_run_qemu()
9ae3a8
+{
9ae3a8
+    echo Testing: "$@"
9ae3a8
+    $QEMU -nographic -qmp stdio -serial none "$@"
9ae3a8
+    echo
9ae3a8
+}
9ae3a8
+
9ae3a8
+function run_qemu()
9ae3a8
+{
9ae3a8
+    do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qmp
9ae3a8
+}
9ae3a8
+
9ae3a8
+size=128M
9ae3a8
+
9ae3a8
+_make_test_img $size
9ae3a8
+
9ae3a8
+echo
9ae3a8
+echo === -drive/-device and device_del ===
9ae3a8
+echo
9ae3a8
+
9ae3a8
+run_qemu -drive file=$TEST_IMG,format=$IMGFMT,if=none,id=disk -device virtio-blk-pci,drive=disk,id=virtio0 <
9ae3a8
+{ "execute": "qmp_capabilities" }
9ae3a8
+{ "execute": "query-block" }
9ae3a8
+{ "execute": "device_del", "arguments": { "id": "virtio0" } }
9ae3a8
+{ "execute": "system_reset" }
9ae3a8
+{ "execute": "query-block" }
9ae3a8
+{ "execute": "quit" }
9ae3a8
+EOF
9ae3a8
+
9ae3a8
+echo
9ae3a8
+echo === -drive/device_add and device_del ===
9ae3a8
+echo
9ae3a8
+
9ae3a8
+run_qemu -drive file=$TEST_IMG,format=$IMGFMT,if=none,id=disk <
9ae3a8
+{ "execute": "qmp_capabilities" }
9ae3a8
+{ "execute": "query-block" }
9ae3a8
+{ "execute": "device_add",
9ae3a8
+   "arguments": { "driver": "virtio-blk-pci", "drive": "disk",
9ae3a8
+                  "id": "virtio0" } }
9ae3a8
+{ "execute": "device_del", "arguments": { "id": "virtio0" } }
9ae3a8
+{ "execute": "system_reset" }
9ae3a8
+{ "execute": "query-block" }
9ae3a8
+{ "execute": "quit" }
9ae3a8
+EOF
9ae3a8
+
9ae3a8
+echo
9ae3a8
+echo === drive_add/device_add and device_del ===
9ae3a8
+echo
9ae3a8
+
9ae3a8
+run_qemu <
9ae3a8
+{ "execute": "qmp_capabilities" }
9ae3a8
+{ "execute": "human-monitor-command",
9ae3a8
+  "arguments": { "command-line": "drive_add 0 file=$TEST_IMG,format=$IMGFMT,if=none,id=disk" } }
9ae3a8
+{ "execute": "query-block" }
9ae3a8
+{ "execute": "device_add",
9ae3a8
+   "arguments": { "driver": "virtio-blk-pci", "drive": "disk",
9ae3a8
+                  "id": "virtio0" } }
9ae3a8
+{ "execute": "device_del", "arguments": { "id": "virtio0" } }
9ae3a8
+{ "execute": "system_reset" }
9ae3a8
+{ "execute": "query-block" }
9ae3a8
+{ "execute": "quit" }
9ae3a8
+EOF
9ae3a8
+
9ae3a8
+echo
9ae3a8
+echo === blockdev_add/device_add and device_del ===
9ae3a8
+echo
9ae3a8
+
9ae3a8
+run_qemu <
9ae3a8
+{ "execute": "qmp_capabilities" }
9ae3a8
+{ "execute": "blockdev-add",
9ae3a8
+  "arguments": {
9ae3a8
+      "options": {
9ae3a8
+        "driver": "$IMGFMT",
9ae3a8
+        "id": "disk",
9ae3a8
+        "file": {
9ae3a8
+            "driver": "file",
9ae3a8
+            "filename": "$TEST_IMG"
9ae3a8
+        }
9ae3a8
+      }
9ae3a8
+    }
9ae3a8
+  }
9ae3a8
+{ "execute": "query-block" }
9ae3a8
+{ "execute": "device_add",
9ae3a8
+   "arguments": { "driver": "virtio-blk-pci", "drive": "disk",
9ae3a8
+                  "id": "virtio0" } }
9ae3a8
+{ "execute": "device_del", "arguments": { "id": "virtio0" } }
9ae3a8
+{ "execute": "system_reset" }
9ae3a8
+{ "execute": "query-block" }
9ae3a8
+{ "execute": "quit" }
9ae3a8
+EOF
9ae3a8
+
9ae3a8
+# success, all done
9ae3a8
+echo "*** done"
9ae3a8
+rm -f $seq.full
9ae3a8
+status=0
9ae3a8
diff --git a/tests/qemu-iotests/067.out b/tests/qemu-iotests/067.out
9ae3a8
new file mode 100644
9ae3a8
index 0000000..4bb9ff9
9ae3a8
--- /dev/null
9ae3a8
+++ b/tests/qemu-iotests/067.out
9ae3a8
@@ -0,0 +1,80 @@
9ae3a8
+QA output created by 067
9ae3a8
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 
9ae3a8
+
9ae3a8
+=== -drive/-device and device_del ===
9ae3a8
+
9ae3a8
+Testing: -drive file=TEST_DIR/t.qcow2,format=qcow2,if=none,id=disk -device virtio-blk-pci,drive=disk,id=virtio0
9ae3a8
+QMP_VERSION
9ae3a8
+{"return": {}}
9ae3a8
+{"return": [{"io-status": "ok", "device": "disk", "locked": false, "removable": false, "inserted": {"iops_rd": 0, "image": {"virtual-size": 134217728, "filename": "TEST_DIR/t.qcow2", "cluster-size": 65536, "format": "qcow2", "actual-size": 139264, "format-specific": {"type": "qcow2", "data": {"compat": "1.1", "lazy-refcounts": false}}, "dirty-flag": false}, "iops_wr": 0, "ro": false, "backing_file_depth": 0, "drv": "qcow2", "iops": 0, "bps_wr": 0, "encrypted": false, "bps": 0, "bps_rd": 0, "file": "TEST_DIR/t.qcow2", "encryption_key_missing": false}, "type": "unknown"}, {"io-status": "ok", "device": "ide1-cd0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"device": "floppy0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"device": "sd0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}]}
9ae3a8
+{"return": {}}
9ae3a8
+{"return": {}}
9ae3a8
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "DEVICE_DELETED", "data": {"path": "/machine/peripheral/virtio0/virtio-backend"}}
9ae3a8
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "DEVICE_DELETED", "data": {"device": "virtio0", "path": "/machine/peripheral/virtio0"}}
9ae3a8
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "RESET"}
9ae3a8
+{"return": [{"io-status": "ok", "device": "ide1-cd0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"device": "floppy0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"device": "sd0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}]}
9ae3a8
+{"return": {}}
9ae3a8
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "SHUTDOWN"}
9ae3a8
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "DEVICE_TRAY_MOVED", "data": {"device": "ide1-cd0", "tray-open": true}}
9ae3a8
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "DEVICE_TRAY_MOVED", "data": {"device": "floppy0", "tray-open": true}}
9ae3a8
+
9ae3a8
+
9ae3a8
+=== -drive/device_add and device_del ===
9ae3a8
+
9ae3a8
+Testing: -drive file=TEST_DIR/t.qcow2,format=qcow2,if=none,id=disk
9ae3a8
+QMP_VERSION
9ae3a8
+{"return": {}}
9ae3a8
+{"return": [{"device": "disk", "locked": false, "removable": true, "inserted": {"iops_rd": 0, "image": {"virtual-size": 134217728, "filename": "TEST_DIR/t.qcow2", "cluster-size": 65536, "format": "qcow2", "actual-size": 139264, "format-specific": {"type": "qcow2", "data": {"compat": "1.1", "lazy-refcounts": false}}, "dirty-flag": false}, "iops_wr": 0, "ro": false, "backing_file_depth": 0, "drv": "qcow2", "iops": 0, "bps_wr": 0, "encrypted": false, "bps": 0, "bps_rd": 0, "file": "TEST_DIR/t.qcow2", "encryption_key_missing": false}, "tray_open": false, "type": "unknown"}, {"io-status": "ok", "device": "ide1-cd0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"device": "floppy0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"device": "sd0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}]}
9ae3a8
+{"return": {}}
9ae3a8
+{"return": {}}
9ae3a8
+{"return": {}}
9ae3a8
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "DEVICE_DELETED", "data": {"path": "/machine/peripheral/virtio0/virtio-backend"}}
9ae3a8
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "DEVICE_DELETED", "data": {"device": "virtio0", "path": "/machine/peripheral/virtio0"}}
9ae3a8
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "RESET"}
9ae3a8
+{"return": [{"io-status": "ok", "device": "ide1-cd0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"device": "floppy0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"device": "sd0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}]}
9ae3a8
+{"return": {}}
9ae3a8
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "SHUTDOWN"}
9ae3a8
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "DEVICE_TRAY_MOVED", "data": {"device": "ide1-cd0", "tray-open": true}}
9ae3a8
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "DEVICE_TRAY_MOVED", "data": {"device": "floppy0", "tray-open": true}}
9ae3a8
+
9ae3a8
+
9ae3a8
+=== drive_add/device_add and device_del ===
9ae3a8
+
9ae3a8
+Testing:
9ae3a8
+QMP_VERSION
9ae3a8
+{"return": {}}
9ae3a8
+{"return": "OK\r\n"}
9ae3a8
+{"return": [{"io-status": "ok", "device": "ide1-cd0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"device": "floppy0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"device": "sd0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"device": "disk", "locked": false, "removable": true, "inserted": {"iops_rd": 0, "image": {"virtual-size": 134217728, "filename": "TEST_DIR/t.qcow2", "cluster-size": 65536, "format": "qcow2", "actual-size": 139264, "format-specific": {"type": "qcow2", "data": {"compat": "1.1", "lazy-refcounts": false}}, "dirty-flag": false}, "iops_wr": 0, "ro": false, "backing_file_depth": 0, "drv": "qcow2", "iops": 0, "bps_wr": 0, "encrypted": false, "bps": 0, "bps_rd": 0, "file": "TEST_DIR/t.qcow2", "encryption_key_missing": false}, "tray_open": false, "type": "unknown"}]}
9ae3a8
+{"return": {}}
9ae3a8
+{"return": {}}
9ae3a8
+{"return": {}}
9ae3a8
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "DEVICE_DELETED", "data": {"path": "/machine/peripheral/virtio0/virtio-backend"}}
9ae3a8
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "DEVICE_DELETED", "data": {"device": "virtio0", "path": "/machine/peripheral/virtio0"}}
9ae3a8
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "RESET"}
9ae3a8
+{"return": [{"io-status": "ok", "device": "ide1-cd0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"device": "floppy0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"device": "sd0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}]}
9ae3a8
+{"return": {}}
9ae3a8
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "SHUTDOWN"}
9ae3a8
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "DEVICE_TRAY_MOVED", "data": {"device": "ide1-cd0", "tray-open": true}}
9ae3a8
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "DEVICE_TRAY_MOVED", "data": {"device": "floppy0", "tray-open": true}}
9ae3a8
+
9ae3a8
+
9ae3a8
+=== blockdev_add/device_add and device_del ===
9ae3a8
+
9ae3a8
+Testing:
9ae3a8
+QMP_VERSION
9ae3a8
+{"return": {}}
9ae3a8
+{"return": {}}
9ae3a8
+{"return": [{"io-status": "ok", "device": "ide1-cd0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"device": "floppy0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"device": "sd0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"device": "disk", "locked": false, "removable": true, "inserted": {"iops_rd": 0, "image": {"virtual-size": 134217728, "filename": "TEST_DIR/t.qcow2", "cluster-size": 65536, "format": "qcow2", "actual-size": 139264, "format-specific": {"type": "qcow2", "data": {"compat": "1.1", "lazy-refcounts": false}}, "dirty-flag": false}, "iops_wr": 0, "ro": false, "backing_file_depth": 0, "drv": "qcow2", "iops": 0, "bps_wr": 0, "encrypted": false, "bps": 0, "bps_rd": 0, "file": "TEST_DIR/t.qcow2", "encryption_key_missing": false}, "tray_open": false, "type": "unknown"}]}
9ae3a8
+{"return": {}}
9ae3a8
+{"return": {}}
9ae3a8
+{"return": {}}
9ae3a8
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "DEVICE_DELETED", "data": {"path": "/machine/peripheral/virtio0/virtio-backend"}}
9ae3a8
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "DEVICE_DELETED", "data": {"device": "virtio0", "path": "/machine/peripheral/virtio0"}}
9ae3a8
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "RESET"}
9ae3a8
+{"return": [{"io-status": "ok", "device": "ide1-cd0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"device": "floppy0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"device": "sd0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"io-status": "ok", "device": "disk", "locked": false, "removable": true, "inserted": {"iops_rd": 0, "image": {"virtual-size": 134217728, "filename": "TEST_DIR/t.qcow2", "cluster-size": 65536, "format": "qcow2", "actual-size": 139264, "format-specific": {"type": "qcow2", "data": {"compat": "1.1", "lazy-refcounts": false}}, "dirty-flag": false}, "iops_wr": 0, "ro": false, "backing_file_depth": 0, "drv": "qcow2", "iops": 0, "bps_wr": 0, "encrypted": false, "bps": 0, "bps_rd": 0, "file": "TEST_DIR/t.qcow2", "encryption_key_missing": false}, "tray_open": false, "type": "unknown"}]}
9ae3a8
+{"return": {}}
9ae3a8
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "SHUTDOWN"}
9ae3a8
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "DEVICE_TRAY_MOVED", "data": {"device": "ide1-cd0", "tray-open": true}}
9ae3a8
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "DEVICE_TRAY_MOVED", "data": {"device": "floppy0", "tray-open": true}}
9ae3a8
+
9ae3a8
+*** done
9ae3a8
diff --git a/tests/qemu-iotests/common.filter b/tests/qemu-iotests/common.filter
9ae3a8
index 5dfda63..8e7b1a4 100644
9ae3a8
--- a/tests/qemu-iotests/common.filter
9ae3a8
+++ b/tests/qemu-iotests/common.filter
9ae3a8
@@ -159,5 +159,13 @@ _filter_qemu()
9ae3a8
         -e 's#^QEMU [0-9]\+\.[0-9]\+\.[0-9]\+ monitor#QEMU X.Y.Z monitor#'
9ae3a8
 }
9ae3a8
 
9ae3a8
+# replace problematic QMP output like timestamps
9ae3a8
+_filter_qmp()
9ae3a8
+{
9ae3a8
+    _filter_win32 | \
9ae3a8
+    sed -e 's#\("\(micro\)\?seconds": \)[0-9]\+#\1 TIMESTAMP#g' \
9ae3a8
+        -e 's#^{"QMP":.*}$#QMP_VERSION#'
9ae3a8
+}
9ae3a8
+
9ae3a8
 # make sure this script returns success
9ae3a8
 /bin/true
9ae3a8
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
9ae3a8
index ff3c505..c841c5e 100644
9ae3a8
--- a/tests/qemu-iotests/group
9ae3a8
+++ b/tests/qemu-iotests/group
9ae3a8
@@ -63,4 +63,5 @@
9ae3a8
 059 rw auto
9ae3a8
 060 rw auto
9ae3a8
 063 rw auto
9ae3a8
+067 rw auto
9ae3a8
 068 rw auto
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8