cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

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

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