Signed-off-by: Marc-André Lureau <[email protected]>
---
python/qemu/utils/__init__.py | 5 +++--
tests/functional/qemu_test/utils.py | 8 ++++++--
tests/vm/basevm.py | 13 ++++++++-----
3 files changed, 17 insertions(+), 9 deletions(-)
diff --git a/python/qemu/utils/__init__.py b/python/qemu/utils/__init__.py
index be5daa83634..e32911d4c6d 100644
--- a/python/qemu/utils/__init__.py
+++ b/python/qemu/utils/__init__.py
@@ -46,10 +46,11 @@ def get_info_usernet_hostfwd_port(info_usernet_output: str)
-> Optional[int]:
"""
Returns the port given to the hostfwd parameter via info usernet
- :param info_usernet_output: output generated by hmp command "info usernet"
+ :param info_usernet_output: output generated by "info usernet" or
+ the "info" field from x-query-usernet
:return: the port number allocated by the hostfwd option
"""
- for line in info_usernet_output.split('\r\n'):
+ for line in info_usernet_output.splitlines():
regex = r'TCP.HOST_FORWARD.*127\.0\.0\.1\s+(\d+)\s+10\.'
match = re.search(regex, line)
if match is not None:
diff --git a/tests/functional/qemu_test/utils.py
b/tests/functional/qemu_test/utils.py
index 826c267785b..0992db49ab2 100644
--- a/tests/functional/qemu_test/utils.py
+++ b/tests/functional/qemu_test/utils.py
@@ -14,8 +14,12 @@
def get_usernet_hostfwd_port(vm):
- res = vm.cmd('human-monitor-command', command_line='info usernet')
- return get_info_usernet_hostfwd_port(res)
+ res = vm.cmd('x-query-usernet')
+ for entry in res:
+ port = get_info_usernet_hostfwd_port(entry['info'])
+ if port is not None:
+ return port
+ return None
def pow2ceil(x):
"""
diff --git a/tests/vm/basevm.py b/tests/vm/basevm.py
index 9e879e966a3..198b04e8c37 100644
--- a/tests/vm/basevm.py
+++ b/tests/vm/basevm.py
@@ -312,12 +312,15 @@ def boot(self, img, extra_args=[]):
self._guest = guest
# Init console so we can start consuming the chars.
self.console_init()
- usernet_info = guest.cmd("human-monitor-command",
- command_line="info usernet")
- self.ssh_port = get_info_usernet_hostfwd_port(usernet_info)
+ res = guest.cmd("x-query-usernet")
+ for entry in res:
+ port = get_info_usernet_hostfwd_port(entry['info'])
+ if port is not None:
+ self.ssh_port = port
+ break
if not self.ssh_port:
- raise Exception("Cannot find ssh port from 'info usernet':\n%s" % \
- usernet_info)
+ raise Exception("Cannot find ssh port from"
+ " 'x-query-usernet': %s" % res)
def console_init(self, timeout = None):
if timeout == None:
--
2.54.0