tests: pick a free console port instead of hardcoding 5011

A dev machine running a real gns3server (or qemu) can already listen on
5011; reserve_tcp_port then silently replaces it with the next free port
and test_console fails on the exact-echo assertion. Pick a port that is
actually free on the host first, like test_change_console_port does.
This commit is contained in:
YueGuobin 2026-08-19 23:34:14 +08:00
parent 72dc10a669
commit 5188ae625a
No known key found for this signature in database

View File

@ -51,11 +51,16 @@ def test_temporary_directory(compute_project, manager):
assert isinstance(node.temporary_directory, str)
def test_console(compute_project, manager):
def test_console(compute_project, manager, port_manager):
node = VPCSVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", compute_project, manager)
node.console = 5011
assert node.console == 5011
# pick a port that is actually free on this host: a hardcoded one may be
# taken by a running gns3server/qemu on a dev machine, and the setter would
# silently replace it with the next free port
console_port = port_manager.get_free_tcp_port(node.project)
port_manager.release_tcp_port(console_port, node.project)
node.console = console_port
assert node.console == console_port
node.console = None
assert node.console is None