From fd6e4a8b14724b685020b51110de9c0ec041cc40 Mon Sep 17 00:00:00 2001 From: Piotr Bartman-Szwarc Date: Thu, 15 Aug 2024 12:19:29 +0200 Subject: [PATCH] q-dev: fix events --- qubes/devices.py | 2 +- qubes/ext/block.py | 8 ++++---- qubes/ext/utils.py | 2 +- qubes/tests/api_admin.py | 2 +- qubes/tests/devices_block.py | 6 +++--- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/qubes/devices.py b/qubes/devices.py index b41a84467..4f78270b0 100644 --- a/qubes/devices.py +++ b/qubes/devices.py @@ -127,7 +127,7 @@ class DeviceCollection: :param device: :py:class:`DeviceInfo` object to be attached - .. event:: device-detach: (device) + .. event:: device-detach: (port) Fired when device is detached from a VM. diff --git a/qubes/ext/block.py b/qubes/ext/block.py index 46c5f8001..0780876e6 100644 --- a/qubes/ext/block.py +++ b/qubes/ext/block.py @@ -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}" @@ -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() @@ -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): diff --git a/qubes/ext/utils.py b/qubes/ext/utils.py index c6cda9800..3505293d1 100644 --- a/qubes/ext/utils.py +++ b/qubes/ext/utils.py @@ -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) diff --git a/qubes/tests/api_admin.py b/qubes/tests/api_admin.py index a74f2cfee..effbefde8 100644 --- a/qubes/tests/api_admin.py +++ b/qubes/tests/api_admin.py @@ -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): diff --git a/qubes/tests/devices_block.py b/qubes/tests/devices_block.py index 2041838e6..79bc1e203 100644 --- a/qubes/tests/devices_block.py +++ b/qubes/tests/devices_block.py @@ -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 @@ -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)}))],