Skip to content

Commit

Permalink
api/admin: gracefully handle device listing during qubesd shutdown
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
marmarek committed Jul 17, 2024
1 parent 77aa7ce commit f57e736
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions qubes/api/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f57e736

Please sign in to comment.