Skip to content

Commit

Permalink
q-dev: minor device_protocol fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrbartman committed Oct 14, 2024
1 parent d019190 commit f602a3d
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions qubesadmin/device_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def parse_basic_device_properties(
f"when expected port: {expected.port_id}.")
properties.pop('port_id', None)

if expected.devclass == 'peripheral':
if not expected.has_devclass:
expected = Port(
expected.backend_domain,
expected.port_id,
Expand Down Expand Up @@ -360,13 +360,18 @@ def devclass(self) -> str:
return "peripheral"


@property
def has_devclass(self):
return self.__devclass is not None


class VirtualDevice:
"""
Class of a device connected to *port*.
Attributes:
port (Port): A unique identifier for the port within the backend domain.
device_id (str): A unique identifier for the device.
port (Port): Peripheral device port exposed by vm.
device_id (str): An identifier for the device.
"""
def __init__(
self,
Expand Down Expand Up @@ -573,10 +578,8 @@ def serialize(self) -> bytes:
for key, value in (
('device_id', self.device_id),
('port_id', self.port_id),
('devclass', self.devclass)))

properties += b' ' + DeviceSerializer.pack_property(
'backend_domain', self.backend_name)
('devclass', self.devclass),
('backend_domain', self.backend_name)))

return properties

Expand Down Expand Up @@ -1212,7 +1215,7 @@ def device(self) -> DeviceInfo:
return devices[0]
if len(devices) > 1:
raise ProtocolError("Too many devices matches to assignment")
raise ProtocolError("Any devices matches to assignment")
raise ProtocolError("No devices matches to assignment")

@property
def port(self) -> Port:
Expand Down Expand Up @@ -1329,7 +1332,7 @@ def _deserialize(
device_id=properties['device_id'])
# we do not need port, we need device
del properties['port']
properties.pop('device_id', None)
del properties['device_id']
properties['device'] = expected_device

return cls(**properties)
Expand Down

0 comments on commit f602a3d

Please sign in to comment.