From f57e73686809dfa1378cbc9a13335393eea41091 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Wed, 17 Jul 2024 17:43:36 +0200 Subject: [PATCH 1/2] api/admin: gracefully handle device listing during qubesd shutdown When shutting down qubesd during tests, a bunch of properties are cleaned up early (see 'close()' method of QubesVM object). Do not fail with unhandled exception in this case, but report a clear error message instead. --- qubes/api/admin.py | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/qubes/api/admin.py b/qubes/api/admin.py index 39b9311e4..e255cf44d 100644 --- a/qubes/api/admin.py +++ b/qubes/api/admin.py @@ -1199,7 +1199,13 @@ async def deviceclass_list(self): scope='local', read=True) async def vm_device_available(self, endpoint): devclass = endpoint - devices = self.dest.devices[devclass].get_exposed_devices() + try: + devices = self.dest.devices[devclass].get_exposed_devices() + except AttributeError as e: + if e.name == 'devices': + # shutdown in progress, return specific error + raise qubes.exc.QubesException("qubesd shutdown in progress") + raise if self.arg: devices = [dev for dev in devices if dev.ident == self.arg] # no duplicated devices, but device may not exist, in which case @@ -1216,8 +1222,14 @@ async def vm_device_available(self, endpoint): scope='local', read=True) async def vm_device_list(self, endpoint): devclass = endpoint - device_assignments = list( - self.dest.devices[devclass].get_assigned_devices()) + try: + device_assignments = list( + self.dest.devices[devclass].get_assigned_devices()) + except AttributeError as e: + if e.name == 'devices': + # shutdown in progress, return specific error + raise qubes.exc.QubesException("qubesd shutdown in progress") + raise if self.arg: select_backend, select_ident = self.arg.split('+', 1) device_assignments = [dev for dev in device_assignments @@ -1245,7 +1257,14 @@ async def vm_device_list(self, endpoint): no_payload=True, scope='local', read=True) async def vm_device_attached(self, endpoint): devclass = endpoint - device_assignments = self.dest.devices[devclass].get_attached_devices() + try: + device_assignments = \ + self.dest.devices[devclass].get_attached_devices() + except AttributeError as e: + if e.name == 'devices': + # shutdown in progress, return specific error + raise qubes.exc.QubesException("qubesd shutdown in progress") + raise if self.arg: select_backend, select_ident = self.arg.split('+', 1) device_assignments = [dev for dev in device_assignments From 1734b65dd2bf906aacbd1de7f3bcea5784180bd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Thu, 18 Jul 2024 00:30:38 +0200 Subject: [PATCH 2/2] vm: fix uuid property type for AdminVM --- qubes/vm/adminvm.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/qubes/vm/adminvm.py b/qubes/vm/adminvm.py index 6b67addbe..6a9bb67be 100644 --- a/qubes/vm/adminvm.py +++ b/qubes/vm/adminvm.py @@ -25,6 +25,7 @@ import grp import subprocess import libvirt +import uuid import qubes import qubes.exc @@ -45,7 +46,7 @@ class AdminVM(BaseVM): default=0, type=int, setter=qubes.property.forbidden) uuid = qubes.property('uuid', - default='00000000-0000-0000-0000-000000000000', + default=uuid.UUID('00000000-0000-0000-0000-000000000000'), setter=qubes.property.forbidden) default_dispvm = qubes.VMProperty('default_dispvm',