[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 03/10] iotests: add copy-before-write: on-cbw-error tests
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
[PULL 03/10] iotests: add copy-before-write: on-cbw-error tests |
Date: |
Tue, 14 Jun 2022 13:29:03 +0300 |
From: Vladimir Sementsov-Ogievskiy <vsementsov@openvz.org>
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>
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
---
tests/qemu-iotests/pylintrc | 5 +
tests/qemu-iotests/tests/copy-before-write | 132 ++++++++++++++++++
.../qemu-iotests/tests/copy-before-write.out | 5 +
3 files changed, 142 insertions(+)
create mode 100755 tests/qemu-iotests/tests/copy-before-write
create mode 100644 tests/qemu-iotests/tests/copy-before-write.out
diff --git a/tests/qemu-iotests/pylintrc b/tests/qemu-iotests/pylintrc
index 32ab77b8bb..f4f823a991 100644
--- a/tests/qemu-iotests/pylintrc
+++ b/tests/qemu-iotests/pylintrc
@@ -51,3 +51,8 @@ notes=FIXME,
# Maximum number of characters on a single line.
max-line-length=79
+
+
+[SIMILARITIES]
+
+min-similarity-lines=6
diff --git a/tests/qemu-iotests/tests/copy-before-write
b/tests/qemu-iotests/tests/copy-before-write
new file mode 100755
index 0000000000..6c7638965e
--- /dev/null
+++ b/tests/qemu-iotests/tests/copy-before-write
@@ -0,0 +1,132 @@
+#!/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)
+
+ self.vm = QEMUMachine(iotests.qemu_prog)
+ 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'])
diff --git a/tests/qemu-iotests/tests/copy-before-write.out
b/tests/qemu-iotests/tests/copy-before-write.out
new file mode 100644
index 0000000000..fbc63e62f8
--- /dev/null
+++ b/tests/qemu-iotests/tests/copy-before-write.out
@@ -0,0 +1,5 @@
+..
+----------------------------------------------------------------------
+Ran 2 tests
+
+OK
--
2.25.1
- [PULL 00/10] Block jobs & NBD patches, Vladimir Sementsov-Ogievskiy, 2022/06/14
- [PULL 01/10] block/copy-before-write: refactor option parsing, Vladimir Sementsov-Ogievskiy, 2022/06/14
- [PULL 02/10] block/copy-before-write: add on-cbw-error open parameter, Vladimir Sementsov-Ogievskiy, 2022/06/14
- [PULL 04/10] util: add qemu-co-timeout, Vladimir Sementsov-Ogievskiy, 2022/06/14
- [PULL 05/10] block/block-copy: block_copy(): add timeout_ns parameter, Vladimir Sementsov-Ogievskiy, 2022/06/14
- [PULL 07/10] iotests: copy-before-write: add cases for cbw-timeout option, Vladimir Sementsov-Ogievskiy, 2022/06/14
- [PULL 03/10] iotests: add copy-before-write: on-cbw-error tests,
Vladimir Sementsov-Ogievskiy <=
- [PULL 08/10] nbd: trace long NBD operations, Vladimir Sementsov-Ogievskiy, 2022/06/14
- [PULL 06/10] block/copy-before-write: implement cbw-timeout option, Vladimir Sementsov-Ogievskiy, 2022/06/14
- [PULL 09/10] block: use 'unsigned' for in_flight field on driver state, Vladimir Sementsov-Ogievskiy, 2022/06/14
- [PULL 10/10] MAINTAINERS: update Vladimir's address and repositories, Vladimir Sementsov-Ogievskiy, 2022/06/14
- Re: [PULL 00/10] Block jobs & NBD patches, Richard Henderson, 2022/06/14