Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api/admin: gracefully handle device listing during qubesd shutdown #609

Merged
merged 2 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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':

Check warning on line 1205 in qubes/api/admin.py

View check run for this annotation

Codecov / codecov/patch

qubes/api/admin.py#L1204-L1205

Added lines #L1204 - L1205 were not covered by tests
# shutdown in progress, return specific error
raise qubes.exc.QubesException("qubesd shutdown in progress")
raise

Check warning on line 1208 in qubes/api/admin.py

View check run for this annotation

Codecov / codecov/patch

qubes/api/admin.py#L1207-L1208

Added lines #L1207 - L1208 were not covered by tests
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 @@
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':

Check warning on line 1229 in qubes/api/admin.py

View check run for this annotation

Codecov / codecov/patch

qubes/api/admin.py#L1228-L1229

Added lines #L1228 - L1229 were not covered by tests
# shutdown in progress, return specific error
raise qubes.exc.QubesException("qubesd shutdown in progress")
raise

Check warning on line 1232 in qubes/api/admin.py

View check run for this annotation

Codecov / codecov/patch

qubes/api/admin.py#L1231-L1232

Added lines #L1231 - L1232 were not covered by tests
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 @@
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':

Check warning on line 1264 in qubes/api/admin.py

View check run for this annotation

Codecov / codecov/patch

qubes/api/admin.py#L1263-L1264

Added lines #L1263 - L1264 were not covered by tests
# shutdown in progress, return specific error
raise qubes.exc.QubesException("qubesd shutdown in progress")
raise

Check warning on line 1267 in qubes/api/admin.py

View check run for this annotation

Codecov / codecov/patch

qubes/api/admin.py#L1266-L1267

Added lines #L1266 - L1267 were not covered by tests
if self.arg:
select_backend, select_ident = self.arg.split('+', 1)
device_assignments = [dev for dev in device_assignments
Expand Down
3 changes: 2 additions & 1 deletion qubes/vm/adminvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import grp
import subprocess
import libvirt
import uuid

import qubes
import qubes.exc
Expand All @@ -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',
Expand Down