salt/tests/integration/modules/publish.py

115 lines
3.0 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
# Import Python libs
2014-11-22 11:05:56 +00:00
from __future__ import absolute_import, print_function
# Import Salt Testing libs
from salttesting.helpers import ensure_in_syspath
ensure_in_syspath('../../')
# Import salt libs
import integration
2012-03-29 00:37:05 +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'])
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:
if name not in ret:
2014-11-22 11:05:56 +00:00
print(name)
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(
'publish.full_data',
2014-06-12 19:35:36 +00:00
['minion', 'test.fib', 40]
)
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)
def test_kwarg(self):
'''
Verify that the pub data is making it to the minion functions
'''
ret = self.run_function(
'publish.full_data',
['minion', 'test.kwarg', 'arg="cheese=spam"']
)
ret = ret['minion']['ret']
check_true = (
'cheese',
'__pub_arg',
'__pub_fun',
'__pub_id',
'__pub_jid',
'__pub_ret',
'__pub_tgt',
'__pub_tgt_type',
)
for name in check_true:
if name not in ret:
2014-11-22 11:05:56 +00:00
print(name)
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')
self.assertEqual(ret['__pub_fun'], 'test.kwarg')
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
)
2012-03-29 00:47:10 +00:00
def test_reject_minion(self):
'''
Test bad authentication
'''
ret = self.run_function(
'publish.publish',
['minion', 'cmd.run', ['echo foo']]
)
2012-03-29 00:47:10 +00:00
self.assertEqual(ret, {})
if __name__ == '__main__':
from integration import run_tests
run_tests(PublishModuleTest)