Skip to content

Commit 4aac101

Browse files
committed
q-dev: add block devices tests
1 parent 64e7669 commit 4aac101

File tree

3 files changed

+346
-132
lines changed

3 files changed

+346
-132
lines changed

qubes/ext/block.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,8 @@ async def on_domain_start(self, vm, _event, **_kwargs):
552552
for device in assignment.devices:
553553
if isinstance(device, qubes.device_protocol.UnknownDevice):
554554
continue
555+
if device.attachment:
556+
continue
555557
if not assignment.matches(device):
556558
print(
557559
"Unrecognized identity, skipping attachment of device "
@@ -560,11 +562,9 @@ async def on_domain_start(self, vm, _event, **_kwargs):
560562
# chose first assignment (the most specific) and ignore rest
561563
if device not in to_attach:
562564
# make it unique
563-
to_attach[device] = assignment.clone(
564-
device=qubes.device_protocol.VirtualDevice(
565-
device.port, device.device_id))
565+
to_attach[device] = assignment.clone(device=device)
566566
for assignment in to_attach.values():
567-
await self.attach_and_notify(vm, assignment)
567+
asyncio.ensure_future(self.attach_and_notify(vm, assignment))
568568

569569
async def attach_and_notify(self, vm, assignment):
570570
# bypass DeviceCollection logic preventing double attach
@@ -575,7 +575,7 @@ async def attach_and_notify(self, vm, assignment):
575575
self.on_device_pre_attached_block(
576576
vm, 'device-pre-attach:block', device, assignment.options)
577577
await vm.fire_event_async(
578-
'device-attach:block', device=str(device), options=assignment.options)
578+
'device-attach:block', device=device, options=assignment.options)
579579

580580
@qubes.ext.handler('domain-shutdown')
581581
async def on_domain_shutdown(self, vm, event, **_kwargs):

qubes/ext/utils.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ def device_list_change(
6565
for front_vm in vm.app.domains:
6666
if not front_vm.is_running():
6767
continue
68-
for assignment in front_vm.devices[devclass].get_assigned_devices():
68+
for assignment in reversed(sorted(
69+
front_vm.devices[devclass].get_assigned_devices())):
6970
for device in assignment.devices:
7071
if (assignment.matches(device)
7172
and device.port_id in added

0 commit comments

Comments
 (0)