iotests: rewrite iotest 240 in python

The recent changes that brought RCU delayed device deletion,
broke few tests and this test breakage went unnoticed.

Fix this test by rewriting it in python
(which allows to wait for DEVICE_DELETED events before continuing).

Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
Tested-by: Christian Borntraeger <borntraeger@de.ibm.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20201104185025.434703-3-mlevitsk@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
This commit is contained in:
Maxim Levitsky 2020-11-04 20:50:25 +02:00 committed by Max Reitz
parent 2daba44205
commit c6ac463631
2 changed files with 114 additions and 149 deletions

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env python3
#
# Test hot plugging and unplugging with iothreads # Test hot plugging and unplugging with iothreads
# #
# Copyright (C) 2019 Igalia, S.L. # Copyright (C) 2019 Igalia, S.L.
@ -17,133 +17,90 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# creator import iotests
owner=berto@igalia.com import os
seq=`basename $0` nbd_sock = iotests.file_path('nbd.sock', base_dir=iotests.sock_dir)
echo "QA output created by $seq"
status=1 # failure is the default! class TestCase(iotests.QMPTestCase):
test_driver = "null-co"
_cleanup() def required_drivers(self):
{ return [self.test_driver]
rm -f "$SOCK_DIR/nbd"
}
trap "_cleanup; exit \$status" 0 1 2 3 15
# get standard environment, filters and checks @iotests.skip_if_unsupported(required_drivers)
. ./common.rc def setUp(self):
. ./common.filter self.vm = iotests.VM()
self.vm.launch()
_supported_fmt generic def tearDown(self):
_supported_proto generic self.vm.shutdown()
do_run_qemu() def test1(self):
{ iotests.log('==Unplug a SCSI disk and then plug it again==')
echo Testing: "$@" self.vm.qmp_log('blockdev-add', driver='null-co', read_zeroes=True, node_name='hd0')
$QEMU -nographic -qmp stdio -serial none "$@" self.vm.qmp_log('object-add', qom_type='iothread', id="iothread0")
echo self.vm.qmp_log('device_add', id='scsi0', driver=iotests.get_virtio_scsi_device(), iothread='iothread0', filters=[iotests.filter_qmp_virtio_scsi])
} self.vm.qmp_log('device_add', id='scsi-hd0', driver='scsi-hd', drive='hd0')
self.vm.qmp_log('device_del', id='scsi-hd0')
self.vm.event_wait('DEVICE_DELETED')
self.vm.qmp_log('device_add', id='scsi-hd0', driver='scsi-hd', drive='hd0')
self.vm.qmp_log('device_del', id='scsi-hd0')
self.vm.event_wait('DEVICE_DELETED')
self.vm.qmp_log('blockdev-del', node_name='hd0')
# Remove QMP events from (pretty-printed) output. Doesn't handle def test2(self):
# nested dicts correctly, but we don't get any of those in this test. iotests.log('==Attach two SCSI disks using the same block device and the same iothread==')
_filter_qmp_events() self.vm.qmp_log('blockdev-add', driver='null-co', read_zeroes=True, node_name='hd0', read_only=True)
{ self.vm.qmp_log('object-add', qom_type='iothread', id="iothread0")
tr '\n' '\t' | sed -e \ self.vm.qmp_log('device_add', id='scsi0', driver=iotests.get_virtio_scsi_device(), iothread='iothread0', filters=[iotests.filter_qmp_virtio_scsi])
's/{\s*"timestamp":\s*{[^}]*},\s*"event":[^,}]*\(,\s*"data":\s*{[^}]*}\)\?\s*}\s*//g' \
| tr '\t' '\n'
}
run_qemu() self.vm.qmp_log('device_add', id='scsi-hd0', driver='scsi-hd', drive='hd0')
{ self.vm.qmp_log('device_add', id='scsi-hd1', driver='scsi-hd', drive='hd0')
do_run_qemu "$@" 2>&1 | _filter_qmp | _filter_qmp_events self.vm.qmp_log('device_del', id='scsi-hd0')
} self.vm.event_wait('DEVICE_DELETED')
self.vm.qmp_log('device_del', id='scsi-hd1')
self.vm.event_wait('DEVICE_DELETED')
self.vm.qmp_log('blockdev-del', node_name='hd0')
case "$QEMU_DEFAULT_MACHINE" in def test3(self):
s390-ccw-virtio) iotests.log('==Attach two SCSI disks using the same block device but different iothreads==')
virtio_scsi=virtio-scsi-ccw
;;
*)
virtio_scsi=virtio-scsi-pci
;;
esac
echo self.vm.qmp_log('blockdev-add', driver='null-co', read_zeroes=True, node_name='hd0', read_only=True)
echo === Unplug a SCSI disk and then plug it again ===
echo
run_qemu <<EOF self.vm.qmp_log('object-add', qom_type='iothread', id="iothread0")
{ "execute": "qmp_capabilities" } self.vm.qmp_log('object-add', qom_type='iothread', id="iothread1")
{ "execute": "blockdev-add", "arguments": {"driver": "null-co", "read-zeroes": true, "node-name": "hd0"}}
{ "execute": "object-add", "arguments": {"qom-type": "iothread", "id": "iothread0"}}
{ "execute": "device_add", "arguments": {"id": "scsi0", "driver": "${virtio_scsi}", "iothread": "iothread0"}}
{ "execute": "device_add", "arguments": {"id": "scsi-hd0", "driver": "scsi-hd", "drive": "hd0"}}
{ "execute": "device_del", "arguments": {"id": "scsi-hd0"}}
{ "execute": "device_add", "arguments": {"id": "scsi-hd0", "driver": "scsi-hd", "drive": "hd0"}}
{ "execute": "device_del", "arguments": {"id": "scsi-hd0"}}
{ "execute": "device_del", "arguments": {"id": "scsi0"}}
{ "execute": "blockdev-del", "arguments": {"node-name": "hd0"}}
{ "execute": "quit"}
EOF
echo self.vm.qmp_log('device_add', id='scsi0', driver=iotests.get_virtio_scsi_device(), iothread='iothread0', filters=[iotests.filter_qmp_virtio_scsi])
echo === Attach two SCSI disks using the same block device and the same iothread === self.vm.qmp_log('device_add', id='scsi1', driver=iotests.get_virtio_scsi_device(), iothread='iothread1', filters=[iotests.filter_qmp_virtio_scsi])
echo
run_qemu <<EOF self.vm.qmp_log('device_add', id='scsi-hd0', driver='scsi-hd', drive='hd0', bus="scsi0.0")
{ "execute": "qmp_capabilities" } self.vm.qmp_log('device_add', id='scsi-hd1', driver='scsi-hd', drive='hd0', bus="scsi1.0")
{ "execute": "blockdev-add", "arguments": {"driver": "null-co", "read-zeroes": true, "node-name": "hd0", "read-only": true}}
{ "execute": "object-add", "arguments": {"qom-type": "iothread", "id": "iothread0"}}
{ "execute": "device_add", "arguments": {"id": "scsi0", "driver": "${virtio_scsi}", "iothread": "iothread0"}}
{ "execute": "device_add", "arguments": {"id": "scsi-hd0", "driver": "scsi-hd", "drive": "hd0"}}
{ "execute": "device_add", "arguments": {"id": "scsi-hd1", "driver": "scsi-hd", "drive": "hd0"}}
{ "execute": "device_del", "arguments": {"id": "scsi-hd0"}}
{ "execute": "device_del", "arguments": {"id": "scsi-hd1"}}
{ "execute": "device_del", "arguments": {"id": "scsi0"}}
{ "execute": "blockdev-del", "arguments": {"node-name": "hd0"}}
{ "execute": "quit"}
EOF
echo self.vm.qmp_log('device_del', id='scsi-hd0')
echo === Attach two SCSI disks using the same block device but different iothreads === self.vm.event_wait('DEVICE_DELETED')
echo self.vm.qmp_log('device_add', id='scsi-hd1', driver='scsi-hd', drive='hd0', bus="scsi1.0")
run_qemu <<EOF self.vm.qmp_log('device_del', id='scsi-hd1')
{ "execute": "qmp_capabilities" } self.vm.event_wait('DEVICE_DELETED')
{ "execute": "blockdev-add", "arguments": {"driver": "null-co", "read-zeroes": true, "node-name": "hd0", "read-only": true}} self.vm.qmp_log('blockdev-del', node_name='hd0')
{ "execute": "object-add", "arguments": {"qom-type": "iothread", "id": "iothread0"}}
{ "execute": "object-add", "arguments": {"qom-type": "iothread", "id": "iothread1"}}
{ "execute": "device_add", "arguments": {"id": "scsi0", "driver": "${virtio_scsi}", "iothread": "iothread0"}}
{ "execute": "device_add", "arguments": {"id": "scsi1", "driver": "${virtio_scsi}", "iothread": "iothread1"}}
{ "execute": "device_add", "arguments": {"id": "scsi-hd0", "driver": "scsi-hd", "drive": "hd0", "bus": "scsi0.0"}}
{ "execute": "device_add", "arguments": {"id": "scsi-hd1", "driver": "scsi-hd", "drive": "hd0", "bus": "scsi1.0"}}
{ "execute": "device_del", "arguments": {"id": "scsi-hd0"}}
{ "execute": "device_add", "arguments": {"id": "scsi-hd1", "driver": "scsi-hd", "drive": "hd0", "bus": "scsi1.0"}}
{ "execute": "device_del", "arguments": {"id": "scsi-hd1"}}
{ "execute": "device_del", "arguments": {"id": "scsi0"}}
{ "execute": "device_del", "arguments": {"id": "scsi1"}}
{ "execute": "blockdev-del", "arguments": {"node-name": "hd0"}}
{ "execute": "quit"}
EOF
echo def test4(self):
echo === Attach a SCSI disks using the same block device as a NBD server === iotests.log('==Attach a SCSI disks using the same block device as a NBD server==')
echo
run_qemu <<EOF self.vm.qmp_log('blockdev-add', driver='null-co', read_zeroes=True, node_name='hd0', read_only=True)
{ "execute": "qmp_capabilities" }
{ "execute": "blockdev-add", "arguments": {"driver": "null-co", "read-zeroes": true, "node-name": "hd0", "read-only": true}}
{ "execute": "nbd-server-start", "arguments": {"addr":{"type":"unix","data":{"path":"$SOCK_DIR/nbd"}}}}
{ "execute": "nbd-server-add", "arguments": {"device":"hd0"}}
{ "execute": "object-add", "arguments": {"qom-type": "iothread", "id": "iothread0"}}
{ "execute": "device_add", "arguments": {"id": "scsi0", "driver": "${virtio_scsi}", "iothread": "iothread0"}}
{ "execute": "device_add", "arguments": {"id": "scsi-hd0", "driver": "scsi-hd", "drive": "hd0", "bus": "scsi0.0"}}
{ "execute": "quit"}
EOF
# success, all done self.vm.qmp_log('nbd-server-start',
echo "*** done" filters=[iotests.filter_qmp_testfiles],
rm -f $seq.full addr={'type':'unix', 'data':{'path':nbd_sock}})
status=0
self.vm.qmp_log('nbd-server-add', device='hd0')
self.vm.qmp_log('object-add', qom_type='iothread', id="iothread0")
self.vm.qmp_log('device_add', id='scsi0', driver=iotests.get_virtio_scsi_device(), iothread='iothread0', filters=[iotests.filter_qmp_virtio_scsi])
self.vm.qmp_log('device_add', id='scsi-hd0', driver='scsi-hd', drive='hd0')
if __name__ == '__main__':
iotests.activate_logging()
iotests.main()

