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>
This commit is contained in:
Vladimir Sementsov-Ogievskiy 2021-02-05 19:37:16 +03:00 committed by Eric Blake
parent 521ff8b779
commit 46bd6f8c36
2 changed files with 58 additions and 55 deletions

View File

@ -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
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):
vm = iotests.VM().add_drive(disk_a)
vm.launch()
vm.hmp_qemu_io('drive0', 'write 0 {}'.format(size))
vm.qmp_log('blockdev-add', filters=[iotests.filter_qmp_testfiles],
result = self.vm.qmp('blockdev-add',
**{'node_name': 'backup0',
'driver': 'raw',
'file': {'driver': 'nbd',
'server': {'type': 'unix', 'path': nbd_sock},
'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.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 = vm.qmp('query-block-jobs')['return']
jobs = self.vm.qmp('query-block-jobs')['return']
if jobs and jobs[0]['offset'] > 0:
break
time.sleep(wait_step)
t += wait_step
if jobs and jobs[0]['offset'] > 0:
log('Backup job is started')
self.assertTrue(jobs and jobs[0]['offset'] > 0) # job started
jobs = vm.qmp('query-block-jobs')['return']
if jobs and jobs[0]['offset'] < jobs[0]['len']:
log('Backup job is still in progress')
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'])
vm.qmp_log('block-job-set-speed', device='drive0', speed=0)
result = self.vm.qmp('block-job-set-speed', device='drive0', speed=0)
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()
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', {})
if __name__ == '__main__':
iotests.main(supported_fmts=['qcow2'])

View File

@ -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