1#!/usr/bin/env python3 2# group: rw quick migration 3# 4# Regression test for issue 945: 5# https://gitlab.com/qemu-project/qemu/-/issues/945 6# Test adding an export on top of an iothread-ed block device while in 7# -incoming defer. 8# 9# Copyright (C) 2022 Red Hat, Inc. 10# 11# This program is free software; you can redistribute it and/or modify 12# it under the terms of the GNU General Public License as published by 13# the Free Software Foundation; either version 2 of the License, or 14# (at your option) any later version. 15# 16# This program is distributed in the hope that it will be useful, 17# but WITHOUT ANY WARRANTY; without even the implied warranty of 18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19# GNU General Public License for more details. 20# 21# You should have received a copy of the GNU General Public License 22# along with this program. If not, see <http://www.gnu.org/licenses/>. 23# 24 25import os 26import iotests 27from iotests import qemu_img_create 28 29 30image_size = 1 * 1024 * 1024 31test_img = os.path.join(iotests.test_dir, 'test.img') 32node_name = 'node0' 33iothread_id = 'iothr0' 34 35nbd_sock = os.path.join(iotests.sock_dir, 'nbd.sock') 36 37 38class TestExportIncomingIothread(iotests.QMPTestCase): 39 def setUp(self) -> None: 40 qemu_img_create('-f', iotests.imgfmt, test_img, str(image_size)) 41 42 self.vm = iotests.VM() 43 self.vm.add_object(f'iothread,id={iothread_id}') 44 self.vm.add_blockdev(( 45 f'driver={iotests.imgfmt}', 46 f'node-name={node_name}', 47 'file.driver=file', 48 f'file.filename={test_img}' 49 )) 50 self.vm.add_incoming('defer') 51 self.vm.launch() 52 53 def tearDown(self): 54 self.vm.shutdown() 55 os.remove(test_img) 56 57 def test_export_add(self): 58 self.vm.cmd('nbd-server-start', { 59 'addr': { 60 'type': 'unix', 61 'data': { 62 'path': nbd_sock 63 } 64 } 65 }) 66 67 # Regression test for issue 945: This should not fail an assertion 68 self.vm.cmd('block-export-add', { 69 'type': 'nbd', 70 'id': 'exp0', 71 'node-name': node_name, 72 'iothread': iothread_id 73 }) 74 75 76if __name__ == '__main__': 77 iotests.main(supported_fmts=['generic'], 78 unsupported_fmts=['luks'], # Would need a secret 79 supported_protocols=['file']) 80