View File

@ -1,67 +1,75 @@
QA output created by 240 ==Unplug a SCSI disk and then plug it again==
{"execute": "blockdev-add", "arguments": {"driver": "null-co", "node-name": "hd0", "read-zeroes": true}}
=== Unplug a SCSI disk and then plug it again ===
Testing:
QMP_VERSION
{"return": {}} {"return": {}}
{"execute": "object-add", "arguments": {"id": "iothread0", "qom-type": "iothread"}}
{"return": {}} {"return": {}}
{"execute": "device_add", "arguments": {"driver": "virtio-scsi", "id": "scsi0", "iothread": "iothread0"}}
{"return": {}} {"return": {}}
{"execute": "device_add", "arguments": {"drive": "hd0", "driver": "scsi-hd", "id": "scsi-hd0"}}
{"return": {}} {"return": {}}
{"execute": "device_del", "arguments": {"id": "scsi-hd0"}}
{"return": {}} {"return": {}}
{"execute": "device_add", "arguments": {"drive": "hd0", "driver": "scsi-hd", "id": "scsi-hd0"}}
{"return": {}} {"return": {}}
{"execute": "device_del", "arguments": {"id": "scsi-hd0"}}
{"return": {}} {"return": {}}
{"execute": "blockdev-del", "arguments": {"node-name": "hd0"}}
{"return": {}} {"return": {}}
==Attach two SCSI disks using the same block device and the same iothread==
{"execute": "blockdev-add", "arguments": {"driver": "null-co", "node-name": "hd0", "read-only": true, "read-zeroes": true}}
{"return": {}} {"return": {}}
{"execute": "object-add", "arguments": {"id": "iothread0", "qom-type": "iothread"}}
{"return": {}} {"return": {}}
{"execute": "device_add", "arguments": {"driver": "virtio-scsi", "id": "scsi0", "iothread": "iothread0"}}
{"return": {}} {"return": {}}
{"execute": "device_add", "arguments": {"drive": "hd0", "driver": "scsi-hd", "id": "scsi-hd0"}}
=== Attach two SCSI disks using the same block device and the same iothread ===
Testing:
QMP_VERSION
{"return": {}} {"return": {}}
{"execute": "device_add", "arguments": {"drive": "hd0", "driver": "scsi-hd", "id": "scsi-hd1"}}
{"return": {}} {"return": {}}
{"execute": "device_del", "arguments": {"id": "scsi-hd0"}}
{"return": {}} {"return": {}}
{"execute": "device_del", "arguments": {"id": "scsi-hd1"}}
{"return": {}} {"return": {}}
{"execute": "blockdev-del", "arguments": {"node-name": "hd0"}}
{"return": {}} {"return": {}}
==Attach two SCSI disks using the same block device but different iothreads==
{"execute": "blockdev-add", "arguments": {"driver": "null-co", "node-name": "hd0", "read-only": true, "read-zeroes": true}}
{"return": {}} {"return": {}}
{"execute": "object-add", "arguments": {"id": "iothread0", "qom-type": "iothread"}}
{"return": {}} {"return": {}}
{"execute": "object-add", "arguments": {"id": "iothread1", "qom-type": "iothread"}}
{"return": {}} {"return": {}}
{"execute": "device_add", "arguments": {"driver": "virtio-scsi", "id": "scsi0", "iothread": "iothread0"}}
{"return": {}} {"return": {}}
{"execute": "device_add", "arguments": {"driver": "virtio-scsi", "id": "scsi1", "iothread": "iothread1"}}
{"return": {}} {"return": {}}
{"execute": "device_add", "arguments": {"bus": "scsi0.0", "drive": "hd0", "driver": "scsi-hd", "id": "scsi-hd0"}}
{"return": {}} {"return": {}}
{"execute": "device_add", "arguments": {"bus": "scsi1.0", "drive": "hd0", "driver": "scsi-hd", "id": "scsi-hd1"}}
=== Attach two SCSI disks using the same block device but different iothreads ===
Testing:
QMP_VERSION
{"return": {}}
{"return": {}}
{"return": {}}
{"return": {}}
{"return": {}}
{"return": {}}
{"return": {}}
{"error": {"class": "GenericError", "desc": "Cannot change iothread of active block backend"}} {"error": {"class": "GenericError", "desc": "Cannot change iothread of active block backend"}}
{"execute": "device_del", "arguments": {"id": "scsi-hd0"}}
{"return": {}} {"return": {}}
{"execute": "device_add", "arguments": {"bus": "scsi1.0", "drive": "hd0", "driver": "scsi-hd", "id": "scsi-hd1"}}
{"return": {}} {"return": {}}
{"execute": "device_del", "arguments": {"id": "scsi-hd1"}}
{"return": {}} {"return": {}}
{"execute": "blockdev-del", "arguments": {"node-name": "hd0"}}
{"return": {}} {"return": {}}
==Attach a SCSI disks using the same block device as a NBD server==
{"execute": "blockdev-add", "arguments": {"driver": "null-co", "node-name": "hd0", "read-only": true, "read-zeroes": true}}
{"return": {}} {"return": {}}
{"execute": "nbd-server-start", "arguments": {"addr": {"data": {"path": "SOCK_DIR/PID-nbd.sock"}, "type": "unix"}}}
{"return": {}} {"return": {}}
{"execute": "nbd-server-add", "arguments": {"device": "hd0"}}
{"return": {}} {"return": {}}
{"execute": "object-add", "arguments": {"id": "iothread0", "qom-type": "iothread"}}
{"return": {}}
{"execute": "device_add", "arguments": {"driver": "virtio-scsi", "id": "scsi0", "iothread": "iothread0"}}
{"return": {}}
{"execute": "device_add", "arguments": {"drive": "hd0", "driver": "scsi-hd", "id": "scsi-hd0"}}
{"return": {}}
....
----------------------------------------------------------------------
Ran 4 tests
=== Attach a SCSI disks using the same block device as a NBD server === OK
Testing:
QMP_VERSION
{"return": {}}
{"return": {}}
{"return": {}}
{"return": {}}
{"return": {}}
{"return": {}}
{"return": {}}
{"return": {}}
*** done