events: deserialize DeviceInfo class in device-* events

This commit is contained in:
Marek Marczykowski-Górecki 2018-09-18 21:55:32 +02:00
parent a8c24bee0f
commit 4a1e90392b
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
2 changed files with 19 additions and 0 deletions

View File

@ -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)]

View File

@ -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='{}')