1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-02 17:06:09 +00:00

fix(instances): console changes that cannot be made are refused, not reported as done

A switch to the serial console removed the graphics device but kept a
serial console of another type, a TCP one say, which the browser does
not open; the audit log said the console type was set. The switch is now
refused, with nothing changed, unless the serial console is a pty one.

A listen address change of a console that listens on a network, a socket
or nowhere did nothing without a word. It is refused with the reason.

The .vv file pointed virt-viewer at "::" for a console on all IPv6
addresses; such a console is reached through the host, as one on
0.0.0.0.
This commit is contained in:
catborise 2026-11-13 22:32:00 +03:00
parent 88e7e0fa90
commit d6df6b1df4
11 changed files with 291 additions and 210 deletions

View file

@ -1639,6 +1639,10 @@ class wvmInstance(wvmConnect):
except ValueError: # a host name
return False
def get_console_listen_type(self, config=False):
"""address, network, socket or none; None for a console without a listen element"""
return util.get_xml_path(self._XMLDesc(PERSISTENT_XML if config else 0), "/domain/devices/graphics[1]/listen/@type")
def set_console_listener_addr(self, listener_addr):
root = etree.fromstring(self._XMLDesc(PERSISTENT_XML))
# The console is the first graphics device of the definition being
@ -1648,7 +1652,9 @@ class wvmInstance(wvmConnect):
return False
listen = graphic.find("listen[@type='address']")
if listen is None:
return False
raise util.OperationError(
gettext_noop("The console listens on no address (on a network, a socket or nowhere); "
"change it in the XML editor"))
if listener_addr:
graphic.set("listen", listener_addr)
listen.set("address", listener_addr)
@ -1665,6 +1671,11 @@ class wvmInstance(wvmConnect):
serial console opens (libvirt adds the serial port for the console)."""
root = etree.fromstring(self._XMLDesc(PERSISTENT_XML))
devices = root.find("devices")
console = devices.find("console")
if console_type == "pty" and console is not None and console.get("type") != "pty":
raise util.OperationError(
gettext_noop("The serial console is a %(type)s one, the browser opens only a pty one; "
"change it in the XML editor"), type=console.get("type"))
graphics = devices.findall("graphics")
for graphic in graphics:
devices.remove(graphic)
@ -1684,7 +1695,7 @@ class wvmInstance(wvmConnect):
if passwd is not None:
fits = len(passwd) <= 8 and all(" " <= c <= "~" for c in passwd)
vnc.set("passwd", passwd if fits else util.randomPasswd(8))
elif devices.find("console") is None:
elif console is None:
etree.SubElement(devices, "console", type="pty")
return self._defineXML(etree.tostring(root).decode())

View file

@ -6,6 +6,7 @@ import unittest
from lxml import etree
from vrtManager.instance import wvmInstance
from vrtManager.util import OperationError
SPICE = """<domain><devices>
<graphics type='spice' autoport='yes' keymap='de' passwd='%s'><listen type='address' address='0.0.0.0'/></graphics>
@ -54,3 +55,13 @@ class ConsoleGraphicsTestCase(unittest.TestCase):
self.assertEqual((p.get_console_type(), p.get_console_port(), p.get_console_passwd(),
p.get_console_keymap(), p.get_console_listener_addr()),
("vnc", "5901", None, "", "127.0.0.1"))
def test_a_change_the_console_cannot_take_is_refused_and_nothing_is_saved(self):
# the browser opens only a pty serial console; a socket console has no address to change
p = vm("""<domain><devices><console type='tcp'><source mode='bind' host='127.0.0.1' service='4555'/></console>
<graphics type='vnc'><listen type='socket'/></graphics></devices></domain>""")
for change, reason in ((lambda: p.set_console_type("pty"), "The serial console is a tcp one"),
(lambda: p.set_console_listener_addr("0.0.0.0"), "The console listens on no address")):
with self.subTest(reason), self.assertRaisesRegex(OperationError, reason):
change()
self.assertEqual(p.defined, [])