Fix reporting events even if its source is not available anymore
This is especially the case for domain-shutdown event for DispVM - when handled, DispVM can be already removed. Give the handled VM object even if actual VM is already removed. For this, avoid VM existence check by using domains.get_blind() method. And actually implement domains.get_blind() method - it was present only in generic collection, but not VMCollection.
This commit is contained in:
parent
b2a70f3794
commit
0caf6f735d
@ -85,6 +85,13 @@ class VMCollection(object):
|
||||
def __getitem__(self, item):
|
||||
if not self.app.blind_mode and item not in self:
|
||||
raise KeyError(item)
|
||||
return self.get_blind(item)
|
||||
|
||||
def get_blind(self, item):
|
||||
'''
|
||||
Get a vm without downloading the list
|
||||
and checking if exists
|
||||
'''
|
||||
if item not in self._vm_objects:
|
||||
cls = qubesadmin.vm.QubesVM
|
||||
# provide class name to constructor, if already cached (which can be
|
||||
|
@ -192,7 +192,7 @@ class EventsDispatcher(object):
|
||||
if event in ['property-set:name']:
|
||||
self.app.domains.clear_cache()
|
||||
try:
|
||||
subject = self.app.domains[subject]
|
||||
subject = self.app.domains.get_blind(subject)
|
||||
except KeyError:
|
||||
return
|
||||
else:
|
||||
|
@ -54,7 +54,7 @@ class TC_00_Events(qubesadmin.tests.QubesTestCase):
|
||||
handler.reset_mock()
|
||||
self.dispatcher.handle('test-vm', 'some-event', arg1='value1')
|
||||
handler.assert_called_once_with(
|
||||
self.app.domains['test-vm'], 'some-event', arg1='value1')
|
||||
self.app.domains.get_blind('test-vm'), 'some-event', arg1='value1')
|
||||
handler.reset_mock()
|
||||
self.dispatcher.handle('', 'other-event', arg1='value1')
|
||||
self.assertFalse(handler.called)
|
||||
@ -70,7 +70,7 @@ class TC_00_Events(qubesadmin.tests.QubesTestCase):
|
||||
handler.reset_mock()
|
||||
self.dispatcher.handle('test-vm', 'some-event', arg1='value1')
|
||||
handler.assert_called_once_with(
|
||||
self.app.domains['test-vm'], 'some-event', arg1='value1')
|
||||
self.app.domains.get_blind('test-vm'), 'some-event', arg1='value1')
|
||||
handler.reset_mock()
|
||||
self.dispatcher.handle('', 'other-event', arg1='value1')
|
||||
handler.assert_called_once_with(None, 'other-event', arg1='value1')
|
||||
@ -116,9 +116,10 @@ class TC_00_Events(qubesadmin.tests.QubesTestCase):
|
||||
self.assertEqual(handler.mock_calls, [
|
||||
unittest.mock.call(None, 'some-event', arg1='value1'),
|
||||
unittest.mock.call(
|
||||
self.app.domains['some-vm'], 'some-event', arg1='value1'),
|
||||
self.app.domains.get_blind('some-vm'), 'some-event',
|
||||
arg1='value1'),
|
||||
unittest.mock.call(
|
||||
self.app.domains['some-vm'], 'some-event',
|
||||
self.app.domains.get_blind('some-vm'), 'some-event',
|
||||
arg_without_value='', arg2='value'),
|
||||
])
|
||||
cleanup_func.assert_called_once_with()
|
||||
|
Loading…
Reference in New Issue
Block a user