mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-11 12:46:49 +00:00
feat(instances): choose VNC or the serial console on the VM page
Settings > Console gets a Console type field. Serial removes the VM's graphics device (adding a pty console when there is none); VNC adds the graphics device new VMs get, on localhost, and then applies the form's VNC fields, so an administrator can open it to all interfaces for a TCP compute. Serial is offered only while SERIAL_CONSOLE_ENABLED is on.
This commit is contained in:
parent
d37aa42392
commit
0f9bbd3e86
6 changed files with 53 additions and 3 deletions
|
|
@ -105,6 +105,16 @@ EDITS = {
|
|||
lambda t: first(t, "devices/graphics/listen/@address") == "127.0.0.1",
|
||||
["devices/graphics/@listen", "devices/graphics/listen/@address"], True, False,
|
||||
),
|
||||
"set_console_type pty": (
|
||||
lambda vm: vm.set_console_type("pty"),
|
||||
lambda t: not t.xpath("devices/graphics") and first(t, "devices/console/@type") == "pty",
|
||||
["devices/graphics", "devices/console"], True, False,
|
||||
),
|
||||
"set_console_type vnc": (
|
||||
lambda vm: vm.set_console_type("vnc"),
|
||||
lambda t: t.xpath("devices/graphics/@type") == ["vnc"] and first(t, "devices/graphics/@listen") == "127.0.0.1",
|
||||
["devices/graphics"], True, False,
|
||||
),
|
||||
"set_console_passwd": (
|
||||
lambda vm: vm.set_console_passwd("new12345"),
|
||||
lambda t: first(t, "devices/graphics/@passwd") == "new12345",
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ from unittest.mock import patch
|
|||
|
||||
from computes.models import Compute
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.test import TestCase
|
||||
from django.test import TestCase, override_settings
|
||||
from django.urls import reverse
|
||||
from instances.models import Instance
|
||||
|
||||
|
|
@ -25,3 +25,18 @@ class UpdateConsoleTestCase(TestCase):
|
|||
proxy = self.post({"listen_on": "127.0.0.1", "password": "", "keymap": "de"})
|
||||
proxy.set_console_keymap.assert_called_once_with("de")
|
||||
proxy.set_console_listener_addr.assert_called_once_with("127.0.0.1")
|
||||
|
||||
@override_settings(SERIAL_CONSOLE_ENABLED=True)
|
||||
def test_a_new_console_type_and_its_vnc_settings(self):
|
||||
data = {"listen_on": "0.0.0.0", "keymap": "de"}
|
||||
for old, new, vnc_settings in (("vnc", "pty", False), ("pty", "vnc", True)):
|
||||
with self.subTest(new), patch("instances.models.wvmInstance") as wvm:
|
||||
wvm.return_value.get_console_type.return_value = old
|
||||
self.client.post(reverse("instances:update_console", args=[self.instance.id]), dict(data, console_type=new))
|
||||
wvm.return_value.set_console_type.assert_called_once_with(new)
|
||||
self.assertEqual(wvm.return_value.set_console_listener_addr.called, vnc_settings)
|
||||
|
||||
@override_settings(SERIAL_CONSOLE_ENABLED=False)
|
||||
def test_serial_is_not_offered_while_the_serial_console_is_off(self):
|
||||
proxy = self.post({"console_type": "pty", "listen_on": "127.0.0.1", "keymap": "de"})
|
||||
proxy.set_console_type.assert_not_called()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue