"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "tests/unit/test_pillar.py" between
salt-3002.1.tar.gz and salt-3002.2.tar.gz

About: SaltStack is a systems management software for data center automation, cloud orchestration, server provisioning, configuration management and more. Community version.

test_pillar.py  (salt-3002.1):test_pillar.py  (salt-3002.2)
""" """
:codeauthor: Pedro Algarvio (pedro@algarvio.me) :codeauthor: Pedro Algarvio (pedro@algarvio.me)
:codeauthor: Alexandru Bleotu (alexandru.bleotu@morganstanley.com) :codeauthor: Alexandru Bleotu (alexandru.bleotu@morganstanley.com)
tests.unit.pillar_test tests.unit.pillar_test
~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~
""" """
# Import python libs
import logging import logging
import os import os
import shutil import shutil
import tempfile import tempfile
import textwrap import textwrap
# Import salt libs
import salt.config import salt.config
import salt.exceptions import salt.exceptions
import salt.fileclient import salt.fileclient
import salt.utils.stringutils import salt.utils.stringutils
from salt.utils.files import fopen from salt.utils.files import fopen
from tests.support.helpers import with_tempdir from tests.support.helpers import with_tempdir
from tests.support.mock import MagicMock, patch from tests.support.mock import MagicMock, patch
# Import Salt Testing libs
from tests.support.runtests import RUNTIME_VARS from tests.support.runtests import RUNTIME_VARS
from tests.support.unit import TestCase from tests.support.unit import TestCase
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
class MockFileclient: class MockFileclient:
def __init__(self, cache_file=None, get_state=None, list_states=None): def __init__(self, cache_file=None, get_state=None, list_states=None):
if cache_file is not None: if cache_file is not None:
self.cache_file = lambda *x, **y: cache_file self.cache_file = lambda *x, **y: cache_file
if get_state is not None: if get_state is not None:
skipping to change at line 1330 skipping to change at line 1325
dir=RUNTIME_VARS.TMP dir=RUNTIME_VARS.TMP
) )
def tearDown(self): def tearDown(self):
for attr in ("grains",): for attr in ("grains",):
try: try:
delattr(self, attr) delattr(self, attr)
except AttributeError: except AttributeError:
continue continue
def test_compile_pillar(self): def test_compile_pillar_disk_cache(self):
self.mock_master_default_opts.update( self.mock_master_default_opts.update(
{"pillar_cache_backend": "disk", "pillar_cache_ttl": 3600} {"pillar_cache_backend": "disk", "pillar_cache_ttl": 3600}
) )
pillar = salt.pillar.PillarCache( pillar = salt.pillar.PillarCache(
self.mock_master_default_opts, self.mock_master_default_opts,
self.grains, self.grains,
"mocked_minion", "mocked_minion",
"fake_env", "fake_env",
pillarenv="base", pillarenv="base",
skipping to change at line 1374 skipping to change at line 1369
"mocked_minion": {"base": {"foo": "bar"}, "dev": {"foo": "ba z"}} "mocked_minion": {"base": {"foo": "bar"}, "dev": {"foo": "ba z"}}
} }
self.assertEqual(pillar.cache._dict, expected_cache) self.assertEqual(pillar.cache._dict, expected_cache)
# Run a second time for pillarenv dev # Run a second time for pillarenv dev
ret = pillar.compile_pillar() ret = pillar.compile_pillar()
expected_cache = { expected_cache = {
"mocked_minion": {"base": {"foo": "bar"}, "dev": {"foo": "ba z"}} "mocked_minion": {"base": {"foo": "bar"}, "dev": {"foo": "ba z"}}
} }
self.assertEqual(pillar.cache._dict, expected_cache) self.assertEqual(pillar.cache._dict, expected_cache)
def test_compile_pillar_memory_cache(self):
self.mock_master_default_opts.update(
{"pillar_cache_backend": "memory", "pillar_cache_ttl": 3600}
)
pillar = salt.pillar.PillarCache(
self.mock_master_default_opts,
self.grains,
"mocked_minion",
"fake_env",
pillarenv="base",
)
with patch(
"salt.pillar.PillarCache.fetch_pillar",
side_effect=[{"foo": "bar"}, {"foo": "baz"}],
):
# Run once for pillarenv base
ret = pillar.compile_pillar()
expected_cache = {"base": {"foo": "bar"}}
self.assertIn("mocked_minion", pillar.cache)
self.assertEqual(pillar.cache["mocked_minion"], expected_cache)
# Run a second time for pillarenv base
ret = pillar.compile_pillar()
expected_cache = {"base": {"foo": "bar"}}
self.assertIn("mocked_minion", pillar.cache)
self.assertEqual(pillar.cache["mocked_minion"], expected_cache)
# Change the pillarenv
pillar.pillarenv = "dev"
# Run once for pillarenv dev
ret = pillar.compile_pillar()
expected_cache = {"base": {"foo": "bar"}, "dev": {"foo": "baz"}}
self.assertIn("mocked_minion", pillar.cache)
self.assertEqual(pillar.cache["mocked_minion"], expected_cache)
# Run a second time for pillarenv dev
ret = pillar.compile_pillar()
expected_cache = {"base": {"foo": "bar"}, "dev": {"foo": "baz"}}
self.assertIn("mocked_minion", pillar.cache)
self.assertEqual(pillar.cache["mocked_minion"], expected_cache)
 End of changes. 5 change blocks. 
6 lines changed or deleted 1 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)