diff --git a/tests/pytests/integration/runners/test_saltutil.py b/tests/pytests/integration/runners/test_saltutil.py index 22ae12285ac2..edc81f24f1b8 100644 --- a/tests/pytests/integration/runners/test_saltutil.py +++ b/tests/pytests/integration/runners/test_saltutil.py @@ -98,6 +98,36 @@ def world(): assert "{}.hello".format(module_type) in ret.stdout +def test_sync_refresh_false( + module_type, module_sync_functions, salt_run_cli, salt_minion, salt_master +): + """ + Ensure modules are synced when various sync functions are called + """ + module_name = "hello_sync_{}".format(module_type) + module_contents = """ +def __virtual__(): + return "hello" + +def world(): + return "world" +""" + + test_moduledir = salt_master.state_tree.base.write_path / "_{}".format(module_type) + test_moduledir.mkdir(parents=True, exist_ok=True) + module_tempfile = salt_master.state_tree.base.temp_file( + "_{}/{}.py".format(module_type, module_name), module_contents + ) + + with module_tempfile: + salt_cmd = "saltutil.sync_{}".format(module_sync_functions[module_type]) + ret = salt_run_cli.run(salt_cmd, saltenv=None, refresh=False) + assert ret.returncode == 0 + assert ( + "saltutil.sync_{}".format(module_sync_functions[module_type]) in ret.stdout + ) + + def _write_module_dir_and_file(module_type, salt_minion, salt_master): """ Write out dummy module to appropriate module location diff --git a/tests/pytests/unit/modules/test_saltutil.py b/tests/pytests/unit/modules/test_saltutil.py index 97527d3dc241..a25877b6d244 100644 --- a/tests/pytests/unit/modules/test_saltutil.py +++ b/tests/pytests/unit/modules/test_saltutil.py @@ -8,7 +8,19 @@ @pytest.fixture def configure_loader_modules(): - return {saltutil: {"__opts__": {"file_client": "local"}}} + return { + saltutil: { + "__opts__": { + "file_client": "local", + "cachedir": "/tmp", + "pki_dir": "/tmp/pki_dir", + "id": "minion", + "master_uri": "tcp://127.0.0.1:4505", + "__role": "minion", + "keysize": 2048, + } + } + } def test_exec_kwargs(): @@ -90,12 +102,24 @@ def test_refresh_grains_default_clean_pillar_cache(): refresh_pillar.assert_called_with(clean_cache=False) +def test_refresh_grains_default_clean_pillar_cache_with_refresh_false(): + with patch("salt.modules.saltutil.refresh_modules") as refresh_modules: + saltutil.refresh_grains(refresh_pillar=False) + refresh_modules.assert_called() + + def test_refresh_grains_clean_pillar_cache(): with patch("salt.modules.saltutil.refresh_pillar") as refresh_pillar: saltutil.refresh_grains(clean_pillar_cache=True) refresh_pillar.assert_called_with(clean_cache=True) +def test_refresh_grains_clean_pillar_cache_with_refresh_false(): + with patch("salt.modules.saltutil.refresh_modules") as refresh_modules: + saltutil.refresh_grains(clean_pillar_cache=True, refresh_pillar=False) + refresh_modules.assert_called() + + def test_sync_grains_default_clean_pillar_cache(): with patch("salt.modules.saltutil._sync"): with patch("salt.modules.saltutil.refresh_pillar") as refresh_pillar: @@ -136,3 +160,46 @@ def test_sync_all_clean_pillar_cache(): with patch("salt.modules.saltutil.refresh_pillar") as refresh_pillar: saltutil.sync_all(clean_pillar_cache=True) refresh_pillar.assert_called_with(clean_cache=True) + + +@pytest.mark.skip_on_windows(reason="making use of /tmp directory") +def test_list_extmods(salt_call_cli): + ret = salt_call_cli.run("--local", "cmd.run", "mkdir -p /tmp/extmods/dummydir") + assert ret.returncode == 0 + + ret = saltutil.list_extmods() + assert "dummydir" in ret + assert ret["dummydir"] == [] + + +def test_refresh_beacons(): + ret = saltutil.refresh_beacons() + assert ret is False + + +def test_refresh_matchers(): + ret = saltutil.refresh_matchers() + assert ret is False + + +def test_refresh_modules_async_false(): + ## ret = saltutil.refresh_modules( kwargs({"async": False}) ) + kwargs = {"async": False} + ret = saltutil.refresh_modules(**kwargs) + assert ret is False + + +def test_clear_job_cache(salt_call_cli): + ret = salt_call_cli.run("--local", "cmd.run", "mkdir -p /tmp/minion_jobs/dummydir") + assert ret.returncode == 0 + + ret = saltutil.clear_job_cache(hours=1) + assert ret is True + + +@pytest.mark.destructive_test +def test_regen_keys(salt_call_cli): + ret = salt_call_cli.run("--local", "cmd.run", "mkdir -p /tmp/pki_dir/dummydir") + assert ret.returncode == 0 + + saltutil.regen_keys()