MCPcopy Create free account
hub / github.com/saltstack/salt / test_compile_pillar_disk_cache

Function test_compile_pillar_disk_cache

tests/pytests/unit/test_pillar.py:1371–1420  ·  view source on GitHub ↗
(master_opts, grains)

Source from the content-addressed store, hash-verified

1369
1370
1371def test_compile_pillar_disk_cache(master_opts, grains):
1372 master_opts.update({"pillar_cache_ttl": 3600, "pillar_cache": True})
1373
1374 pillar = salt.pillar.PillarCache(
1375 master_opts,
1376 grains,
1377 "mocked_minion",
1378 "fake_env",
1379 pillarenv="base",
1380 )
1381 with patch(
1382 "salt.pillar.Pillar.compile_pillar",
1383 side_effect=[{"foo": "bar"}, {"foo": "baz"}],
1384 ), patch.object(
1385 pillar.cache, "fetch", side_effect=[None, {"foo": "bar"}, None, {"foo": "baz"}]
1386 ) as fetch_mock, patch.object(
1387 pillar.cache, "store"
1388 ) as store_mock:
1389 # Run once for pillarenv base
1390 pillar.compile_pillar()
1391
1392 # Run a second time for pillarenv base
1393 pillar.compile_pillar()
1394
1395 # Change the pillarenv
1396 pillar.opts["pillarenv"] = "dev"
1397
1398 # Run once for pillarenv dev
1399 pillar.compile_pillar()
1400
1401 # Run a second time for pillarenv dev
1402 pillar.compile_pillar()
1403
1404 expected_fetches = [
1405 call("pillar", "mocked_minion:base"),
1406 call("pillar", "mocked_minion:base"),
1407 call("pillar", "mocked_minion:dev"),
1408 call("pillar", "mocked_minion:dev"),
1409 ]
1410
1411 # Assert all calls match the pattern
1412 fetch_mock.assert_has_calls(expected_fetches, any_order=False)
1413
1414 expected_stores = [
1415 call("pillar", "mocked_minion:base", {"foo": "bar"}),
1416 call("pillar", "mocked_minion:dev", {"foo": "baz"}),
1417 ]
1418
1419 # Assert all calls match the pattern
1420 store_mock.assert_has_calls(expected_stores, any_order=False)
1421
1422
1423def test_remote_pillar_bad_return(grains, tmp_pki):

Callers

nothing calls this directly

Calls 4

compile_pillarMethod · 0.95
patchFunction · 0.50
callFunction · 0.50
updateMethod · 0.45

Tested by

no test coverage detected