xref: /openbmc/qemu/tests/qemu-iotests/240 (revision 63ad23fa)
1c6ac4636SMaxim Levitsky#!/usr/bin/env python3
29dd003a9SVladimir Sementsov-Ogievskiy# group: quick
3c6ac4636SMaxim Levitsky
4a6f230c8SAlberto Garcia# Test hot plugging and unplugging with iothreads
5a6f230c8SAlberto Garcia#
6a6f230c8SAlberto Garcia# Copyright (C) 2019 Igalia, S.L.
7a6f230c8SAlberto Garcia# Author: Alberto Garcia <berto@igalia.com>
8a6f230c8SAlberto Garcia#
9a6f230c8SAlberto Garcia# This program is free software; you can redistribute it and/or modify
10a6f230c8SAlberto Garcia# it under the terms of the GNU General Public License as published by
11a6f230c8SAlberto Garcia# the Free Software Foundation; either version 2 of the License, or
12a6f230c8SAlberto Garcia# (at your option) any later version.
13a6f230c8SAlberto Garcia#
14a6f230c8SAlberto Garcia# This program is distributed in the hope that it will be useful,
15a6f230c8SAlberto Garcia# but WITHOUT ANY WARRANTY; without even the implied warranty of
16a6f230c8SAlberto Garcia# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17a6f230c8SAlberto Garcia# GNU General Public License for more details.
18a6f230c8SAlberto Garcia#
19a6f230c8SAlberto Garcia# You should have received a copy of the GNU General Public License
20a6f230c8SAlberto Garcia# along with this program.  If not, see <http://www.gnu.org/licenses/>.
21a6f230c8SAlberto Garcia
22c6ac4636SMaxim Levitskyimport iotests
23c6ac4636SMaxim Levitskyimport os
24a6f230c8SAlberto Garcia
25c6ac4636SMaxim Levitskynbd_sock = iotests.file_path('nbd.sock', base_dir=iotests.sock_dir)
26a6f230c8SAlberto Garcia
27c6ac4636SMaxim Levitskyclass TestCase(iotests.QMPTestCase):
28c6ac4636SMaxim Levitsky    test_driver = "null-co"
29a6f230c8SAlberto Garcia
30c6ac4636SMaxim Levitsky    def required_drivers(self):
31c6ac4636SMaxim Levitsky        return [self.test_driver]
3245e92a90SKevin Wolf
33c6ac4636SMaxim Levitsky    @iotests.skip_if_unsupported(required_drivers)
34c6ac4636SMaxim Levitsky    def setUp(self):
35c6ac4636SMaxim Levitsky        self.vm = iotests.VM()
36c6ac4636SMaxim Levitsky        self.vm.launch()
37a6f230c8SAlberto Garcia
38c6ac4636SMaxim Levitsky    def tearDown(self):
39c6ac4636SMaxim Levitsky        self.vm.shutdown()
40a6f230c8SAlberto Garcia
41c6ac4636SMaxim Levitsky    def test1(self):
42c6ac4636SMaxim Levitsky        iotests.log('==Unplug a SCSI disk and then plug it again==')
43c6ac4636SMaxim Levitsky        self.vm.qmp_log('blockdev-add', driver='null-co', read_zeroes=True, node_name='hd0')
44c6ac4636SMaxim Levitsky        self.vm.qmp_log('object-add', qom_type='iothread', id="iothread0")
45*22329f0dSLaurent Vivier        self.vm.qmp_log('device_add', id='scsi0', driver='virtio-scsi', iothread='iothread0', filters=[iotests.filter_qmp_virtio_scsi])
46c6ac4636SMaxim Levitsky        self.vm.qmp_log('device_add', id='scsi-hd0', driver='scsi-hd', drive='hd0')
47c6ac4636SMaxim Levitsky        self.vm.qmp_log('device_del', id='scsi-hd0')
48c6ac4636SMaxim Levitsky        self.vm.event_wait('DEVICE_DELETED')
49c6ac4636SMaxim Levitsky        self.vm.qmp_log('device_add', id='scsi-hd0', driver='scsi-hd', drive='hd0')
50c6ac4636SMaxim Levitsky        self.vm.qmp_log('device_del', id='scsi-hd0')
51c6ac4636SMaxim Levitsky        self.vm.event_wait('DEVICE_DELETED')
52c6ac4636SMaxim Levitsky        self.vm.qmp_log('blockdev-del', node_name='hd0')
53a6f230c8SAlberto Garcia
54c6ac4636SMaxim Levitsky    def test2(self):
55c6ac4636SMaxim Levitsky        iotests.log('==Attach two SCSI disks using the same block device and the same iothread==')
56c6ac4636SMaxim Levitsky        self.vm.qmp_log('blockdev-add', driver='null-co', read_zeroes=True, node_name='hd0', read_only=True)
57c6ac4636SMaxim Levitsky        self.vm.qmp_log('object-add', qom_type='iothread', id="iothread0")
58*22329f0dSLaurent Vivier        self.vm.qmp_log('device_add', id='scsi0', driver='virtio-scsi', iothread='iothread0', filters=[iotests.filter_qmp_virtio_scsi])
59a6f230c8SAlberto Garcia
60c6ac4636SMaxim Levitsky        self.vm.qmp_log('device_add', id='scsi-hd0', driver='scsi-hd', drive='hd0')
61c6ac4636SMaxim Levitsky        self.vm.qmp_log('device_add', id='scsi-hd1', driver='scsi-hd', drive='hd0')
62c6ac4636SMaxim Levitsky        self.vm.qmp_log('device_del', id='scsi-hd0')
63c6ac4636SMaxim Levitsky        self.vm.event_wait('DEVICE_DELETED')
64c6ac4636SMaxim Levitsky        self.vm.qmp_log('device_del', id='scsi-hd1')
65c6ac4636SMaxim Levitsky        self.vm.event_wait('DEVICE_DELETED')
66c6ac4636SMaxim Levitsky        self.vm.qmp_log('blockdev-del', node_name='hd0')
67a6f230c8SAlberto Garcia
68c6ac4636SMaxim Levitsky    def test3(self):
69c6ac4636SMaxim Levitsky        iotests.log('==Attach two SCSI disks using the same block device but different iothreads==')
70a6f230c8SAlberto Garcia
71c6ac4636SMaxim Levitsky        self.vm.qmp_log('blockdev-add', driver='null-co', read_zeroes=True, node_name='hd0', read_only=True)
72a6f230c8SAlberto Garcia
73c6ac4636SMaxim Levitsky        self.vm.qmp_log('object-add', qom_type='iothread', id="iothread0")
74c6ac4636SMaxim Levitsky        self.vm.qmp_log('object-add', qom_type='iothread', id="iothread1")
75a6f230c8SAlberto Garcia
76*22329f0dSLaurent Vivier        self.vm.qmp_log('device_add', id='scsi0', driver='virtio-scsi', iothread='iothread0', filters=[iotests.filter_qmp_virtio_scsi])
77*22329f0dSLaurent Vivier        self.vm.qmp_log('device_add', id='scsi1', driver='virtio-scsi', iothread='iothread1', filters=[iotests.filter_qmp_virtio_scsi])
783ff35ba3SAlberto Garcia
79c6ac4636SMaxim Levitsky        self.vm.qmp_log('device_add', id='scsi-hd0', driver='scsi-hd', drive='hd0', bus="scsi0.0")
80c6ac4636SMaxim Levitsky        self.vm.qmp_log('device_add', id='scsi-hd1', driver='scsi-hd', drive='hd0', bus="scsi1.0")
813ff35ba3SAlberto Garcia
82c6ac4636SMaxim Levitsky        self.vm.qmp_log('device_del', id='scsi-hd0')
83c6ac4636SMaxim Levitsky        self.vm.event_wait('DEVICE_DELETED')
84c6ac4636SMaxim Levitsky        self.vm.qmp_log('device_add', id='scsi-hd1', driver='scsi-hd', drive='hd0', bus="scsi1.0")
85eb97813fSAlberto Garcia
86c6ac4636SMaxim Levitsky        self.vm.qmp_log('device_del', id='scsi-hd1')
87c6ac4636SMaxim Levitsky        self.vm.event_wait('DEVICE_DELETED')
88c6ac4636SMaxim Levitsky        self.vm.qmp_log('blockdev-del', node_name='hd0')
89eb97813fSAlberto Garcia
90c6ac4636SMaxim Levitsky    def test4(self):
91c6ac4636SMaxim Levitsky        iotests.log('==Attach a SCSI disks using the same block device as a NBD server==')
9245e92a90SKevin Wolf
93c6ac4636SMaxim Levitsky        self.vm.qmp_log('blockdev-add', driver='null-co', read_zeroes=True, node_name='hd0', read_only=True)
9445e92a90SKevin Wolf
95c6ac4636SMaxim Levitsky        self.vm.qmp_log('nbd-server-start',
96c6ac4636SMaxim Levitsky                        filters=[iotests.filter_qmp_testfiles],
97c6ac4636SMaxim Levitsky                        addr={'type':'unix', 'data':{'path':nbd_sock}})
98c6ac4636SMaxim Levitsky
99c6ac4636SMaxim Levitsky        self.vm.qmp_log('nbd-server-add', device='hd0')
100c6ac4636SMaxim Levitsky
101c6ac4636SMaxim Levitsky        self.vm.qmp_log('object-add', qom_type='iothread', id="iothread0")
102*22329f0dSLaurent Vivier        self.vm.qmp_log('device_add', id='scsi0', driver='virtio-scsi', iothread='iothread0', filters=[iotests.filter_qmp_virtio_scsi])
103c6ac4636SMaxim Levitsky        self.vm.qmp_log('device_add', id='scsi-hd0', driver='scsi-hd', drive='hd0')
104c6ac4636SMaxim Levitsky
105c6ac4636SMaxim Levitskyif __name__ == '__main__':
106c6ac4636SMaxim Levitsky    iotests.activate_logging()
107c6ac4636SMaxim Levitsky    iotests.main()
108