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