2012-08-31 00:20:32 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
|
|
|
tests.unit.utils.event_test
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
2012-12-11 10:23:37 +00:00
|
|
|
:codeauthor: :email:`Pedro Algarvio (pedro@algarvio.me)`
|
|
|
|
:copyright: © 2012 by the SaltStack Team, see AUTHORS for more details.
|
2012-08-31 00:20:32 +00:00
|
|
|
:license: Apache 2.0, see LICENSE for more details.
|
|
|
|
'''
|
|
|
|
|
2012-12-11 10:23:37 +00:00
|
|
|
# Import python libs
|
2012-08-31 00:20:32 +00:00
|
|
|
import os
|
2012-09-19 20:21:56 +00:00
|
|
|
import hashlib
|
2012-08-31 00:20:32 +00:00
|
|
|
|
2012-12-11 10:23:37 +00:00
|
|
|
# Import salt libs
|
2013-06-24 22:53:59 +00:00
|
|
|
try:
|
|
|
|
import integration
|
|
|
|
except ImportError:
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys
|
|
|
|
sys.path.insert(
|
|
|
|
0, os.path.abspath(
|
|
|
|
os.path.join(
|
|
|
|
os.path.dirname(__file__), '../../'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
import integration
|
2012-08-31 00:20:32 +00:00
|
|
|
from salt.utils import event
|
|
|
|
|
2013-06-24 22:53:59 +00:00
|
|
|
# Import Salt Testing libs
|
|
|
|
from salttesting import TestCase
|
|
|
|
|
2012-08-31 00:20:32 +00:00
|
|
|
SOCK_DIR = os.path.join(integration.TMP, 'test-socks')
|
|
|
|
|
2012-12-11 10:23:37 +00:00
|
|
|
|
2012-08-31 00:20:32 +00:00
|
|
|
class TestSaltEvent(TestCase):
|
|
|
|
|
|
|
|
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)
|
2012-09-19 20:21:56 +00:00
|
|
|
id_hash = hashlib.md5(opts['id']).hexdigest()
|
2012-09-01 04:06:44 +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')
|
2012-09-01 04:06:44 +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):
|
2012-09-01 04:06:44 +00:00
|
|
|
me = event.MinionEvent(sock_dir=SOCK_DIR)
|
2012-09-19 20:39:01 +00:00
|
|
|
id_hash = hashlib.md5('').hexdigest()
|
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-06-24 22:53:59 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
from integration import run_tests
|
|
|
|
run_tests(TestSaltEvent, needs_daemon=False)
|