mgmt: send artificial 'connection-established' event just after connection

This allows avoid race condition between  registering event handlers and
performing some action. The important thing is the event sent after
registering event handlers in qubesd. This means state changes (like
VM start/stop) after 'connection-established' event will be included in
event stream.

QubesOS/qubes-issues#2622
This commit is contained in:
Marek Marczykowski-Górecki 2017-04-14 23:09:16 +02:00
parent 8cc0af1eda
commit 643cef1e65
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
2 changed files with 7 additions and 1 deletions

View File

@ -583,6 +583,9 @@ class QubesMgmt(AbstractQubesMgmt):
type(self.app).add_handler('*', handler)
qubes.vm.BaseVM.add_handler('*', handler)
# send artificial event as a confirmation that connection is established
self.send_event(self.app, 'connection-established')
try:
yield from wait_for_cancel
except asyncio.CancelledError:

View File

@ -856,7 +856,10 @@ class TC_00_VMs(MgmtTestCase):
self.assertEventFired(self.emitter,
'mgmt-permission:' + 'mgmt.Events')
self.assertEqual(send_event.mock_calls,
[unittest.mock.call(self.vm, 'test-event', arg1='abc')])
[
unittest.mock.call(self.app, 'connection-established'),
unittest.mock.call(self.vm, 'test-event', arg1='abc')
])
def test_990_vm_unexpected_payload(self):