2013-11-27 11:19:24 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2013-05-26 13:18:12 +00:00
|
|
|
'''
|
|
|
|
Test the salt mine system
|
|
|
|
'''
|
2016-07-13 20:51:28 +00:00
|
|
|
# Import Python libs
|
2014-11-21 19:05:13 +00:00
|
|
|
from __future__ import absolute_import
|
2016-07-13 20:51:28 +00:00
|
|
|
import time
|
2014-11-21 19:05:13 +00:00
|
|
|
|
2013-06-27 11:11:20 +00:00
|
|
|
# Import Salt Testing libs
|
2017-04-03 16:04:09 +00:00
|
|
|
from tests.support.case import ModuleCase
|
2013-06-25 08:24:45 +00:00
|
|
|
|
2013-05-26 13:18:12 +00:00
|
|
|
|
2017-04-03 16:04:09 +00:00
|
|
|
class MineTest(ModuleCase):
|
2013-05-26 13:18:12 +00:00
|
|
|
'''
|
|
|
|
Test the mine system
|
|
|
|
'''
|
|
|
|
def test_get(self):
|
|
|
|
'''
|
2013-05-26 14:55:18 +00:00
|
|
|
test mine.get and mine.update
|
2013-05-26 13:18:12 +00:00
|
|
|
'''
|
2013-05-29 20:28:37 +00:00
|
|
|
self.assertTrue(self.run_function('mine.update', minion_tgt='minion'))
|
|
|
|
self.assertTrue(
|
2013-09-18 21:22:46 +00:00
|
|
|
self.run_function(
|
|
|
|
'mine.update',
|
|
|
|
minion_tgt='sub_minion'
|
|
|
|
)
|
|
|
|
)
|
2013-05-29 20:28:37 +00:00
|
|
|
self.assertTrue(
|
2013-09-18 21:22:46 +00:00
|
|
|
self.run_function(
|
|
|
|
'mine.get',
|
|
|
|
['minion', 'test.ping']
|
|
|
|
)
|
|
|
|
)
|
2013-05-26 14:55:18 +00:00
|
|
|
|
|
|
|
def test_send(self):
|
|
|
|
'''
|
|
|
|
test mine.send
|
|
|
|
'''
|
2013-05-29 20:28:37 +00:00
|
|
|
self.assertFalse(
|
2013-09-18 21:22:46 +00:00
|
|
|
self.run_function(
|
|
|
|
'mine.send',
|
|
|
|
['foo.__spam_and_cheese']
|
|
|
|
)
|
|
|
|
)
|
2013-05-29 20:28:37 +00:00
|
|
|
self.assertTrue(
|
2013-09-18 21:22:46 +00:00
|
|
|
self.run_function(
|
|
|
|
'mine.send',
|
|
|
|
['grains.items'],
|
|
|
|
minion_tgt='minion',
|
|
|
|
)
|
|
|
|
)
|
2013-05-29 20:28:37 +00:00
|
|
|
self.assertTrue(
|
2013-09-18 21:22:46 +00:00
|
|
|
self.run_function(
|
|
|
|
'mine.send',
|
|
|
|
['grains.items'],
|
|
|
|
minion_tgt='sub_minion',
|
|
|
|
)
|
|
|
|
)
|
2013-05-29 20:28:37 +00:00
|
|
|
ret = self.run_function(
|
2013-09-18 21:22:46 +00:00
|
|
|
'mine.get',
|
|
|
|
['sub_minion', 'grains.items']
|
|
|
|
)
|
2013-05-29 20:28:37 +00:00
|
|
|
self.assertEqual(ret['sub_minion']['id'], 'sub_minion')
|
|
|
|
ret = self.run_function(
|
2013-09-18 21:22:46 +00:00
|
|
|
'mine.get',
|
|
|
|
['minion', 'grains.items'],
|
|
|
|
minion_tgt='sub_minion'
|
|
|
|
)
|
2013-05-29 20:28:37 +00:00
|
|
|
self.assertEqual(ret['minion']['id'], 'minion')
|
2013-06-25 08:24:45 +00:00
|
|
|
|
2013-09-18 20:49:12 +00:00
|
|
|
def test_mine_flush(self):
|
|
|
|
'''
|
|
|
|
Test mine.flush
|
|
|
|
'''
|
|
|
|
for minion_id in ('minion', 'sub_minion'):
|
|
|
|
self.assertTrue(
|
|
|
|
self.run_function(
|
|
|
|
'mine.send',
|
|
|
|
['grains.items'],
|
|
|
|
minion_tgt=minion_id
|
|
|
|
)
|
|
|
|
)
|
2016-07-13 20:51:28 +00:00
|
|
|
time.sleep(1)
|
|
|
|
for minion_id in ('minion', 'sub_minion'):
|
2013-09-18 20:49:12 +00:00
|
|
|
ret = self.run_function(
|
|
|
|
'mine.get',
|
|
|
|
[minion_id, 'grains.items'],
|
|
|
|
minion_tgt=minion_id
|
|
|
|
)
|
|
|
|
self.assertEqual(ret[minion_id]['id'], minion_id)
|
|
|
|
self.assertTrue(
|
|
|
|
self.run_function(
|
|
|
|
'mine.flush',
|
|
|
|
minion_tgt='minion'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
ret_flushed = self.run_function(
|
|
|
|
'mine.get',
|
|
|
|
['*', 'grains.items']
|
|
|
|
)
|
|
|
|
self.assertEqual(ret_flushed.get('minion', None), None)
|
|
|
|
self.assertEqual(ret_flushed['sub_minion']['id'], 'sub_minion')
|
2013-06-25 08:24:45 +00:00
|
|
|
|
2013-09-18 21:07:04 +00:00
|
|
|
def test_mine_delete(self):
|
|
|
|
'''
|
|
|
|
Test mine.delete
|
|
|
|
'''
|
|
|
|
self.assertTrue(
|
|
|
|
self.run_function(
|
|
|
|
'mine.send',
|
|
|
|
['grains.items']
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self.assertTrue(
|
|
|
|
self.run_function(
|
|
|
|
'mine.send',
|
|
|
|
['test.echo', 'foo']
|
|
|
|
)
|
|
|
|
)
|
|
|
|
ret_grains = self.run_function(
|
|
|
|
'mine.get',
|
|
|
|
['minion', 'grains.items']
|
|
|
|
)
|
|
|
|
self.assertEqual(ret_grains['minion']['id'], 'minion')
|
|
|
|
ret_echo = self.run_function(
|
|
|
|
'mine.get',
|
|
|
|
['minion', 'test.echo']
|
|
|
|
)
|
|
|
|
self.assertEqual(ret_echo['minion'], 'foo')
|
|
|
|
self.assertTrue(
|
|
|
|
self.run_function(
|
|
|
|
'mine.delete',
|
|
|
|
['grains.items']
|
|
|
|
)
|
|
|
|
)
|
|
|
|
ret_grains_deleted = self.run_function(
|
|
|
|
'mine.get',
|
|
|
|
['minion', 'grains.items']
|
|
|
|
)
|
|
|
|
self.assertEqual(ret_grains_deleted.get('minion', None), None)
|
|
|
|
ret_echo_stays = self.run_function(
|
|
|
|
'mine.get',
|
|
|
|
['minion', 'test.echo']
|
|
|
|
)
|
|
|
|
self.assertEqual(ret_echo_stays['minion'], 'foo')
|