2013-11-27 11:19:24 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2014-11-21 19:05:13 +00:00
|
|
|
# Import Python libs
|
2014-11-22 11:05:56 +00:00
|
|
|
from __future__ import absolute_import, print_function
|
2014-11-21 19:05:13 +00:00
|
|
|
|
2013-06-27 11:36:37 +00:00
|
|
|
# Import Salt Testing libs
|
|
|
|
from salttesting.helpers import ensure_in_syspath
|
|
|
|
ensure_in_syspath('../../')
|
|
|
|
|
|
|
|
# Import salt libs
|
|
|
|
import integration
|
2012-05-05 14:09:23 +00:00
|
|
|
|
2012-03-29 00:37:05 +00:00
|
|
|
|
2013-04-25 19:58:54 +00:00
|
|
|
class PublishModuleTest(integration.ModuleCase,
|
|
|
|
integration.SaltReturnAssertsMixIn):
|
2012-03-29 00:37:05 +00:00
|
|
|
'''
|
|
|
|
Validate the publish module
|
|
|
|
'''
|
|
|
|
def test_publish(self):
|
|
|
|
'''
|
|
|
|
publish.publish
|
|
|
|
'''
|
|
|
|
ret = self.run_function('publish.publish', ['minion', 'test.ping'])
|
2013-11-10 11:40:01 +00:00
|
|
|
self.assertEqual(ret, {'minion': True})
|
|
|
|
|
|
|
|
ret = self.run_function(
|
|
|
|
'publish.publish',
|
|
|
|
['minion', 'test.kwarg', 'arg="cheese=spam"']
|
|
|
|
)
|
|
|
|
ret = ret['minion']
|
|
|
|
|
|
|
|
check_true = (
|
|
|
|
'cheese',
|
|
|
|
'__pub_arg',
|
|
|
|
'__pub_fun',
|
|
|
|
'__pub_id',
|
|
|
|
'__pub_jid',
|
|
|
|
'__pub_ret',
|
|
|
|
'__pub_tgt',
|
|
|
|
'__pub_tgt_type',
|
|
|
|
)
|
|
|
|
for name in check_true:
|
2014-06-06 10:27:01 +00:00
|
|
|
if name not in ret:
|
2014-11-22 11:05:56 +00:00
|
|
|
print(name)
|
2013-11-10 11:40:01 +00:00
|
|
|
self.assertTrue(name in ret)
|
|
|
|
|
|
|
|
self.assertEqual(ret['cheese'], 'spam')
|
|
|
|
self.assertEqual(ret['__pub_arg'], ['cheese=spam'])
|
|
|
|
self.assertEqual(ret['__pub_id'], 'minion')
|
|
|
|
self.assertEqual(ret['__pub_fun'], 'test.kwarg')
|
2012-03-29 00:37:05 +00:00
|
|
|
|
|
|
|
def test_full_data(self):
|
|
|
|
'''
|
|
|
|
publish.full_data
|
|
|
|
'''
|
|
|
|
ret = self.run_function(
|
2013-04-25 19:58:54 +00:00
|
|
|
'publish.full_data',
|
2014-06-12 19:35:36 +00:00
|
|
|
['minion', 'test.fib', 40]
|
2013-04-25 19:58:54 +00:00
|
|
|
)
|
2013-04-27 18:59:34 +00:00
|
|
|
self.assertTrue(ret)
|
2012-03-29 00:37:05 +00:00
|
|
|
self.assertEqual(ret['minion']['ret'][0][-1], 34)
|
2012-05-05 14:09:23 +00:00
|
|
|
|
2012-04-01 19:29:23 +00:00
|
|
|
def test_kwarg(self):
|
|
|
|
'''
|
|
|
|
Verify that the pub data is making it to the minion functions
|
|
|
|
'''
|
|
|
|
ret = self.run_function(
|
2013-04-25 19:58:54 +00:00
|
|
|
'publish.full_data',
|
2013-11-10 11:40:01 +00:00
|
|
|
['minion', 'test.kwarg', 'arg="cheese=spam"']
|
2013-04-25 19:58:54 +00:00
|
|
|
)
|
|
|
|
ret = ret['minion']['ret']
|
|
|
|
|
2012-05-10 04:42:38 +00:00
|
|
|
check_true = (
|
|
|
|
'cheese',
|
|
|
|
'__pub_arg',
|
|
|
|
'__pub_fun',
|
|
|
|
'__pub_id',
|
|
|
|
'__pub_jid',
|
|
|
|
'__pub_ret',
|
|
|
|
'__pub_tgt',
|
|
|
|
'__pub_tgt_type',
|
|
|
|
)
|
|
|
|
for name in check_true:
|
2014-06-06 10:27:01 +00:00
|
|
|
if name not in ret:
|
2014-11-22 11:05:56 +00:00
|
|
|
print(name)
|
2012-05-10 04:42:38 +00:00
|
|
|
self.assertTrue(name in ret)
|
|
|
|
|
2012-05-29 16:40:20 +00:00
|
|
|
self.assertEqual(ret['cheese'], 'spam')
|
2012-07-23 19:00:54 +00:00
|
|
|
self.assertEqual(ret['__pub_arg'], ['cheese=spam'])
|
2012-05-29 16:40:20 +00:00
|
|
|
self.assertEqual(ret['__pub_id'], 'minion')
|
2012-04-01 19:29:23 +00:00
|
|
|
self.assertEqual(ret['__pub_fun'], 'test.kwarg')
|
|
|
|
|
2013-11-10 11:40:01 +00:00
|
|
|
ret = self.run_function(
|
|
|
|
'publish.full_data',
|
|
|
|
['minion', 'test.kwarg', 'cheese=spam']
|
|
|
|
)
|
|
|
|
self.assertIn(
|
2014-07-01 21:13:52 +00:00
|
|
|
'The following keyword arguments are not valid', ret
|
2013-11-10 11:40:01 +00:00
|
|
|
)
|
|
|
|
|
2012-03-29 00:47:10 +00:00
|
|
|
def test_reject_minion(self):
|
|
|
|
'''
|
|
|
|
Test bad authentication
|
|
|
|
'''
|
|
|
|
ret = self.run_function(
|
2013-04-25 19:58:54 +00:00
|
|
|
'publish.publish',
|
|
|
|
['minion', 'cmd.run', ['echo foo']]
|
|
|
|
)
|
2012-03-29 00:47:10 +00:00
|
|
|
self.assertEqual(ret, {})
|
2012-05-05 14:09:23 +00:00
|
|
|
|
2012-07-20 06:21:01 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
from integration import run_tests
|
|
|
|
run_tests(PublishModuleTest)
|