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:
parent
521ff8b779
commit
46bd6f8c36
@ -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))
|
||||
|
||||
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))
|
||||
def tearDown(self):
|
||||
self.vm.shutdown()
|
||||
os.remove(disk_a)
|
||||
os.remove(disk_b)
|
||||
|
||||
# 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
|
||||
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', {})
|
||||
|
||||
if jobs and jobs[0]['offset'] > 0:
|
||||
log('Backup job is started')
|
||||
# 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
|
||||
|
||||
jobs = vm.qmp('query-block-jobs')['return']
|
||||
if jobs and jobs[0]['offset'] < jobs[0]['len']:
|
||||
log('Backup job is still in progress')
|
||||
self.assertTrue(jobs and jobs[0]['offset'] > 0) # job started
|
||||
|
||||
vm.qmp_log('block-job-set-speed', device='drive0', speed=0)
|
||||
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'])
|
||||
|
||||
# Emulate server down time for 1 second
|
||||
time.sleep(1)
|
||||
result = self.vm.qmp('block-job-set-speed', device='drive0', speed=0)
|
||||
self.assert_qmp(result, 'return', {})
|
||||
|
||||
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()
|
||||
# Emulate server down time for 1 second
|
||||
time.sleep(1)
|
||||
|
||||
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', {})
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
iotests.main(supported_fmts=['qcow2'])
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user