2015-11-18 22:46:27 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
|
|
|
unit tests for the cache runner
|
|
|
|
'''
|
|
|
|
|
|
|
|
# Import Python Libs
|
2017-12-15 01:21:00 +00:00
|
|
|
from __future__ import absolute_import, print_function, unicode_literals
|
2015-11-18 22:46:27 +00:00
|
|
|
|
|
|
|
# Import Salt Testing Libs
|
2017-02-19 15:35:30 +00:00
|
|
|
from tests.support.mixins import LoaderModuleMockMixin
|
|
|
|
from tests.support.paths import TMP
|
2017-02-27 13:58:07 +00:00
|
|
|
from tests.support.unit import skipIf, TestCase
|
|
|
|
from tests.support.mock import (
|
2015-11-18 22:46:27 +00:00
|
|
|
NO_MOCK,
|
|
|
|
NO_MOCK_REASON,
|
|
|
|
patch
|
|
|
|
)
|
|
|
|
|
|
|
|
# Import Salt Libs
|
2017-03-21 17:15:36 +00:00
|
|
|
import salt.runners.cache as cache
|
2017-10-14 01:52:56 +00:00
|
|
|
import salt.utils.master
|
2015-11-18 22:46:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
2017-02-19 15:35:30 +00:00
|
|
|
class CacheTest(TestCase, LoaderModuleMockMixin):
|
2015-11-18 22:46:27 +00:00
|
|
|
'''
|
|
|
|
Validate the cache runner
|
|
|
|
'''
|
2017-03-22 12:12:36 +00:00
|
|
|
def setup_loader_modules(self):
|
|
|
|
return {cache: {'__opts__': {'cache': 'localfs', 'pki_dir': TMP, 'key_cache': True}}}
|
2017-02-19 15:35:30 +00:00
|
|
|
|
2015-11-18 22:46:27 +00:00
|
|
|
def test_grains(self):
|
|
|
|
'''
|
|
|
|
test cache.grains runner
|
|
|
|
'''
|
|
|
|
mock_minion = ['Larry']
|
|
|
|
mock_ret = {}
|
|
|
|
self.assertEqual(cache.grains(minion=mock_minion), mock_ret)
|
|
|
|
|
|
|
|
mock_data = 'grain stuff'
|
|
|
|
|
|
|
|
class MockMaster(object):
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def get_minion_grains(self):
|
|
|
|
return mock_data
|
|
|
|
|
|
|
|
with patch.object(salt.utils.master, 'MasterPillarUtil', MockMaster):
|
2016-02-10 17:22:08 +00:00
|
|
|
self.assertEqual(cache.grains(), mock_data)
|