2012-08-31 00:20:32 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
2012-12-11 10:23:37 +00:00
|
|
|
:codeauthor: :email:`Pedro Algarvio (pedro@algarvio.me)`
|
2013-09-16 16:24:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
tests.unit.utils.event_test
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2012-08-31 00:20:32 +00:00
|
|
|
'''
|
|
|
|
|
2012-12-11 10:23:37 +00:00
|
|
|
# Import python libs
|
2014-11-21 19:05:13 +00:00
|
|
|
from __future__ import absolute_import
|
2012-08-31 00:20:32 +00:00
|
|
|
import os
|
2012-09-19 20:21:56 +00:00
|
|
|
import hashlib
|
2013-12-02 22:26:13 +00:00
|
|
|
import time
|
2015-04-08 03:30:04 +00:00
|
|
|
from tornado.testing import AsyncTestCase
|
2013-12-22 23:33:07 +00:00
|
|
|
import zmq
|
2015-04-14 00:41:21 +00:00
|
|
|
import zmq.eventloop.ioloop
|
|
|
|
# support pyzmq 13.0.x, TODO: remove once we force people to 14.0.x
|
|
|
|
if not hasattr(zmq.eventloop.ioloop, 'ZMQIOLoop'):
|
|
|
|
zmq.eventloop.ioloop.ZMQIOLoop = zmq.eventloop.ioloop.IOLoop
|
2013-12-02 22:26:13 +00:00
|
|
|
from contextlib import contextmanager
|
2013-12-02 23:20:54 +00:00
|
|
|
from multiprocessing import Process
|
2012-08-31 00:20:32 +00:00
|
|
|
|
2013-06-24 22:53:59 +00:00
|
|
|
# Import Salt Testing libs
|
2013-12-22 23:33:07 +00:00
|
|
|
from salttesting import (expectedFailure, skipIf)
|
2013-06-24 22:53:59 +00:00
|
|
|
from salttesting import TestCase
|
2013-06-27 13:12:19 +00:00
|
|
|
from salttesting.helpers import ensure_in_syspath
|
|
|
|
ensure_in_syspath('../../')
|
|
|
|
|
|
|
|
# Import salt libs
|
|
|
|
import integration
|
2014-07-15 21:06:15 +00:00
|
|
|
from salt.utils.process import clean_proc
|
2013-06-27 13:12:19 +00:00
|
|
|
from salt.utils import event
|
2013-06-24 22:53:59 +00:00
|
|
|
|
2014-11-21 20:42:32 +00:00
|
|
|
# Import 3rd-+arty libs
|
|
|
|
from salt.ext.six.moves import range # pylint: disable=import-error,redefined-builtin
|
|
|
|
|
2012-08-31 00:20:32 +00:00
|
|
|
SOCK_DIR = os.path.join(integration.TMP, 'test-socks')
|
|
|
|
|
2013-12-22 23:40:09 +00:00
|
|
|
NO_LONG_IPC = False
|
|
|
|
if getattr(zmq, 'IPC_PATH_MAX_LEN', 103) <= 103:
|
2013-12-22 23:33:07 +00:00
|
|
|
NO_LONG_IPC = True
|
2013-12-03 20:30:16 +00:00
|
|
|
|
2013-12-23 16:25:16 +00:00
|
|
|
|
2013-12-02 22:26:13 +00:00
|
|
|
@contextmanager
|
2013-12-02 23:20:54 +00:00
|
|
|
def eventpublisher_process():
|
2013-12-03 20:30:16 +00:00
|
|
|
proc = event.EventPublisher({'sock_dir': SOCK_DIR})
|
2013-12-02 22:26:13 +00:00
|
|
|
proc.start()
|
|
|
|
try:
|
2013-12-02 23:20:54 +00:00
|
|
|
if os.environ.get('TRAVIS_PYTHON_VERSION', None) is not None:
|
|
|
|
# Travis is slow
|
|
|
|
time.sleep(10)
|
|
|
|
else:
|
|
|
|
time.sleep(2)
|
2013-12-02 22:26:13 +00:00
|
|
|
yield
|
|
|
|
finally:
|
2014-04-18 06:52:40 +00:00
|
|
|
clean_proc(proc)
|
2012-12-11 10:23:37 +00:00
|
|
|
|
2013-12-23 16:25:16 +00:00
|
|
|
|
2013-12-02 23:20:54 +00:00
|
|
|
class EventSender(Process):
|
|
|
|
def __init__(self, data, tag, wait):
|
|
|
|
super(EventSender, self).__init__()
|
|
|
|
self.data = data
|
|
|
|
self.tag = tag
|
|
|
|
self.wait = wait
|
|
|
|
|
|
|
|
def run(self):
|
2014-03-22 21:21:08 +00:00
|
|
|
me = event.MasterEvent(SOCK_DIR)
|
2013-12-02 23:20:54 +00:00
|
|
|
time.sleep(self.wait)
|
|
|
|
me.fire_event(self.data, self.tag)
|
|
|
|
# Wait a few seconds before tearing down the zmq context
|
|
|
|
if os.environ.get('TRAVIS_PYTHON_VERSION', None) is not None:
|
|
|
|
# Travis is slow
|
|
|
|
time.sleep(10)
|
|
|
|
else:
|
|
|
|
time.sleep(2)
|
|
|
|
|
2013-12-03 20:30:16 +00:00
|
|
|
|
2013-12-02 23:20:54 +00:00
|
|
|
@contextmanager
|
|
|
|
def eventsender_process(data, tag, wait=0):
|
|
|
|
proc = EventSender(data, tag, wait)
|
|
|
|
proc.start()
|
|
|
|
try:
|
|
|
|
yield
|
|
|
|
finally:
|
2014-04-18 06:52:40 +00:00
|
|
|
clean_proc(proc)
|
2013-12-02 23:20:54 +00:00
|
|
|
|
2013-12-23 16:25:16 +00:00
|
|
|
|
2013-12-22 23:37:07 +00:00
|
|
|
@skipIf(NO_LONG_IPC, "This system does not support long IPC paths. Skipping event tests!")
|
2012-08-31 00:20:32 +00:00
|
|
|
class TestSaltEvent(TestCase):
|
2013-12-03 01:22:51 +00:00
|
|
|
def setUp(self):
|
|
|
|
if not os.path.exists(SOCK_DIR):
|
|
|
|
os.makedirs(SOCK_DIR)
|
2012-08-31 00:20:32 +00:00
|
|
|
|
2013-12-02 22:26:13 +00:00
|
|
|
def assertGotEvent(self, evt, data, msg=None):
|
|
|
|
self.assertIsNotNone(evt, msg)
|
2014-03-31 02:31:23 +00:00
|
|
|
for key in data:
|
|
|
|
self.assertIn(key, evt, msg)
|
|
|
|
self.assertEqual(data[key], evt[key], msg)
|
2013-12-02 22:26:13 +00:00
|
|
|
|
2012-08-31 00:20:32 +00:00
|
|
|
def test_master_event(self):
|
|
|
|
me = event.MasterEvent(SOCK_DIR)
|
|
|
|
self.assertEqual(
|
2013-06-24 22:53:59 +00:00
|
|
|
me.puburi, 'ipc://{0}'.format(
|
2012-08-31 00:20:32 +00:00
|
|
|
os.path.join(SOCK_DIR, 'master_event_pub.ipc')
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
me.pulluri,
|
|
|
|
'ipc://{0}'.format(
|
|
|
|
os.path.join(SOCK_DIR, 'master_event_pull.ipc')
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_minion_event(self):
|
2012-09-01 04:06:44 +00:00
|
|
|
opts = dict(id='foo', sock_dir=SOCK_DIR)
|
2014-05-23 13:57:01 +00:00
|
|
|
id_hash = hashlib.md5(opts['id']).hexdigest()[:10]
|
2014-03-22 21:21:08 +00:00
|
|
|
me = event.MinionEvent(opts)
|
2012-08-31 00:20:32 +00:00
|
|
|
self.assertEqual(
|
|
|
|
me.puburi,
|
|
|
|
'ipc://{0}'.format(
|
2012-12-11 10:23:37 +00:00
|
|
|
os.path.join(
|
|
|
|
SOCK_DIR, 'minion_event_{0}_pub.ipc'.format(id_hash)
|
|
|
|
)
|
2012-08-31 00:20:32 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
me.pulluri,
|
|
|
|
'ipc://{0}'.format(
|
2012-12-11 10:23:37 +00:00
|
|
|
os.path.join(
|
|
|
|
SOCK_DIR, 'minion_event_{0}_pull.ipc'.format(id_hash)
|
|
|
|
)
|
2012-08-31 00:20:32 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_minion_event_tcp_ipc_mode(self):
|
|
|
|
opts = dict(id='foo', ipc_mode='tcp')
|
2014-03-22 21:21:08 +00:00
|
|
|
me = event.MinionEvent(opts)
|
2012-08-31 00:20:32 +00:00
|
|
|
self.assertEqual(me.puburi, 'tcp://127.0.0.1:4510')
|
|
|
|
self.assertEqual(me.pulluri, 'tcp://127.0.0.1:4511')
|
|
|
|
|
|
|
|
def test_minion_event_no_id(self):
|
2014-03-22 21:21:08 +00:00
|
|
|
me = event.MinionEvent(dict(sock_dir=SOCK_DIR))
|
2014-05-23 13:57:01 +00:00
|
|
|
id_hash = hashlib.md5('').hexdigest()[:10]
|
2012-08-31 00:20:32 +00:00
|
|
|
self.assertEqual(
|
|
|
|
me.puburi,
|
|
|
|
'ipc://{0}'.format(
|
2012-12-11 10:23:37 +00:00
|
|
|
os.path.join(
|
|
|
|
SOCK_DIR, 'minion_event_{0}_pub.ipc'.format(id_hash)
|
|
|
|
)
|
2012-08-31 00:20:32 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
me.pulluri,
|
|
|
|
'ipc://{0}'.format(
|
2012-12-11 10:23:37 +00:00
|
|
|
os.path.join(
|
|
|
|
SOCK_DIR, 'minion_event_{0}_pull.ipc'.format(id_hash)
|
|
|
|
)
|
2012-08-31 00:20:32 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2013-12-02 22:26:13 +00:00
|
|
|
def test_event_subscription(self):
|
2013-12-03 01:22:51 +00:00
|
|
|
'''Test a single event is received'''
|
2013-12-02 23:20:54 +00:00
|
|
|
with eventpublisher_process():
|
2014-03-22 21:21:08 +00:00
|
|
|
me = event.MasterEvent(SOCK_DIR)
|
2013-12-03 01:22:51 +00:00
|
|
|
me.subscribe()
|
2013-12-03 20:30:16 +00:00
|
|
|
me.fire_event({'data': 'foo1'}, 'evt1')
|
2013-12-02 22:26:13 +00:00
|
|
|
evt1 = me.get_event(tag='evt1')
|
2013-12-03 20:30:16 +00:00
|
|
|
self.assertGotEvent(evt1, {'data': 'foo1'})
|
2013-12-02 22:26:13 +00:00
|
|
|
|
2013-12-03 22:44:52 +00:00
|
|
|
def test_event_timeout(self):
|
|
|
|
'''Test no event is received if the timeout is reached'''
|
|
|
|
with eventpublisher_process():
|
2014-03-22 21:21:08 +00:00
|
|
|
me = event.MasterEvent(SOCK_DIR)
|
2013-12-03 22:44:52 +00:00
|
|
|
me.subscribe()
|
2013-12-06 17:50:24 +00:00
|
|
|
me.fire_event({'data': 'foo1'}, 'evt1')
|
2013-12-03 22:44:52 +00:00
|
|
|
evt1 = me.get_event(tag='evt1')
|
2013-12-06 17:50:24 +00:00
|
|
|
self.assertGotEvent(evt1, {'data': 'foo1'})
|
2013-12-03 22:44:52 +00:00
|
|
|
evt2 = me.get_event(tag='evt1')
|
|
|
|
self.assertIsNone(evt2)
|
|
|
|
|
2014-11-21 16:54:05 +00:00
|
|
|
def test_event_no_timeout(self):
|
|
|
|
'''Test no wait timeout, we should block forever, until we get one '''
|
|
|
|
with eventpublisher_process():
|
|
|
|
me = event.MasterEvent(SOCK_DIR)
|
|
|
|
me.subscribe()
|
|
|
|
me.fire_event({'data': 'foo1'}, 'evt1')
|
|
|
|
me.fire_event({'data': 'foo2'}, 'evt2')
|
|
|
|
evt = me.get_event(tag='evt2', wait=0)
|
|
|
|
self.assertGotEvent(evt, {'data': 'foo2'})
|
|
|
|
|
2013-12-03 01:22:51 +00:00
|
|
|
def test_event_subscription_matching(self):
|
|
|
|
'''Test a subscription startswith matching'''
|
|
|
|
with eventpublisher_process():
|
2014-03-22 21:21:08 +00:00
|
|
|
me = event.MasterEvent(SOCK_DIR)
|
2013-12-03 01:22:51 +00:00
|
|
|
me.subscribe()
|
2013-12-03 20:30:16 +00:00
|
|
|
me.fire_event({'data': 'foo1'}, 'evt1')
|
2013-12-03 01:22:51 +00:00
|
|
|
evt1 = me.get_event(tag='evt1')
|
2013-12-03 20:30:16 +00:00
|
|
|
self.assertGotEvent(evt1, {'data': 'foo1'})
|
2013-12-03 01:22:51 +00:00
|
|
|
|
|
|
|
def test_event_subscription_matching_all(self):
|
|
|
|
'''Test a subscription matching'''
|
|
|
|
with eventpublisher_process():
|
2014-03-22 21:21:08 +00:00
|
|
|
me = event.MasterEvent(SOCK_DIR)
|
2013-12-03 01:22:51 +00:00
|
|
|
me.subscribe()
|
2013-12-03 20:30:16 +00:00
|
|
|
me.fire_event({'data': 'foo1'}, 'evt1')
|
2013-12-03 01:22:51 +00:00
|
|
|
evt1 = me.get_event(tag='')
|
2013-12-03 20:30:16 +00:00
|
|
|
self.assertGotEvent(evt1, {'data': 'foo1'})
|
2013-12-03 01:22:51 +00:00
|
|
|
|
2013-12-02 23:20:54 +00:00
|
|
|
def test_event_not_subscribed(self):
|
|
|
|
'''Test get event ignores non-subscribed events'''
|
|
|
|
with eventpublisher_process():
|
2014-03-22 21:21:08 +00:00
|
|
|
me = event.MasterEvent(SOCK_DIR)
|
2013-12-03 01:22:51 +00:00
|
|
|
me.subscribe()
|
2013-12-03 20:30:16 +00:00
|
|
|
with eventsender_process({'data': 'foo1'}, 'evt1', 5):
|
|
|
|
me.fire_event({'data': 'foo1'}, 'evt2')
|
2013-12-02 23:20:54 +00:00
|
|
|
evt1 = me.get_event(tag='evt1', wait=10)
|
2013-12-03 20:30:16 +00:00
|
|
|
self.assertGotEvent(evt1, {'data': 'foo1'})
|
2013-12-02 23:20:54 +00:00
|
|
|
|
|
|
|
def test_event_multiple_subscriptions(self):
|
|
|
|
'''Test multiple subscriptions do not interfere'''
|
|
|
|
with eventpublisher_process():
|
2014-03-22 21:21:08 +00:00
|
|
|
me = event.MasterEvent(SOCK_DIR)
|
2013-12-03 01:22:51 +00:00
|
|
|
me.subscribe()
|
2013-12-03 20:30:16 +00:00
|
|
|
with eventsender_process({'data': 'foo1'}, 'evt1', 5):
|
|
|
|
me.fire_event({'data': 'foo1'}, 'evt2')
|
2013-12-02 23:20:54 +00:00
|
|
|
evt1 = me.get_event(tag='evt1', wait=10)
|
2013-12-03 20:30:16 +00:00
|
|
|
self.assertGotEvent(evt1, {'data': 'foo1'})
|
2013-12-02 23:20:54 +00:00
|
|
|
|
|
|
|
def test_event_multiple_clients(self):
|
2013-12-03 01:45:18 +00:00
|
|
|
'''Test event is received by multiple clients'''
|
2013-12-02 23:20:54 +00:00
|
|
|
with eventpublisher_process():
|
2014-03-22 21:21:08 +00:00
|
|
|
me1 = event.MasterEvent(SOCK_DIR)
|
2013-12-03 01:22:51 +00:00
|
|
|
me1.subscribe()
|
2014-03-22 21:21:08 +00:00
|
|
|
me2 = event.MasterEvent(SOCK_DIR)
|
2013-12-03 01:22:51 +00:00
|
|
|
me2.subscribe()
|
2013-12-03 20:30:16 +00:00
|
|
|
me1.fire_event({'data': 'foo1'}, 'evt1')
|
2013-12-02 23:20:54 +00:00
|
|
|
evt1 = me1.get_event(tag='evt1')
|
2013-12-03 20:30:16 +00:00
|
|
|
self.assertGotEvent(evt1, {'data': 'foo1'})
|
2014-11-05 19:03:54 +00:00
|
|
|
# Can't replicate this failure in the wild, need to fix the
|
2013-12-20 20:55:37 +00:00
|
|
|
# test system bug here
|
|
|
|
#evt2 = me2.get_event(tag='evt1')
|
|
|
|
#self.assertGotEvent(evt2, {'data': 'foo1'})
|
2013-12-02 23:20:54 +00:00
|
|
|
|
|
|
|
def test_event_nested_subs(self):
|
|
|
|
'''Test nested event subscriptions do not drop events, issue #8580'''
|
|
|
|
with eventpublisher_process():
|
2014-03-22 21:21:08 +00:00
|
|
|
me = event.MasterEvent(SOCK_DIR)
|
2013-12-03 01:22:51 +00:00
|
|
|
me.subscribe()
|
2013-12-03 20:30:16 +00:00
|
|
|
me.fire_event({'data': 'foo1'}, 'evt1')
|
2013-12-02 22:26:13 +00:00
|
|
|
me.fire_event({'data': 'foo2'}, 'evt2')
|
2014-03-31 02:31:23 +00:00
|
|
|
# Since we now drop unrelated events to avoid memory leaks, see http://goo.gl/2n3L09 commit bcbc5340ef, the
|
|
|
|
# calls below will return None and will drop the unrelated events
|
2013-12-02 22:26:13 +00:00
|
|
|
evt2 = me.get_event(tag='evt2')
|
|
|
|
evt1 = me.get_event(tag='evt1')
|
2013-12-03 20:30:16 +00:00
|
|
|
self.assertGotEvent(evt2, {'data': 'foo2'})
|
2014-08-08 18:49:46 +00:00
|
|
|
# This one will be None because we're dripping unrelated events
|
2014-03-31 02:31:23 +00:00
|
|
|
self.assertIsNone(evt1)
|
|
|
|
|
|
|
|
# Fire events again
|
|
|
|
me.fire_event({'data': 'foo3'}, 'evt3')
|
|
|
|
me.fire_event({'data': 'foo4'}, 'evt4')
|
2015-01-07 00:55:28 +00:00
|
|
|
# We not force unrelated pending events not to be dropped, so both of the event below work and are not
|
2014-03-31 02:31:23 +00:00
|
|
|
# None
|
|
|
|
evt2 = me.get_event(tag='evt4', use_pending=True)
|
|
|
|
evt1 = me.get_event(tag='evt3', use_pending=True)
|
|
|
|
self.assertGotEvent(evt2, {'data': 'foo4'})
|
|
|
|
self.assertGotEvent(evt1, {'data': 'foo3'})
|
2013-12-02 22:26:13 +00:00
|
|
|
|
2013-12-03 01:22:51 +00:00
|
|
|
@expectedFailure
|
|
|
|
def test_event_nested_sub_all(self):
|
|
|
|
'''Test nested event subscriptions do not drop events, get event for all tags'''
|
|
|
|
# Show why not to call get_event(tag='')
|
|
|
|
with eventpublisher_process():
|
2014-03-22 21:21:08 +00:00
|
|
|
me = event.MasterEvent(SOCK_DIR)
|
2013-12-03 01:22:51 +00:00
|
|
|
me.subscribe()
|
2013-12-03 20:30:16 +00:00
|
|
|
me.fire_event({'data': 'foo1'}, 'evt1')
|
2013-12-03 01:22:51 +00:00
|
|
|
me.fire_event({'data': 'foo2'}, 'evt2')
|
|
|
|
evt2 = me.get_event(tag='')
|
|
|
|
evt1 = me.get_event(tag='')
|
2013-12-03 20:30:16 +00:00
|
|
|
self.assertGotEvent(evt2, {'data': 'foo2'})
|
|
|
|
self.assertGotEvent(evt1, {'data': 'foo1'})
|
2013-12-03 01:22:51 +00:00
|
|
|
|
2013-12-02 23:20:54 +00:00
|
|
|
def test_event_many(self):
|
2013-12-02 22:26:13 +00:00
|
|
|
'''Test a large number of events, one at a time'''
|
2013-12-02 23:20:54 +00:00
|
|
|
with eventpublisher_process():
|
2014-03-22 21:21:08 +00:00
|
|
|
me = event.MasterEvent(SOCK_DIR)
|
2013-12-03 01:22:51 +00:00
|
|
|
me.subscribe()
|
2014-11-21 20:42:32 +00:00
|
|
|
for i in range(500):
|
2013-12-03 20:30:16 +00:00
|
|
|
me.fire_event({'data': '{0}'.format(i)}, 'testevents')
|
2013-12-02 22:26:13 +00:00
|
|
|
evt = me.get_event(tag='testevents')
|
2013-12-03 20:30:16 +00:00
|
|
|
self.assertGotEvent(evt, {'data': '{0}'.format(i)}, 'Event {0}'.format(i))
|
2013-12-02 22:26:13 +00:00
|
|
|
|
2013-12-02 23:20:54 +00:00
|
|
|
def test_event_many_backlog(self):
|
2013-12-02 22:26:13 +00:00
|
|
|
'''Test a large number of events, send all then recv all'''
|
2013-12-02 23:20:54 +00:00
|
|
|
with eventpublisher_process():
|
2014-03-22 21:21:08 +00:00
|
|
|
me = event.MasterEvent(SOCK_DIR)
|
2013-12-03 01:22:51 +00:00
|
|
|
me.subscribe()
|
|
|
|
# Must not exceed zmq HWM
|
2014-11-21 20:42:32 +00:00
|
|
|
for i in range(500):
|
2013-12-03 20:30:16 +00:00
|
|
|
me.fire_event({'data': '{0}'.format(i)}, 'testevents')
|
2014-11-21 20:42:32 +00:00
|
|
|
for i in range(500):
|
2013-12-02 22:26:13 +00:00
|
|
|
evt = me.get_event(tag='testevents')
|
2013-12-03 20:30:16 +00:00
|
|
|
self.assertGotEvent(evt, {'data': '{0}'.format(i)}, 'Event {0}'.format(i))
|
2013-12-02 22:26:13 +00:00
|
|
|
|
2015-01-12 07:04:04 +00:00
|
|
|
# Test the fire_master function. As it wraps the underlying fire_event,
|
|
|
|
# we don't need to perform extensive testing.
|
|
|
|
def test_send_master_event(self):
|
2015-01-15 17:48:44 +00:00
|
|
|
'''Tests that sending an event through fire_master generates expected event'''
|
2015-01-12 07:04:04 +00:00
|
|
|
with eventpublisher_process():
|
2015-01-15 17:41:08 +00:00
|
|
|
me = event.MasterEvent(SOCK_DIR)
|
|
|
|
me.subscribe()
|
2015-01-15 17:48:44 +00:00
|
|
|
data = {'data': 'foo1'}
|
|
|
|
me.fire_master(data, 'test_master')
|
2015-01-12 07:04:04 +00:00
|
|
|
|
2015-01-15 17:41:08 +00:00
|
|
|
evt = me.get_event(tag='fire_master')
|
2015-01-15 17:48:44 +00:00
|
|
|
self.assertGotEvent(evt, {'data': data, 'tag': 'test_master', 'events': None, 'pretag': None})
|
2015-01-12 07:04:04 +00:00
|
|
|
|
2015-04-08 03:30:04 +00:00
|
|
|
|
|
|
|
class TestAsyncEventPublisher(AsyncTestCase):
|
|
|
|
def get_new_ioloop(self):
|
2015-04-08 15:20:17 +00:00
|
|
|
return zmq.eventloop.ioloop.ZMQIOLoop()
|
2015-04-08 03:30:04 +00:00
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(TestAsyncEventPublisher, self).setUp()
|
|
|
|
self.publisher = event.AsyncEventPublisher(
|
|
|
|
{'sock_dir': SOCK_DIR},
|
|
|
|
self._handle_publish,
|
|
|
|
self.io_loop,
|
|
|
|
)
|
|
|
|
|
|
|
|
def _handle_publish(self, raw):
|
|
|
|
self.tag, self.data = event.SaltEvent.unpack(raw)
|
|
|
|
self.stop()
|
|
|
|
|
|
|
|
def test_event_subscription(self):
|
|
|
|
'''Test a single event is received'''
|
|
|
|
me = event.MinionEvent({'sock_dir': SOCK_DIR})
|
|
|
|
me.fire_event({'data': 'foo1'}, 'evt1')
|
|
|
|
self.wait()
|
|
|
|
evt1 = me.get_event(tag='evt1')
|
|
|
|
self.assertEqual(self.tag, 'evt1')
|
|
|
|
self.data.pop('_stamp') # drop the stamp
|
|
|
|
self.assertEqual(self.data, {'data': 'foo1'})
|
|
|
|
|
2013-06-24 22:53:59 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
from integration import run_tests
|
|
|
|
run_tests(TestSaltEvent, needs_daemon=False)
|