mirror of
https://github.com/qemu/qemu.git
synced 2024-11-23 19:03:38 +08:00
iotests: add copy-before-write: on-cbw-error tests
Add tests for new option of copy-before-write filter: on-cbw-error. Note that we use QEMUMachine instead of VM class, because in further commit we'll want to use throttling which doesn't work with -accel qtest used by VM. We also touch pylintrc to not break iotest 297. Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@openvz.org> Reviewed-by: Hanna Reitz <hreitz@redhat.com> [vsementsov: add arguments to QEMUMachine constructor] Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
This commit is contained in:
parent
f1bb39a8a5
commit
dd3e97dfbe
@ -51,3 +51,8 @@ notes=FIXME,
|
|||||||
|
|
||||||
# Maximum number of characters on a single line.
|
# Maximum number of characters on a single line.
|
||||||
max-line-length=79
|
max-line-length=79
|
||||||
|
|
||||||
|
|
||||||
|
[SIMILARITIES]
|
||||||
|
|
||||||
|
min-similarity-lines=6
|
||||||
|
135
tests/qemu-iotests/tests/copy-before-write
Executable file
135
tests/qemu-iotests/tests/copy-before-write
Executable file
@ -0,0 +1,135 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# group: auto backup
|
||||||
|
#
|
||||||
|
# Copyright (c) 2022 Virtuozzo International GmbH
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
|
||||||
|
from qemu.machine import QEMUMachine
|
||||||
|
|
||||||
|
import iotests
|
||||||
|
from iotests import qemu_img_create, qemu_io
|
||||||
|
|
||||||
|
|
||||||
|
temp_img = os.path.join(iotests.test_dir, 'temp')
|
||||||
|
source_img = os.path.join(iotests.test_dir, 'source')
|
||||||
|
size = '1M'
|
||||||
|
|
||||||
|
|
||||||
|
class TestCbwError(iotests.QMPTestCase):
|
||||||
|
def tearDown(self):
|
||||||
|
self.vm.shutdown()
|
||||||
|
os.remove(temp_img)
|
||||||
|
os.remove(source_img)
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
qemu_img_create('-f', iotests.imgfmt, source_img, size)
|
||||||
|
qemu_img_create('-f', iotests.imgfmt, temp_img, size)
|
||||||
|
qemu_io('-c', 'write 0 1M', source_img)
|
||||||
|
|
||||||
|
opts = ['-nodefaults', '-display', 'none', '-machine', 'none']
|
||||||
|
self.vm = QEMUMachine(iotests.qemu_prog, opts,
|
||||||
|
base_temp_dir=iotests.test_dir,
|
||||||
|
sock_dir=iotests.sock_dir)
|
||||||
|
self.vm.launch()
|
||||||
|
|
||||||
|
def do_cbw_error(self, on_cbw_error):
|
||||||
|
result = self.vm.qmp('blockdev-add', {
|
||||||
|
'node-name': 'cbw',
|
||||||
|
'driver': 'copy-before-write',
|
||||||
|
'on-cbw-error': on_cbw_error,
|
||||||
|
'file': {
|
||||||
|
'driver': iotests.imgfmt,
|
||||||
|
'file': {
|
||||||
|
'driver': 'file',
|
||||||
|
'filename': source_img,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'target': {
|
||||||
|
'driver': iotests.imgfmt,
|
||||||
|
'file': {
|
||||||
|
'driver': 'blkdebug',
|
||||||
|
'image': {
|
||||||
|
'driver': 'file',
|
||||||
|
'filename': temp_img
|
||||||
|
},
|
||||||
|
'inject-error': [
|
||||||
|
{
|
||||||
|
'event': 'write_aio',
|
||||||
|
'errno': 5,
|
||||||
|
'immediately': False,
|
||||||
|
'once': True
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
self.assert_qmp(result, 'return', {})
|
||||||
|
|
||||||
|
result = self.vm.qmp('blockdev-add', {
|
||||||
|
'node-name': 'access',
|
||||||
|
'driver': 'snapshot-access',
|
||||||
|
'file': 'cbw'
|
||||||
|
})
|
||||||
|
self.assert_qmp(result, 'return', {})
|
||||||
|
|
||||||
|
result = self.vm.qmp('human-monitor-command',
|
||||||
|
command_line='qemu-io cbw "write 0 1M"')
|
||||||
|
self.assert_qmp(result, 'return', '')
|
||||||
|
|
||||||
|
result = self.vm.qmp('human-monitor-command',
|
||||||
|
command_line='qemu-io access "read 0 1M"')
|
||||||
|
self.assert_qmp(result, 'return', '')
|
||||||
|
|
||||||
|
self.vm.shutdown()
|
||||||
|
log = self.vm.get_log()
|
||||||
|
log = re.sub(r'^\[I \d+\.\d+\] OPENED\n', '', log)
|
||||||
|
log = re.sub(r'\[I \+\d+\.\d+\] CLOSED\n?$', '', log)
|
||||||
|
log = iotests.filter_qemu_io(log)
|
||||||
|
return log
|
||||||
|
|
||||||
|
def test_break_snapshot_on_cbw_error(self):
|
||||||
|
"""break-snapshot behavior:
|
||||||
|
Guest write succeed, but further snapshot-read fails, as snapshot is
|
||||||
|
broken.
|
||||||
|
"""
|
||||||
|
log = self.do_cbw_error('break-snapshot')
|
||||||
|
|
||||||
|
self.assertEqual(log, """\
|
||||||
|
wrote 1048576/1048576 bytes at offset 0
|
||||||
|
1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
|
||||||
|
read failed: Permission denied
|
||||||
|
""")
|
||||||
|
|
||||||
|
def test_break_guest_write_on_cbw_error(self):
|
||||||
|
"""break-guest-write behavior:
|
||||||
|
Guest write fails, but snapshot-access continues working and further
|
||||||
|
snapshot-read succeeds.
|
||||||
|
"""
|
||||||
|
log = self.do_cbw_error('break-guest-write')
|
||||||
|
|
||||||
|
self.assertEqual(log, """\
|
||||||
|
write failed: Input/output error
|
||||||
|
read 1048576/1048576 bytes at offset 0
|
||||||
|
1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
|
||||||
|
""")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
iotests.main(supported_fmts=['qcow2'],
|
||||||
|
supported_protocols=['file'])
|
5
tests/qemu-iotests/tests/copy-before-write.out
Normal file
5
tests/qemu-iotests/tests/copy-before-write.out
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
..
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
Ran 2 tests
|
||||||
|
|
||||||
|
OK
|
Loading…
Reference in New Issue
Block a user