[PATCH 2/3] iotests/041: add test for mirror with throttled NBD export as target

Fiona Ebner posted 3 patches 3 weeks, 6 days ago
Maintainers: John Snow <jsnow@redhat.com>, Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>, Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>
There is a newer version of this series
[PATCH 2/3] iotests/041: add test for mirror with throttled NBD export as target
Posted by Fiona Ebner 3 weeks, 6 days ago
Mostly in preparation for commit "iotests/041: add test for duplicate
job-complete with throttled target".

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
 tests/qemu-iotests/041     | 112 ++++++++++++++++++++++++++++++++++++-
 tests/qemu-iotests/041.out |   4 +-
 2 files changed, 113 insertions(+), 3 deletions(-)

diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041
index 8452845f44..a7e1980f13 100755
--- a/tests/qemu-iotests/041
+++ b/tests/qemu-iotests/041
@@ -24,7 +24,7 @@ import os
 import re
 import json
 import iotests
-from iotests import qemu_img, qemu_img_map, qemu_io
+from iotests import qemu_img, qemu_img_map, qemu_io, QemuStorageDaemon
 
 backing_img = os.path.join(iotests.test_dir, 'backing.img')
 target_backing_img = os.path.join(iotests.test_dir, 'target-backing.img')
@@ -1373,6 +1373,116 @@ class TestFilters(iotests.QMPTestCase):
 
         self.complete_and_wait('mirror')
 
