@@ -145,7 +145,7 @@ def parse_basic_device_properties(
145
145
the expected values.
146
146
"""
147
147
expected = expected_device .port
148
- exp_vm_name = expected .backend_domain . name
148
+ exp_vm_name = expected .backend_name
149
149
if properties .get ('backend_domain' , exp_vm_name ) != exp_vm_name :
150
150
raise UnexpectedDeviceProperty (
151
151
f"Got device exposed by { properties ['backend_domain' ]} "
@@ -264,7 +264,7 @@ def __str__(self):
264
264
265
265
@property
266
266
def backend_name (self ) -> str :
267
- if self .backend_domain is not None :
267
+ if self .backend_domain not in ( None , "*" ) :
268
268
return self .backend_domain .name
269
269
return "*"
270
270
@@ -307,7 +307,9 @@ def port_id(self) -> str:
307
307
308
308
Unique for given domain and devclass.
309
309
"""
310
- return self .__port_id
310
+ if self .__port_id is not None :
311
+ return self .__port_id
312
+ return '*'
311
313
312
314
@property
313
315
def backend_domain (self ) -> Optional [QubesVM ]:
@@ -338,7 +340,7 @@ def __init__(
338
340
port : Optional [Port ] = None ,
339
341
device_id : Optional [str ] = None ,
340
342
):
341
- # TODO! one of them cannot be None
343
+ assert port is not None or device_id is not None
342
344
self .port : Optional [Port ] = port
343
345
self ._device_id = device_id
344
346
@@ -379,7 +381,6 @@ def backend_name(self):
379
381
return self .port .backend_name
380
382
return '*'
381
383
382
-
383
384
@property
384
385
def port_id (self ):
385
386
if self .port != '*' and self .port .port_id is not None :
@@ -496,8 +497,8 @@ def _parse(
496
497
else :
497
498
identity = representation
498
499
port_id , _ , devid = identity .partition (':' )
499
- if devid in ( '' , '*' ) :
500
- devid = '*'
500
+ if devid == '' :
501
+ devid = None
501
502
return cls (
502
503
Port (backend_domain = backend , port_id = port_id , devclass = devclass ),
503
504
device_id = devid
@@ -515,7 +516,7 @@ def serialize(self) -> bytes:
515
516
('devclass' , self .devclass )))
516
517
517
518
properties += b' ' + DeviceSerializer .pack_property (
518
- 'backend_domain' , self .backend_domain . name )
519
+ 'backend_domain' , self .backend_name )
519
520
520
521
return properties
521
522
@@ -1143,7 +1144,7 @@ def attached(self) -> bool:
1143
1144
Returns False if device is attached to different domain
1144
1145
"""
1145
1146
for device in self .devices :
1146
- if device .attachment == self .frontend_domain :
1147
+ if device .attachment and device . attachment == self .frontend_domain :
1147
1148
return True
1148
1149
return False
1149
1150
@@ -1233,11 +1234,11 @@ def _deserialize(
1233
1234
return cls (** properties )
1234
1235
1235
1236
def matches (self , device : VirtualDevice ) -> bool :
1236
- if self .backend_domain != '*' and self . backend_domain != device .backend_domain :
1237
+ if self .devclass != device .devclass :
1237
1238
return False
1238
- if self .port_id != '*' and self . port_id != device .port_id :
1239
+ if self .backend_domain != device .backend_domain :
1239
1240
return False
1240
- if self .devclass != '*' and self .devclass != device .devclass :
1241
+ if self .port_id != '*' and self .port_id != device .port_id :
1241
1242
return False
1242
1243
if self .device_id != '*' and self .device_id != device .device_id :
1243
1244
return False
0 commit comments