Skip to content

Commit fd6bd27

Browse files
committed
q-dev: minor device_protocol fixes
1 parent 4ff7ae3 commit fd6bd27

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

qubes/device_protocol.py

+14-11
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def parse_basic_device_properties(
161161
f"when expected port: {expected.port_id}.")
162162
properties.pop('port_id', None)
163163

164-
if expected.devclass == 'peripheral':
164+
if not expected.has_devclass:
165165
expected = Port(
166166
expected.backend_domain,
167167
expected.port_id,
@@ -339,14 +339,18 @@ def devclass(self) -> str:
339339
return self.__devclass
340340
return "peripheral"
341341

342+
@property
343+
def has_devclass(self):
344+
return self.__devclass is not None
345+
342346

343347
class VirtualDevice:
344348
"""
345349
Class of a device connected to *port*.
346350
347351
Attributes:
348-
port (Port): A unique identifier for the port within the backend domain.
349-
device_id (str): A unique identifier for the device.
352+
port (Port): Peripheral device port exposed by vm.
353+
device_id (str): An identifier for the device.
350354
"""
351355
def __init__(
352356
self,
@@ -553,10 +557,8 @@ def serialize(self) -> bytes:
553557
for key, value in (
554558
('device_id', self.device_id),
555559
('port_id', self.port_id),
556-
('devclass', self.devclass)))
557-
558-
properties += b' ' + DeviceSerializer.pack_property(
559-
'backend_domain', self.backend_name)
560+
('devclass', self.devclass),
561+
('backend_domain', self.backend_name)))
560562

561563
return properties
562564

@@ -919,7 +921,8 @@ def subdevices(self) -> List[VirtualDevice]:
919921
If the device has subdevices (e.g., partitions of a USB stick),
920922
the subdevices id should be here.
921923
"""
922-
return [dev for dev in self.backend_domain.devices[self.devclass]
924+
return [dev for devclass in self.backend_domain.devices.keys()
925+
for dev in self.backend_domain.devices[devclass]
923926
if dev.parent_device.port.port_id == self.port_id]
924927

925928
@property
@@ -933,7 +936,7 @@ def serialize(self) -> bytes:
933936
"""
934937
Serialize an object to be transmitted via Qubes API.
935938
"""
936-
properties = VirtualDevice.serialize(self)
939+
properties = super().serialize()
937940
# 'attachment', 'interfaces', 'data', 'parent_device'
938941
# are not string, so they need special treatment
939942
default = DeviceInfo(self.port)
@@ -1192,7 +1195,7 @@ def device(self) -> DeviceInfo:
11921195
return devices[0]
11931196
if len(devices) > 1:
11941197
raise ProtocolError("Too many devices matches to assignment")
1195-
raise ProtocolError("Any devices matches to assignment")
1198+
raise ProtocolError("No devices matches to assignment")
11961199

11971200
@property
11981201
def port(self) -> Port:
@@ -1309,7 +1312,7 @@ def _deserialize(
13091312
device_id=properties['device_id'])
13101313
# we do not need port, we need device
13111314
del properties['port']
1312-
properties.pop('device_id', None)
1315+
del properties['device_id']
13131316
properties['device'] = expected_device
13141317

13151318
return cls(**properties)

0 commit comments

Comments
 (0)