Skip to content

Commit f602a3d

Browse files
committed
q-dev: minor device_protocol fixes
1 parent d019190 commit f602a3d

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

qubesadmin/device_protocol.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def parse_basic_device_properties(
181181
f"when expected port: {expected.port_id}.")
182182
properties.pop('port_id', None)
183183

184-
if expected.devclass == 'peripheral':
184+
if not expected.has_devclass:
185185
expected = Port(
186186
expected.backend_domain,
187187
expected.port_id,
@@ -360,13 +360,18 @@ def devclass(self) -> str:
360360
return "peripheral"
361361

362362

363+
@property
364+
def has_devclass(self):
365+
return self.__devclass is not None
366+
367+
363368
class VirtualDevice:
364369
"""
365370
Class of a device connected to *port*.
366371
367372
Attributes:
368-
port (Port): A unique identifier for the port within the backend domain.
369-
device_id (str): A unique identifier for the device.
373+
port (Port): Peripheral device port exposed by vm.
374+
device_id (str): An identifier for the device.
370375
"""
371376
def __init__(
372377
self,
@@ -573,10 +578,8 @@ def serialize(self) -> bytes:
573578
for key, value in (
574579
('device_id', self.device_id),
575580
('port_id', self.port_id),
576-
('devclass', self.devclass)))
577-
578-
properties += b' ' + DeviceSerializer.pack_property(
579-
'backend_domain', self.backend_name)
581+
('devclass', self.devclass),
582+
('backend_domain', self.backend_name)))
580583

581584
return properties
582585

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

12171220
@property
12181221
def port(self) -> Port:
@@ -1329,7 +1332,7 @@ def _deserialize(
13291332
device_id=properties['device_id'])
13301333
# we do not need port, we need device
13311334
del properties['port']
1332-
properties.pop('device_id', None)
1335+
del properties['device_id']
13331336
properties['device'] = expected_device
13341337

13351338
return cls(**properties)

0 commit comments

Comments
 (0)