Skip to content

Commit

Permalink
q-dev: fix events
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrbartman committed Oct 15, 2024
1 parent ba2100e commit fd6e4a8
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion qubes/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class DeviceCollection:
:param device: :py:class:`DeviceInfo` object to be attached
.. event:: device-detach:<class> (device)
.. event:: device-detach:<class> (port)
Fired when device is detached from a VM.
Expand Down
8 changes: 4 additions & 4 deletions qubes/ext/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,8 @@ def notify_auto_attached(self, vm, assignment):
identity = assignment.device_id
device = assignment.device
if identity not in ('*', device.device_id):
print("Unrecognized identity, skipping attachment of device in port"
f" {assignment}", file=sys.stderr)
print("Unrecognized identity, skipping attachment of device "
f"from the port {assignment}", file=sys.stderr)
raise qubes.devices.UnrecognizedDevice(
f"Device presented identity {device.device_id} "
f"does not match expected {identity}"
Expand Down Expand Up @@ -594,7 +594,7 @@ async def on_domain_shutdown(self, vm, event, **_kwargs):
if front_vm == vm:
dev = BlockDevice(vm, dev_id)
asyncio.ensure_future(front_vm.fire_event_async(
'device-detach:block', device=dev))
'device-detach:block', port=dev))
else:
new_cache[domain.name][dev_id] = front_vm
self.devices_cache = new_cache.copy()
Expand All @@ -604,7 +604,7 @@ async def _detach_and_notify(self, vm, device, options):
self.on_device_pre_detached_block(
vm, 'device-pre-detach:block', device.port)
await vm.fire_event_async(
'device-detach:block', device=device, options=options)
'device-detach:block', port=device, options=options)

@qubes.ext.handler('qubes-close', system=True)
def on_qubes_close(self, app, event):
Expand Down
2 changes: 1 addition & 1 deletion qubes/ext/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def device_list_change(
for dev_id, front_vm in detached.items():
dev = device_class(vm, dev_id)
asyncio.ensure_future(front_vm.fire_event_async(
f'device-detach:{devclass}', device=dev))
f'device-detach:{devclass}', port=dev))
for dev_id in removed:
device = device_class(vm, dev_id)
vm.fire_event(f'device-removed:{devclass}', device=device)
Expand Down
2 changes: 1 addition & 1 deletion qubes/tests/api_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2148,7 +2148,7 @@ def test_496_vm_device_detach(self):
b'test-vm1', b'test-vm1+1234')
self.assertIsNone(value)
mock_detach.assert_called_once_with(self.vm, 'device-detach:testclass',
device=self.vm.devices['testclass']['1234'])
port=self.vm.devices['testclass']['1234'])
self.assertFalse(self.app.save.called)

def test_497_vm_device_detach_not_attached(self):
Expand Down
6 changes: 3 additions & 3 deletions qubes/tests/devices_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,9 +833,9 @@ def test_063_on_qdb_change_changed(self):

self.assertEqual(self.ext.devices_cache, {'sys-usb': {'sda': front_2}})
fire_event_async.assert_called_with(
'device-detach:block', device=exp_dev)
'device-detach:block', port=exp_dev)
fire_event_async_2.assert_called_once_with(
'device-attach:block', device=exp_dev, options={})
'device-attach:block', port=exp_dev, options={})

def test_064_on_qdb_change_removed_attached(self):
# attached to front-vm
Expand Down Expand Up @@ -889,7 +889,7 @@ def test_064_on_qdb_change_removed_attached(self):
self.ext.on_qdb_change(back_vm, None, None)
self.assertEqual(self.ext.devices_cache, {'sys-usb': {}})
fire_event_async.assert_called_with(
'device-detach:block', device=exp_dev)
'device-detach:block', port=exp_dev)
self.assertEqual(
back_vm.fired_events[
('device-removed:block', frozenset({('device', exp_dev)}))],
Expand Down

0 comments on commit fd6e4a8

Please sign in to comment.