+# Tests for mirror where the target is a throttled NBD export.
+class TestThrottledNBDTarget(iotests.QMPTestCase):
+    image_len = 3 * 1024 * 1024
+    bps_total = 1 * 1024 * 1024
+
+    def setUp(self):
+        iotests.create_image(backing_img, self.image_len)
+        iotests.create_image(target_backing_img, self.image_len)
+        qemu_img('create', '-f', iotests.imgfmt,
+                 '-o', f'backing_file={backing_img}', '-F', 'raw', test_img)
+        qemu_img('create', '-f', iotests.imgfmt,
+                 '-o', f'backing_file={target_backing_img}', '-F', 'raw',
+                 target_img)
+        qemu_io('-c', 'write -P 23 0 3M', test_img)
+
+        self.qsd = QemuStorageDaemon('--nbd-server',
+                                     f'addr.type=unix,addr.path={nbd_sock_path}',
+                                     qmp=True)
+
+        self.qsd.cmd('object-add', {
+            'qom-type': 'throttle-group',
+            'id': 'thrgr-target',
+            'limits': {
+                'bps-total': self.bps_total,
+            }
+        })
+
+        self.qsd.cmd('blockdev-add', {
+            'node-name': 'target',
+            'driver': 'throttle',
+            'throttle-group': 'thrgr-target',
+            'file': {
+                'driver': iotests.imgfmt,
+                'file': {
+                    'driver': 'file',
+                    'filename': target_img
+                }
+            }
+        })
+
+        self.qsd.cmd('block-export-add', {
+            'id': 'exp0',
+            'type': 'nbd',
+            'node-name': 'target',
+            'writable': True
+        })
+
+        self.vm = iotests.VM().add_device('virtio-scsi,id=vio-scsi')
+        self.vm.launch()
+
+        self.vm.cmd('blockdev-add',{
+            'node-name': 'source',
+            'driver': iotests.imgfmt,
+            'file': {
+                'driver': 'file',
+                'filename': test_img
+            },
+            'backing': {
+                'node-name': 'backing',
+                'driver': 'raw',
+                'file': {
+                    'driver': 'file',
+                    'filename': backing_img
+                }
+            }
+        })
+
+        self.vm.cmd('device_add',
+                    driver='scsi-hd',
+                    id='virtio',
+                    bus='vio-scsi.0',
+                    drive='source')
+
+        self.vm.cmd('blockdev-add', {
+            'node-name': 'target',
+            'driver': 'nbd',
+            'export': 'target',
+            'server': {
+                'type': 'unix',
+                'path': nbd_sock_path
+            }
+        })
+
+    def tearDown(self):
+        os.remove(test_img)
+        os.remove(target_img)
+        os.remove(backing_img)
+        os.remove(target_backing_img)
+
+    def test_throttled(self):
+        self.vm.cmd('blockdev-mirror',
+                    job_id='mirror',
+                    device='source',
+                    target='target',
+                    sync='full')
+
+        time.sleep(1)
+        result = self.vm.qmp('query-block-jobs')
+        self.assert_qmp(result, 'return[0]/ready', False)
+        self.vm.qtest(f'clock_step {4 * 1000 * 1000 * 1000}')
+        time.sleep(1) # in real time, the rest should now comlpete fast
+        result = self.vm.qmp('query-block-jobs')
+        self.assert_qmp(result, 'return[0]/ready', True)
+
+        self.complete_and_wait('mirror')
+        self.vm.shutdown()
+        self.qsd.stop()
+        self.assertTrue(iotests.compare_images(test_img, target_img),
+                        'target image does not match source after mirroring')
+
 
 if __name__ == '__main__':
     iotests.main(supported_fmts=['qcow2', 'qed'],
diff --git a/tests/qemu-iotests/041.out b/tests/qemu-iotests/041.out
index 46651953e8..5273ce86c3 100644
--- a/tests/qemu-iotests/041.out
+++ b/tests/qemu-iotests/041.out
@@ -1,5 +1,5 @@
-...........................................................................................................
+............................................................................................................
 ----------------------------------------------------------------------
-Ran 107 tests
+Ran 108 tests
 
 OK
-- 
2.47.3
Re: [PATCH 2/3] iotests/041: add test for mirror with throttled NBD export as target
Posted by Hanna Czenczek 3 weeks, 1 day ago
On 11.03.26 15:54, Fiona Ebner wrote:
> Mostly in preparation for commit "iotests/041: add test for duplicate
> job-complete with throttled target".
>
> Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
> ---
>   tests/qemu-iotests/041     | 112 ++++++++++++++++++++++++++++++++++++-
>   tests/qemu-iotests/041.out |   4 +-
>   2 files changed, 113 insertions(+), 3 deletions(-)
>
> diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041
> index 8452845f44..a7e1980f13 100755
> --- a/tests/qemu-iotests/041
> +++ b/tests/qemu-iotests/041

[...]


> +    def tearDown(self):
> +        os.remove(test_img)
> +        os.remove(target_img)
> +        os.remove(backing_img)
> +        os.remove(target_backing_img)

It would be good if tearDown() could still contain the VM/QSD shutdown/stop.

> +
> +    def test_throttled(self):
> +        self.vm.cmd('blockdev-mirror',
> +                    job_id='mirror',
> +                    device='source',
> +                    target='target',
> +                    sync='full')
> +
> +        time.sleep(1)
> +        result = self.vm.qmp('query-block-jobs')
> +        self.assert_qmp(result, 'return[0]/ready', False)
> +        self.vm.qtest(f'clock_step {4 * 1000 * 1000 * 1000}')
> +        time.sleep(1) # in real time, the rest should now comlpete fast

I think the clock_step belongs on the export side, the QSD.  On the 
other hand, QSD has no way to enable qtest, I believe, so it won’t work 
well as an export here.  I think it works accidentally because throttle 
allows a burst, and can allow to write 3 MB in 2 seconds.

This whole test is also a bit fiddly. It needs to write 3 MB in one 
second, I believe, which seems prone to being flakey.  I’d be happy with 
a null export on the target side, if that still did the job (pun intended).

(Also *complete)

Hanna

> +        result = self.vm.qmp('query-block-jobs')
> +        self.assert_qmp(result, 'return[0]/ready', True)
> +
> +        self.complete_and_wait('mirror')
> +        self.vm.shutdown()
> +        self.qsd.stop()
> +        self.assertTrue(iotests.compare_images(test_img, target_img),
> +                        'target image does not match source after mirroring')
> +
>   
>   if __name__ == '__main__':
>       iotests.main(supported_fmts=['qcow2', 'qed'],
> diff --git a/tests/qemu-iotests/041.out b/tests/qemu-iotests/041.out
> index 46651953e8..5273ce86c3 100644
> --- a/tests/qemu-iotests/041.out
> +++ b/tests/qemu-iotests/041.out
> @@ -1,5 +1,5 @@
> -...........................................................................................................
> +............................................................................................................
>   ----------------------------------------------------------------------
> -Ran 107 tests
> +Ran 108 tests
>   
>   OK


Re: [PATCH 2/3] iotests/041: add test for mirror with throttled NBD export as target
Posted by Fiona Ebner 2 weeks, 6 days ago
Am 16.03.26 um 6:27 PM schrieb Hanna Czenczek:
> On 11.03.26 15:54, Fiona Ebner wrote:
>> Mostly in preparation for commit "iotests/041: add test for duplicate
>> job-complete with throttled target".
>>
>> Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
>> ---
>>   tests/qemu-iotests/041     | 112 ++++++++++++++++++++++++++++++++++++-
>>   tests/qemu-iotests/041.out |   4 +-
>>   2 files changed, 113 insertions(+), 3 deletions(-)
>>
>> diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041
>> index 8452845f44..a7e1980f13 100755
>> --- a/tests/qemu-iotests/041
>> +++ b/tests/qemu-iotests/041
> 
> [...]
> 
> 
>> +    def tearDown(self):
>> +        os.remove(test_img)
>> +        os.remove(target_img)
>> +        os.remove(backing_img)
>> +        os.remove(target_backing_img)
> 
> It would be good if tearDown() could still contain the VM/QSD shutdown/
> stop.

Will do!

>> +
>> +    def test_throttled(self):
>> +        self.vm.cmd('blockdev-mirror',
>> +                    job_id='mirror',
>> +                    device='source',
>> +                    target='target',
>> +                    sync='full')
>> +
>> +        time.sleep(1)
>> +        result = self.vm.qmp('query-block-jobs')
>> +        self.assert_qmp(result, 'return[0]/ready', False)
>> +        self.vm.qtest(f'clock_step {4 * 1000 * 1000 * 1000}')
>> +        time.sleep(1) # in real time, the rest should now comlpete fast
> 
> I think the clock_step belongs on the export side, the QSD.  On the
> other hand, QSD has no way to enable qtest, I believe, so it won’t work
> well as an export here.  I think it works accidentally because throttle
> allows a burst, and can allow to write 3 MB in 2 seconds.

Ah, good catch! I originally did everything with just the VM, but
draining during mirror completion disables the throttling, so the issue
with the duplicate complete wouldn't trigger for the test in patch 3/3.
That's why an external target is needed.

> This whole test is also a bit fiddly. It needs to write 3 MB in one
> second, I believe, which seems prone to being flakey.  I’d be happy with
> a null export on the target side, if that still did the job (pun intended).

The one from patch 3/3 relies on the same kind of behavior. I guess
using a second VM instance rather than QSD for the export could work?
And adapting the test to make throttling actually have an effect.

Best Regards,
Fiona

> (Also *complete)
> 
> Hanna
> 
>> +        result = self.vm.qmp('query-block-jobs')
>> +        self.assert_qmp(result, 'return[0]/ready', True)
>> +
>> +        self.complete_and_wait('mirror')
>> +        self.vm.shutdown()
>> +        self.qsd.stop()
>> +        self.assertTrue(iotests.compare_images(test_img, target_img),
>> +                        'target image does not match source after
>> mirroring')
>> +
>>     if __name__ == '__main__':
>>       iotests.main(supported_fmts=['qcow2', 'qed'],
>> diff --git a/tests/qemu-iotests/041.out b/tests/qemu-iotests/041.out
>> index 46651953e8..5273ce86c3 100644
>> --- a/tests/qemu-iotests/041.out
>> +++ b/tests/qemu-iotests/041.out
>> @@ -1,5 +1,5 @@
>> -...........................................................................................................
>> +............................................................................................................
>>   ----------------------------------------------------------------------
>> -Ran 107 tests
>> +Ran 108 tests
>>     OK
> 
> 



Re: [PATCH 2/3] iotests/041: add test for mirror with throttled NBD export as target
Posted by Hanna Czenczek 2 weeks, 6 days ago
On 18.03.26 15:51, Fiona Ebner wrote:
> Am 16.03.26 um 6:27 PM schrieb Hanna Czenczek:
>> On 11.03.26 15:54, Fiona Ebner wrote:
>>> Mostly in preparation for commit "iotests/041: add test for duplicate
>>> job-complete with throttled target".
>>>
>>> Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
>>> ---
>>>    tests/qemu-iotests/041     | 112 ++++++++++++++++++++++++++++++++++++-
>>>    tests/qemu-iotests/041.out |   4 +-
>>>    2 files changed, 113 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041
>>> index 8452845f44..a7e1980f13 100755
>>> --- a/tests/qemu-iotests/041
>>> +++ b/tests/qemu-iotests/041
>> [...]
>>
>>
>>> +    def tearDown(self):
>>> +        os.remove(test_img)
>>> +        os.remove(target_img)
>>> +        os.remove(backing_img)
>>> +        os.remove(target_backing_img)
>> It would be good if tearDown() could still contain the VM/QSD shutdown/
>> stop.
> Will do!
>
>>> +
>>> +    def test_throttled(self):
>>> +        self.vm.cmd('blockdev-mirror',
>>> +                    job_id='mirror',
>>> +                    device='source',
>>> +                    target='target',
>>> +                    sync='full')
>>> +
>>> +        time.sleep(1)
>>> +        result = self.vm.qmp('query-block-jobs')
>>> +        self.assert_qmp(result, 'return[0]/ready', False)
>>> +        self.vm.qtest(f'clock_step {4 * 1000 * 1000 * 1000}')
>>> +        time.sleep(1) # in real time, the rest should now comlpete fast
>> I think the clock_step belongs on the export side, the QSD.  On the
>> other hand, QSD has no way to enable qtest, I believe, so it won’t work
>> well as an export here.  I think it works accidentally because throttle
>> allows a burst, and can allow to write 3 MB in 2 seconds.
> Ah, good catch! I originally did everything with just the VM, but
> draining during mirror completion disables the throttling, so the issue
> with the duplicate complete wouldn't trigger for the test in patch 3/3.
> That's why an external target is needed.
>
>> This whole test is also a bit fiddly. It needs to write 3 MB in one
>> second, I believe, which seems prone to being flakey.  I’d be happy with
>> a null export on the target side, if that still did the job (pun intended).
> The one from patch 3/3 relies on the same kind of behavior. I guess
> using a second VM instance rather than QSD for the export could work?
> And adapting the test to make throttling actually have an effect.

Yes, that’s what I had in mind.

Hanna