From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Daniel P . Berrangé" <berrange@redhat.com>,
"Beraldo Leal" <bleal@redhat.com>,
"Vladimir Sementsov-Ogievskiy"
<vladimir.sementsov-ogievskiy@openvz.org>,
"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
"Wainer dos Santos Moschetta" <wainersm@redhat.com>,
"Vladimir Sementsov-Ogievskiy" <vsementsov@openvz.org>,
"Gerd Hoffmann" <kraxel@redhat.com>,
"Cleber Rosa" <crosa@redhat.com>
Subject: [PULL 6/9] avocado/vnc: add test_change_listen
Date: Tue, 26 Apr 2022 13:03:54 +0200 [thread overview]
Message-ID: <20220426110358.1570723-7-kraxel@redhat.com> (raw)
In-Reply-To: <20220426110358.1570723-1-kraxel@redhat.com>
From: Vladimir Sementsov-Ogievskiy <vladimir.sementsov-ogievskiy@openvz.org>
Add simple test-case for new display-update qmp command.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@openvz.org>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Message-Id: <20220401143936.356460-4-vsementsov@openvz.org>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
tests/avocado/vnc.py | 63 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 63 insertions(+)
diff --git a/tests/avocado/vnc.py b/tests/avocado/vnc.py
index 096432988fbb..187fd3febca4 100644
--- a/tests/avocado/vnc.py
+++ b/tests/avocado/vnc.py
@@ -8,9 +8,48 @@
# This work is licensed under the terms of the GNU GPL, version 2 or
# later. See the COPYING file in the top-level directory.
+import socket
+from typing import List
+
from avocado_qemu import QemuSystemTest
+VNC_ADDR = '127.0.0.1'
+VNC_PORT_START = 32768
+VNC_PORT_END = VNC_PORT_START + 1024
+
+
+def check_bind(port: int) -> bool:
+ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
+ try:
+ sock.bind((VNC_ADDR, port))
+ except OSError:
+ return False
+
+ return True
+
+
+def check_connect(port: int) -> bool:
+ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
+ try:
+ sock.connect((VNC_ADDR, port))
+ except ConnectionRefusedError:
+ return False
+
+ return True
+
+
+def find_free_ports(count: int) -> List[int]:
+ result = []
+ for port in range(VNC_PORT_START, VNC_PORT_END):
+ if check_bind(port):
+ result.append(port)
+ if len(result) >= count:
+ break
+ assert len(result) == count
+ return result
+
+
class Vnc(QemuSystemTest):
"""
:avocado: tags=vnc,quick
@@ -51,3 +90,27 @@ def test_change_password(self):
set_password_response = self.vm.qmp('change-vnc-password',
password='new_password')
self.assertEqual(set_password_response['return'], {})
+
+ def test_change_listen(self):
+ a, b, c = find_free_ports(3)
+ self.assertFalse(check_connect(a))
+ self.assertFalse(check_connect(b))
+ self.assertFalse(check_connect(c))
+
+ self.vm.add_args('-nodefaults', '-S', '-vnc', f'{VNC_ADDR}:{a - 5900}')
+ self.vm.launch()
+ self.assertEqual(self.vm.qmp('query-vnc')['return']['service'], str(a))
+ self.assertTrue(check_connect(a))
+ self.assertFalse(check_connect(b))
+ self.assertFalse(check_connect(c))
+
+ res = self.vm.qmp('display-update', type='vnc',
+ addresses=[{'type': 'inet', 'host': VNC_ADDR,
+ 'port': str(b)},
+ {'type': 'inet', 'host': VNC_ADDR,
+ 'port': str(c)}])
+ self.assertEqual(res['return'], {})
+ self.assertEqual(self.vm.qmp('query-vnc')['return']['service'], str(b))
+ self.assertFalse(check_connect(a))
+ self.assertTrue(check_connect(b))
+ self.assertTrue(check_connect(c))
--
2.35.1
next prev parent reply other threads:[~2022-04-26 11:12 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-26 11:03 [PULL 0/9] Kraxel 20220426 patches Gerd Hoffmann
2022-04-26 11:03 ` [PULL 1/9] hw/display/vmware_vga: do not discard screen updates Gerd Hoffmann
2022-04-26 11:03 ` [PULL 2/9] Replacing CONFIG_VNC_PNG with CONFIG_PNG Gerd Hoffmann
2022-04-26 17:35 ` Richard Henderson
2022-04-28 8:41 ` Kshitij Suri
2022-04-26 11:03 ` [PULL 3/9] Added parameter to take screenshot with screendump as PNG Gerd Hoffmann
2022-04-26 11:03 ` [PULL 4/9] ui/vnc: refactor arrays of addresses to SocketAddressList Gerd Hoffmann
2022-04-26 11:03 ` [PULL 5/9] qapi/ui: add 'display-update' command for changing listen address Gerd Hoffmann
2022-04-26 11:03 ` Gerd Hoffmann [this message]
2022-04-26 11:03 ` [PULL 7/9] i386: move bios load error message Gerd Hoffmann
2022-04-26 11:03 ` [PULL 8/9] i386: factor out x86_firmware_configure() Gerd Hoffmann
2022-04-26 11:03 ` [PULL 9/9] i386: firmware parsing and sev setup for -bios loaded firmware Gerd Hoffmann
-- strict thread matches above, loose matches on Subject: below --
2022-04-27 17:29 [PULL 0/9] Kraxel 20220427 patches Gerd Hoffmann
2022-04-27 17:29 ` [PULL 6/9] avocado/vnc: add test_change_listen Gerd Hoffmann
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=20220426110358.1570723-7-kraxel@redhat.com \
--to=kraxel@redhat.com \
--cc=berrange@redhat.com \
--cc=bleal@redhat.com \
--cc=crosa@redhat.com \
--cc=f4bug@amsat.org \
--cc=qemu-devel@nongnu.org \
--cc=vladimir.sementsov-ogievskiy@openvz.org \
--cc=vsementsov@openvz.org \
--cc=wainersm@redhat.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).