All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: "Marc-André Lureau" <marcandre.lureau@redhat.com>
Cc: qemu-devel@nongnu.org,
	"Philippe Mathieu-Daudé" <philmd@mailo.com>,
	"Markus Armbruster" <armbru@redhat.com>
Subject: Re: [PATCH v2 13/39] python, tests: switch usernet queries from HMP to QMP
Date: Mon, 10 Aug 2026 19:00:57 +0100	[thread overview]
Message-ID: <anoR2fZJHnTYGogy@redhat.com> (raw)
In-Reply-To: <20260626-qemu-no-hmp-v2-13-8af31bc54c61@redhat.com>

On Fri, Jun 26, 2026 at 01:19:14AM +0400, Marc-André Lureau wrote:
> Replace human-monitor-command "info usernet" calls with the structured
> x-query-usernet QMP command in get_usernet_hostfwd_port() and the VM
> test runner boot path.
> 
> Since x-query-usernet returns a list of UsernetInfo entries, callers
> now iterate over the result and extract the port from each entry's
> "info" field. Also switch get_info_usernet_hostfwd_port() from
> split('\r\n') to splitlines(), since QMP strings use \n rather than
> the HMP monitor's \r\n line endings.
> 
> Signed-off-by: Marc-Andre Lureau <marcandre.lureau@redhat.com>
> ---
>  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(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

> 
> 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')

I think there's an error handling behaviour difference here.

HMP has no concept of errors, just stuffing messages onto stderr.

So in !CONFIG_SLIRP scenarios this "info usernet" command
probably didn't return an error that this code would detect.
I think get_info_usernet_hostfwd_port() simply wouldn't
find a port number.

x-query-usernet by contrast will have clear error handling,
so should raise an exception in !CONFIG_SLIRP scenarios
which will break callers of this method I expect

> +    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")

Same concern here about likely breaking in !CONFIG_SLIRP
scenarios

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

With regards,
Daniel
-- 
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|



  reply	other threads:[~2026-08-10 18:01 UTC|newest]

Thread overview: 74+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-25 21:19 [PATCH v2 00/39] Make HMP optional (and later standalone) Marc-André Lureau
2026-06-25 21:19 ` [PATCH v2 01/39] vl: fix -monitor none prefix matching Marc-André Lureau
2026-08-10 17:30   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 02/39] hmp: remove 'vcpu' argument from trace-event help Marc-André Lureau
2026-08-10 17:31   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 03/39] hmp: fix snapshot_blkdev argument type Marc-André Lureau
2026-08-10 17:35   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 04/39] target/i386: decouple cpu_x86_inject_mce() from Monitor Marc-André Lureau
2026-08-10 17:40   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 05/39] target/i386: return an error for invalid CPU in hmp_mce() Marc-André Lureau
2026-08-10 17:42   ` Daniel P. Berrangé
2026-08-10 20:16   ` Philippe Mathieu-Daudé
2026-06-25 21:19 ` [PATCH v2 06/39] system: move gpa2hva() to system memory unit Marc-André Lureau
2026-08-10 17:44   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 07/39] s390x: prevent crash if given invalid CPU# Marc-André Lureau
2026-08-10 17:44   ` Daniel P. Berrangé
2026-08-10 21:01   ` Philippe Mathieu-Daudé
2026-06-25 21:19 ` [PATCH v2 08/39] system: decouple qmp_inject_nmi() from Monitor Marc-André Lureau
2026-08-10 17:48   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 09/39] hmp: correct the nmi documentation Marc-André Lureau
2026-08-10 17:51   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 10/39] monitor: move HMP-only fields from Monitor to MonitorHMP Marc-André Lureau
2026-08-10 17:54   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 11/39] tests/functional: use query-version QMP command instead of HMP Marc-André Lureau
2026-08-10 17:54   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 12/39] net/qapi: add x-query-usernet command Marc-André Lureau
2026-08-10 17:56   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 13/39] python, tests: switch usernet queries from HMP to QMP Marc-André Lureau
2026-08-10 18:00   ` Daniel P. Berrangé [this message]
2026-06-25 21:19 ` [PATCH v2 14/39] tests/qtest/pnv: drop unnecessary -serial mon:stdio Marc-André Lureau
2026-08-10 18:01   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 15/39] tests/qtest/qmp-test: don't depend on human-monitor-command Marc-André Lureau
2026-08-10 18:03   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 16/39] tests/qtest/numa-test: replace HMP "info numa" with QMP query-cpus-fast Marc-André Lureau
2026-08-10 18:04   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 17/39] tests/qtest/cdrom-test: replace HMP "info block" with QMP query-block Marc-André Lureau
2026-08-10 18:05   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 18/39] tests/qtest/device-introspect-test: fix test without HMP Marc-André Lureau
2026-06-25 21:19 ` [PATCH v2 19/39] tests/qemu-iotests/205: fix race in assertExportNotFound Marc-André Lureau
2026-08-10 18:15   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 20/39] net: add x-query-network QMP command Marc-André Lureau
2026-06-25 21:19 ` [PATCH v2 21/39] tests/qtest/netdev-socket: replace HMP with x-query-network QMP Marc-André Lureau
2026-06-25 21:19 ` [PATCH v2 22/39] qemu-io: propagate errors through Error API instead of printf Marc-André Lureau
2026-08-10 18:19   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 23/39] RFC: qtest: add qemu-io command to the qtest protocol Marc-André Lureau
2026-08-10 18:22   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 24/39] RFC: qtest/ide-test: convert to use qtest qemu-io command Marc-André Lureau
2026-08-10 18:22   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 25/39] block: add x-qemu-io QMP command Marc-André Lureau
2026-08-10 18:26   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 26/39] tests/qemu-iotests: add qmp_qemu_io() Marc-André Lureau
2026-08-10 18:24   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 27/39] tests/qemu-iotests: convert pause/resume_drive() to QMP Marc-André Lureau
2026-08-10 18:26   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 28/39] build-sys: add 'hmp' option Marc-André Lureau
2026-08-10 18:27   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 29/39] monitor: reject readline monitor when HMP is disabled Marc-André Lureau
2026-08-10 18:28   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 30/39] tests: skip HMP-dependent tests " Marc-André Lureau
2026-08-10 18:29   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 31/39] util: guard monitor_vprintf callers with CONFIG_HMP Marc-André Lureau
2026-08-10 18:34   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 32/39] qapi: make HMP-specific schema entries conditional on CONFIG_HMP Marc-André Lureau
2026-08-10 18:35   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 33/39] system: guard HMP initialization paths with CONFIG_HMP Marc-André Lureau
2026-06-25 21:19 ` [PATCH v2 34/39] Guard HMP command implementations " Marc-André Lureau
2026-08-10 18:36   ` Daniel P. Berrangé
2026-06-25 21:19 ` [PATCH v2 35/39] target: guard MonitorDef tables " Marc-André Lureau
2026-08-10 21:44   ` Philippe Mathieu-Daudé
2026-06-25 21:19 ` [PATCH v2 36/39] hw: guard BusClass::print_dev " Marc-André Lureau
2026-06-25 21:19 ` [PATCH v2 37/39] build-sys: make HMP source files conditional on have_hmp Marc-André Lureau
2026-06-25 21:19 ` [PATCH v2 38/39] monitor: guard HMP internal helpers with CONFIG_HMP Marc-André Lureau
2026-06-25 21:19 ` [PATCH v2 39/39] monitor: guard HMP monitor API " Marc-André Lureau
2026-08-10 21:49 ` [PATCH v2 00/39] Make HMP optional (and later standalone) Philippe Mathieu-Daudé

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=anoR2fZJHnTYGogy@redhat.com \
    --to=berrange@redhat.com \
    --cc=armbru@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=philmd@mailo.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.