aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>2021-02-05 19:37:16 +0300
committerEric Blake <eblake@redhat.com>2021-02-12 11:32:55 -0600
commit46bd6f8c364170d58f9b17a42fa9289872509f6b (patch)
tree273a541e0a7dda485c4c4890e9f7c01bb67a09e4 /tests
parent521ff8b779b11c394dbdc43f02e158dd99df308a (diff)
downloadqemu-46bd6f8c364170d58f9b17a42fa9289872509f6b.zip
qemu-46bd6f8c364170d58f9b17a42fa9289872509f6b.tar.gz
qemu-46bd6f8c364170d58f9b17a42fa9289872509f6b.tar.bz2
iotests/264: move to python unittest
We are going to add more test cases, so use the library supporting test cases. Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-Id: <20210205163720.887197-7-vsementsov@virtuozzo.com> Signed-off-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'tests')
-rwxr-xr-xtests/qemu-iotests/26493
-rw-r--r--tests/qemu-iotests/264.out20
2 files changed, 58 insertions, 55 deletions
diff --git a/tests/qemu-iotests/264 b/tests/qemu-iotests/264
index e725cef..6feeaa4 100755
--- a/tests/qemu-iotests/264
+++ b/tests/qemu-iotests/264
@@ -20,13 +20,10 @@
#
import time
+import os
import iotests
-from iotests import qemu_img_create, file_path, qemu_nbd_popen, log
-
-iotests.script_initialize(
- supported_fmts=['qcow2'],
-)
+from iotests import qemu_img_create, file_path, qemu_nbd_popen
disk_a, disk_b, nbd_sock = file_path('disk_a', 'disk_b', 'nbd-sock')
nbd_uri = 'nbd+unix:///?socket=' + nbd_sock
@@ -34,46 +31,62 @@ size = 5 * 1024 * 1024
wait_limit = 3.0
wait_step = 0.2
-qemu_img_create('-f', iotests.imgfmt, disk_a, str(size))
-qemu_img_create('-f', iotests.imgfmt, disk_b, str(size))
-with qemu_nbd_popen('-k', nbd_sock, '-f', iotests.imgfmt, disk_b):
- vm = iotests.VM().add_drive(disk_a)
- vm.launch()
- vm.hmp_qemu_io('drive0', 'write 0 {}'.format(size))
+class TestNbdReconnect(iotests.QMPTestCase):
+ def setUp(self):
+ qemu_img_create('-f', iotests.imgfmt, disk_a, str(size))
+ qemu_img_create('-f', iotests.imgfmt, disk_b, str(size))
+ self.vm = iotests.VM().add_drive(disk_a)
+ self.vm.launch()
+ self.vm.hmp_qemu_io('drive0', 'write 0 {}'.format(size))
+
+ def tearDown(self):
+ self.vm.shutdown()
+ os.remove(disk_a)
+ os.remove(disk_b)
+
+ def test(self):
+ with qemu_nbd_popen('-k', nbd_sock, '-f', iotests.imgfmt, disk_b):
+ result = self.vm.qmp('blockdev-add',
+ **{'node_name': 'backup0',
+ 'driver': 'raw',
+ 'file': {'driver': 'nbd',
+ 'server': {'type': 'unix',
+ 'path': nbd_sock},
+ 'reconnect-delay': 10}})
+ self.assert_qmp(result, 'return', {})
+ result = self.vm.qmp('blockdev-backup', device='drive0',
+ sync='full', target='backup0',
+ speed=(1 * 1024 * 1024))
+ self.assert_qmp(result, 'return', {})
+
+ # Wait for some progress
+ t = 0.0
+ while t < wait_limit:
+ jobs = self.vm.qmp('query-block-jobs')['return']
+ if jobs and jobs[0]['offset'] > 0:
+ break
+ time.sleep(wait_step)
+ t += wait_step
- vm.qmp_log('blockdev-add', filters=[iotests.filter_qmp_testfiles],
- **{'node_name': 'backup0',
- 'driver': 'raw',
- 'file': {'driver': 'nbd',
- 'server': {'type': 'unix', 'path': nbd_sock},
- 'reconnect-delay': 10}})
- vm.qmp_log('blockdev-backup', device='drive0', sync='full',
- target='backup0', speed=(1 * 1024 * 1024))
+ self.assertTrue(jobs and jobs[0]['offset'] > 0) # job started
- # Wait for some progress
- t = 0.0
- while t < wait_limit:
- jobs = vm.qmp('query-block-jobs')['return']
- if jobs and jobs[0]['offset'] > 0:
- break
- time.sleep(wait_step)
- t += wait_step
+ jobs = self.vm.qmp('query-block-jobs')['return']
+ # Check that job is still in progress
+ self.assertTrue(jobs and jobs[0]['offset'] < jobs[0]['len'])
- if jobs and jobs[0]['offset'] > 0:
- log('Backup job is started')
+ result = self.vm.qmp('block-job-set-speed', device='drive0', speed=0)
+ self.assert_qmp(result, 'return', {})
-jobs = vm.qmp('query-block-jobs')['return']
-if jobs and jobs[0]['offset'] < jobs[0]['len']:
- log('Backup job is still in progress')
+ # Emulate server down time for 1 second
+ time.sleep(1)
-vm.qmp_log('block-job-set-speed', device='drive0', speed=0)
+ with qemu_nbd_popen('-k', nbd_sock, '-f', iotests.imgfmt, disk_b):
+ e = self.vm.event_wait('BLOCK_JOB_COMPLETED')
+ self.assertEqual(e['data']['offset'], size)
+ result = self.vm.qmp('blockdev-del', node_name='backup0')
+ self.assert_qmp(result, 'return', {})
-# Emulate server down time for 1 second
-time.sleep(1)
-with qemu_nbd_popen('-k', nbd_sock, '-f', iotests.imgfmt, disk_b):
- e = vm.event_wait('BLOCK_JOB_COMPLETED')
- log('Backup completed: {}'.format(e['data']['offset']))
- vm.qmp_log('blockdev-del', node_name='backup0')
- vm.shutdown()
+if __name__ == '__main__':
+ iotests.main(supported_fmts=['qcow2'])
diff --git a/tests/qemu-iotests/264.out b/tests/qemu-iotests/264.out
index c45b1e8..ae1213e 100644
--- a/tests/qemu-iotests/264.out
+++ b/tests/qemu-iotests/264.out
@@ -1,15 +1,5 @@
-Start NBD server
-{"execute": "blockdev-add", "arguments": {"driver": "raw", "file": {"driver": "nbd", "reconnect-delay": 10, "server": {"path": "TEST_DIR/PID-nbd-sock", "type": "unix"}}, "node-name": "backup0"}}
-{"return": {}}
-{"execute": "blockdev-backup", "arguments": {"device": "drive0", "speed": 1048576, "sync": "full", "target": "backup0"}}
-{"return": {}}
-Backup job is started
-Kill NBD server
-Backup job is still in progress
-{"execute": "block-job-set-speed", "arguments": {"device": "drive0", "speed": 0}}
-{"return": {}}
-Start NBD server
-Backup completed: 5242880
-{"execute": "blockdev-del", "arguments": {"node-name": "backup0"}}
-{"return": {}}
-Kill NBD server
+.
+----------------------------------------------------------------------
+Ran 1 tests
+
+OK