From: Thomas Huth Date: Fri, 13 Dec 2024 16:02:59 +0000 (+0100) Subject: tests/functional: Add a helper function for retrieving the hostfwd port X-Git-Tag: v10.0.0-rc0~114^2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9fa4fc23e34114971f7ee81acb9b5f4ab0017c7a;p=thirdparty%2Fqemu.git tests/functional: Add a helper function for retrieving the hostfwd port It's just a wrapper around get_info_usernet_hostfwd_port from the qemu module that is also calling the right monitor command for retrieving the information from QEMU. Message-ID: <20241217121550.141072-2-thuth@redhat.com> Acked-by: Michael S. Tsirkin Signed-off-by: Thomas Huth --- diff --git a/tests/functional/qemu_test/utils.py b/tests/functional/qemu_test/utils.py index 43853b4366f..e7c8de81654 100644 --- a/tests/functional/qemu_test/utils.py +++ b/tests/functional/qemu_test/utils.py @@ -10,6 +10,13 @@ import os +from qemu.utils import get_info_usernet_hostfwd_port + + +def get_usernet_hostfwd_port(vm): + res = vm.cmd('human-monitor-command', command_line='info usernet') + return get_info_usernet_hostfwd_port(res) + """ Round up to next power of 2 """ diff --git a/tests/functional/test_info_usernet.py b/tests/functional/test_info_usernet.py index cd37524d94e..e8cbc37eed6 100755 --- a/tests/functional/test_info_usernet.py +++ b/tests/functional/test_info_usernet.py @@ -11,8 +11,7 @@ # later. See the COPYING file in the top-level directory. from qemu_test import QemuSystemTest - -from qemu.utils import get_info_usernet_hostfwd_port +from qemu_test.utils import get_usernet_hostfwd_port class InfoUsernet(QemuSystemTest): @@ -22,9 +21,8 @@ class InfoUsernet(QemuSystemTest): self.set_machine('none') self.vm.add_args('-netdev', 'user,id=vnet,hostfwd=:127.0.0.1:0-:22') self.vm.launch() - res = self.vm.cmd('human-monitor-command', - command_line='info usernet') - port = get_info_usernet_hostfwd_port(res) + + port = get_usernet_hostfwd_port(self.vm) self.assertIsNotNone(port, ('"info usernet" output content does not seem to ' 'contain the redirected port'))