events: deserialize DeviceInfo class in device-* events
This commit is contained in:
parent
a8c24bee0f
commit
4a1e90392b
@ -202,6 +202,15 @@ class EventsDispatcher(object):
|
|||||||
if event in ['domain-add', 'domain-delete']:
|
if event in ['domain-add', 'domain-delete']:
|
||||||
self.app.domains.clear_cache()
|
self.app.domains.clear_cache()
|
||||||
subject = None
|
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()
|
handlers = [h_func for h_name, h_func_set in self.handlers.items()
|
||||||
for h_func in h_func_set
|
for h_func in h_func_set
|
||||||
if fnmatch.fnmatch(event, h_name)]
|
if fnmatch.fnmatch(event, h_name)]
|
||||||
|
@ -253,3 +253,13 @@ class TC_00_Events(qubesadmin.tests.QubesTestCase):
|
|||||||
unittest.mock.call().kill.assert_called_once_with()
|
unittest.mock.call().kill.assert_called_once_with()
|
||||||
|
|
||||||
loop.close()
|
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='{}')
|
||||||
|
Loading…
Reference in New Issue
Block a user