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

fix(instances): USB device changes as PCI ones; device refusals name no VM to owners

- A USB device added to or removed from a VM with a saved state applied
  only at the next cold boot: refused now, as for PCI devices, and the
  form says so.
- A USB hot plug or removal that failed half way said only libvirt's
  error: it now says where the device is, as for PCI devices
  (_hostdev_outcome, shared).
- A host device refusal (check_hostdevs) names the other VMs that have
  the device; users who do not see the hosts, such as an owner whose
  snapshot revert is refused, now read that a device is not free and that
  an administrator can see why.
- The host's USB devices named among a PCI device's host resources were
  English in every language.
This commit is contained in:
catborise 2026-11-11 16:22:42 +03:00
parent d07362106a
commit 2db25314ea
12 changed files with 662 additions and 563 deletions

View file

@ -12,3 +12,12 @@ class PublicErrorTests(SimpleTestCase):
self.assertEqual(public_error_text(PermissionDenied()), "You may no longer do this.")
self.assertEqual(public_error_text(Http404("No Instance matches the given query.")),
"The virtual machine is no longer in the panel.")
def test_a_host_device_refusal_names_no_other_vm(self):
from vrtManager.nodedevs import HostDevicesRefused
from vrtManager.util import message
refused = HostDevicesRefused("%(problems)s", problems=[message("%(device)s is given to %(vms)s",
device="PCI device 0000:00:0a.0", vms="private-db-1")])
self.assertNotIn("private-db-1", public_error_text(refused))
self.assertIn("Host devices tab", public_error_text(refused))

View file

@ -22,6 +22,7 @@ from libvirt import libvirtError
from accounts.models import UserInstance
from appsettings.models import AppSettings
from instances.models import Instance
from vrtManager.nodedevs import HostDevicesRefused
from vrtManager.util import ConnectionFailed, HostBusy, OperationError, render
from . import jobs
@ -57,6 +58,8 @@ HOST_BUSY = gettext_noop("The host of this virtual machine is busy with other re
# a job's checks in the worker (precheck) refuse with Django's exceptions, which have no text
NOT_ALLOWED = gettext_noop("You may no longer do this.")
NOT_FOUND = gettext_noop("The virtual machine is no longer in the panel.")
DEVICES_REFUSED = gettext_noop("A host device of this virtual machine is not free on its host now; an administrator "
"can see why on its Host devices tab.")
BOUNDS = {"WORKER_CONCURRENCY": (1, 16, 4), "JOB_RETENTION_DAYS": (1, 3650, 30), "LOG_RETENTION_DAYS": (1, 3650, 365)}
@ -103,7 +106,8 @@ def words(messages):
def public_error(exception):
"""The error for users who do not see the hosts: a connection error names
the host and how it is reached, so they learn only that it cannot be reached."""
the host and how it is reached, so they learn only that it cannot be
reached; a host device refusal names other VMs and what the host has."""
connection_error = isinstance(exception, ConnectionFailed) or (
isinstance(exception, libvirtError)
and exception.get_error_domain() in TRANSPORT_ERROR_DOMAINS
@ -115,6 +119,8 @@ def public_error(exception):
return say(NOT_ALLOWED)
if isinstance(exception, Http404):
return say(NOT_FOUND)
if isinstance(exception, HostDevicesRefused):
return say(DEVICES_REFUSED)
return say(UNREACHABLE) if connection_error else said(exception)