diff --git a/qubesadmin/events/__init__.py b/qubesadmin/events/__init__.py index 2f0487f..a10f16f 100644 --- a/qubesadmin/events/__init__.py +++ b/qubesadmin/events/__init__.py @@ -202,6 +202,15 @@ class EventsDispatcher(object): if event in ['domain-add', 'domain-delete']: self.app.domains.clear_cache() subject = None + # deserialize known attributes + if event.startswith('device-') and 'device' in kwargs: + try: + devclass = event.split(':', 1)[1] + backend_domain, ident = kwargs['device'].split(':', 1) + kwargs['device'] = self.app.domains.get_blind(backend_domain)\ + .devices[devclass][ident] + except (KeyError, ValueError): + pass handlers = [h_func for h_name, h_func_set in self.handlers.items() for h_func in h_func_set if fnmatch.fnmatch(event, h_name)] diff --git a/qubesadmin/tests/events.py b/qubesadmin/tests/events.py index e2f43e7..54984bb 100644 --- a/qubesadmin/tests/events.py +++ b/qubesadmin/tests/events.py @@ -253,3 +253,13 @@ class TC_00_Events(qubesadmin.tests.QubesTestCase): unittest.mock.call().kill.assert_called_once_with() loop.close() + + def test_030_events_device(self): + handler = unittest.mock.Mock() + self.dispatcher.add_handler('device-attach:test', handler) + self.dispatcher.handle('test-vm', 'device-attach:test', + device='test-vm2:dev', options='{}') + vm = self.app.domains.get_blind('test-vm') + dev = self.app.domains.get_blind('test-vm2').devices['test']['dev'] + handler.assert_called_once_with(vm, 'device-attach:test', device=dev, + options='{}')