Skip to content

Commit

Permalink
q-dev: implement device_id
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrbartman committed Oct 14, 2024
1 parent bab3289 commit 247dca6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
24 changes: 9 additions & 15 deletions qubes_config/tests/test_usb_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,15 +845,13 @@ def test_u2f_handler_add_without_service(test_qapp,
def test_devices_handler_unsaved(test_qapp, test_policy_manager, real_builder):
test_qapp.expected_calls[('sys-usb', "admin.vm.device.pci.Attached",
None, None)] = \
b"0\x00dom0+00_0d.0 ident='00_0d.0' devclass='pci' " \
b"0\x00dom0+00_0d.0 device_id='*' port_id='00_0d.0' devclass='pci' " \
b"backend_domain='dom0' required='yes' attach_automatically='yes' " \
b"_no-strict-reset='yes'\n"
test_qapp.expected_calls[('dom0', "admin.vm.device.pci.Available",
None, None)] = \
b"0\x0000_0d.0 ident='00_0d.0' devclass='pci' backend_domain='dom0' " \
b"serial='unknown' manufacturer='unknown' " \
b"self_identity='0000:0000::p0c0300' vendor='unknown' " \
b"product='unknown' name='unknown' interfaces='p0c0300' " \
b"0\x0000_0d.0 device_id='0000:0000::p0c0300' port_id='00_0d.0' " \
b"devclass='pci' backend_domain='dom0' interfaces='p0c0300' " \
b"_function='0' _bus='00' _libvirt_name='pci_0000_00_0d_0' " \
b"_device='0d'\n"

Expand All @@ -878,26 +876,22 @@ def test_devices_handler_detect_usbvms(test_qapp,
test_policy_manager, real_builder):
test_qapp.expected_calls[('sys-usb', "admin.vm.device.pci.Attached",
None, None)] = \
b"0\x00dom0+00_0d.0 ident='00_0d.0' devclass='pci' " \
b"0\x00dom0+00_0d.0 device_id='*' port_id='00_0d.0' devclass='pci' " \
b"backend_domain='dom0' required='yes' attach_automatically='yes' " \
b"_no-strict-reset='yes'\n"
test_qapp.expected_calls[('test-standalone', "admin.vm.device.pci.Attached",
None, None)] = \
b"0\x00dom0+00_0f.0 ident='00_0f.0' devclass='pci' " \
b"0\x00dom0+00_0f.0 device_id='*' port_id='00_0f.0' devclass='pci' " \
b"backend_domain='dom0' required='yes' attach_automatically='yes' " \
b"_no-strict-reset='yes'\n"
test_qapp.expected_calls[('dom0', "admin.vm.device.pci.Available",
None, None)] = \
b"0\x0000_0f.0 ident='00_0f.0' devclass='pci' backend_domain='dom0' " \
b"serial='unknown' manufacturer='unknown' " \
b"self_identity='0000:0000::p0c0300' vendor='unknown' " \
b"product='unknown' name='unknown' interfaces='p0c0300' " \
b"0\x0000_0f.0 device_id='0000:0000::p0c0300' port_id='00_0f.0' " \
b"devclass='pci' backend_domain='dom0' interfaces='p0c0300' " \
b"_function='0' _bus='00' _libvirt_name='pci_0000_00_0f_0' " \
b"_device='0f'\n" \
b"00_0d.0 ident='00_0d.0' devclass='pci' backend_domain='dom0' " \
b"serial='unknown' manufacturer='unknown' " \
b"self_identity='0000:0000::p0c0300' vendor='unknown' " \
b"product='unknown' name='unknown' interfaces='p0c0300' " \
b"00_0d.0 device_id='0000:0000::p0c0300' port_id='00_0d.0' " \
b"devclass='pci' backend_domain='dom0' interfaces='p0c0300' " \
b"_function='0' _bus='00' _libvirt_name='pci_0000_00_0d_0' " \
b"_device='0d'\n"

Expand Down
2 changes: 1 addition & 1 deletion qui/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def device_hbox(device) -> Gtk.Box:
dev_icon = create_icon(icon)

name_label = Gtk.Label(xalign=0)
name = f"{device.backend_domain}:{device.ident} - {device.description}"
name = f"{device.backend_domain}:{device.port_id} - {device.description}"
if device.attachments:
dev_list = ", ".join(list(device.attachments))
name_label.set_markup(f'<b>{name} ({dev_list})</b>')
Expand Down
12 changes: 9 additions & 3 deletions qui/devices/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def __init__(self, dev: qubesadmin.devices.DeviceInfo,
if dev.devclass == 'block' and 'size' in dev.data:
self._dev_name += " (" + size_to_human(int(dev.data['size'])) + ")"

self._ident: str = getattr(dev, 'ident', 'unknown')
self._ident: str = getattr(dev, 'port_id', 'unknown')
self._description: str = getattr(dev, 'description', 'unknown')
self._devclass: str = getattr(dev, 'devclass', 'unknown')
self._data: Dict = getattr(dev, 'data', {})
Expand Down Expand Up @@ -232,7 +232,10 @@ def attach_to_vm(self, vm: VM):
"""
try:
assignment = qubesadmin.device_protocol.DeviceAssignment(
self.backend_domain, self.id_string)
qubesadmin.device_protocol.Device(
qubesadmin.device_protocol.Port(
self.backend_domain, self.id_string, self.device_class)
))

vm.vm_object.devices[self.device_class].attach(assignment)
self.gtk_app.emit_notification(
Expand Down Expand Up @@ -263,7 +266,10 @@ def detach_from_vm(self, vm: VM):
notification_id=self.notification_id)
try:
assignment = qubesadmin.device_protocol.DeviceAssignment(
self.backend_domain, self._ident)
qubesadmin.device_protocol.Device(
qubesadmin.device_protocol.Port(
self.backend_domain, self._ident, self.device_class)
))
vm.vm_object.devices[self.device_class].detach(assignment)
except qubesadmin.exc.QubesException as ex:
self.gtk_app.emit_notification(
Expand Down

0 comments on commit 247dca6

Please sign in to comment.