From acbef026de77bc8b236af5fc0e8af72b4cad8c98 Mon Sep 17 00:00:00 2001 From: Bert Coleman Date: Tue, 16 Sep 2025 12:18:23 -0600 Subject: [PATCH 1/3] initial commit --- changelog/68188.fixed.md | 1 + salt/runners/mine.py | 2 +- .../pytests/integration/runners/test_mine.py | 77 +++++++++++++++++++ 3 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 changelog/68188.fixed.md create mode 100644 tests/pytests/integration/runners/test_mine.py diff --git a/changelog/68188.fixed.md b/changelog/68188.fixed.md new file mode 100644 index 000000000000..66f8315cc247 --- /dev/null +++ b/changelog/68188.fixed.md @@ -0,0 +1 @@ +fixes salt runner mine.get not returning value if allow_tgt is defined in mine function diff --git a/salt/runners/mine.py b/salt/runners/mine.py index 5fdfbf2bb1e4..2e5ea8e0baee 100644 --- a/salt/runners/mine.py +++ b/salt/runners/mine.py @@ -18,7 +18,7 @@ def get(tgt, fun, tgt_type="glob"): """ masterapi = salt.daemons.masterapi.RemoteFuncs(__opts__) load = { - "id": __opts__["id"], + "id": __opts__["id"].removesuffix("_master"), "fun": fun, "tgt": tgt, "tgt_type": tgt_type, diff --git a/tests/pytests/integration/runners/test_mine.py b/tests/pytests/integration/runners/test_mine.py new file mode 100644 index 000000000000..928ce0d2d9f3 --- /dev/null +++ b/tests/pytests/integration/runners/test_mine.py @@ -0,0 +1,77 @@ +""" +integration tests for the mine runner +""" + +import pytest + +import salt.config +import salt.runners.mine as mine_runner +from tests.support.mock import patch + + +@pytest.fixture(scope="module") +def mine(runners): + return runners.mine + + +@pytest.fixture(scope="module") +def minion_opts(): + return salt.config.minion_config(None) + + +@pytest.fixture(scope="module") +def pillar_tree(salt_master, salt_call_cli, salt_run_cli, salt_minion): + top_file = """ + base: + '*': + - mine + """ + + mine_file = """ + mine_functions: + test_fun: + mine_function: cmd.run + cmd: 'echo hello test' + test_no_allow: + mine_function: cmd.run + cmd: 'echo hello no allow' + """ + + top_tempfile = salt_master.pillar_tree.base.temp_file("top.sls", top_file) + mine_tempfile = salt_master.pillar_tree.base.temp_file("mine.sls", mine_file) + try: + with top_tempfile, mine_tempfile: + ret = salt_call_cli.run("saltutil.refresh_pillar", wait=True) + assert ret.returncode == 0 + assert ret.data is True + ret = salt_run_cli.run("mine.update", salt_minion.id) + assert ret.returncode == 0 + ret = salt_call_cli.run("pillar.items") + assert ret.returncode == 0 + yield + finally: + ret = salt_call_cli.run("saltutil.refresh_pillar", wait=True) + assert ret.returncode == 0 + assert ret.data is True + ret = salt_run_cli.run("mine.update", salt_minion.id) + assert ret.returncode == 0 + + +@pytest.mark.usefixtures("pillar_tree") +def test_allow_tgt(salt_run_cli, salt_minion, minion_opts): + tgt = salt_minion.id + fun = "test_fun" + with patch("salt.runners.mine.__opts__", minion_opts, create=True): + ret = mine_runner.get(tgt, fun) + + ret = salt_run_cli.run("mine.get", tgt, fun) + assert ret.data == {salt_minion.id: "hello test"} + + +@pytest.mark.usefixtures("pillar_tree") +def test_no_allow_tgt(salt_run_cli, salt_minion): + tgt = salt_minion.id + fun = "test_no_allow" + + ret = salt_run_cli.run("mine.get", tgt, fun) + assert ret.data == {salt_minion.id: "hello no allow"} From fb608a5f362b4c2499132300763e8bc817fe7152 Mon Sep 17 00:00:00 2001 From: Bert Coleman Date: Fri, 3 Oct 2025 10:03:45 -0600 Subject: [PATCH 2/3] Update test_mine.py --- .../pytests/integration/runners/test_mine.py | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/tests/pytests/integration/runners/test_mine.py b/tests/pytests/integration/runners/test_mine.py index 928ce0d2d9f3..f3bfbf6d1527 100644 --- a/tests/pytests/integration/runners/test_mine.py +++ b/tests/pytests/integration/runners/test_mine.py @@ -4,19 +4,15 @@ import pytest -import salt.config -import salt.runners.mine as mine_runner -from tests.support.mock import patch +@pytest.fixture(scope="session") +def salt_minion_id(): + return "test-mine" -@pytest.fixture(scope="module") -def mine(runners): - return runners.mine - - -@pytest.fixture(scope="module") -def minion_opts(): - return salt.config.minion_config(None) +@pytest.fixture(scope="session") +def master_id(): + master_id = "test-mine" + yield master_id @pytest.fixture(scope="module") @@ -30,6 +26,8 @@ def pillar_tree(salt_master, salt_call_cli, salt_run_cli, salt_minion): mine_file = """ mine_functions: test_fun: + allow_tgt: '*' + allow_tgt_type: 'glob' mine_function: cmd.run cmd: 'echo hello test' test_no_allow: @@ -57,12 +55,10 @@ def pillar_tree(salt_master, salt_call_cli, salt_run_cli, salt_minion): assert ret.returncode == 0 -@pytest.mark.usefixtures("pillar_tree") -def test_allow_tgt(salt_run_cli, salt_minion, minion_opts): +@pytest.mark.usefixtures("pillar_tree", "master_id", "salt_minion_id") +def test_allow_tgt(salt_run_cli, salt_minion): tgt = salt_minion.id fun = "test_fun" - with patch("salt.runners.mine.__opts__", minion_opts, create=True): - ret = mine_runner.get(tgt, fun) ret = salt_run_cli.run("mine.get", tgt, fun) assert ret.data == {salt_minion.id: "hello test"} From e4d75a8f1195b1d198204fd5a040827faa9790bb Mon Sep 17 00:00:00 2001 From: Bert Coleman Date: Fri, 3 Oct 2025 10:09:29 -0600 Subject: [PATCH 3/3] Update test_mine.py --- tests/pytests/integration/runners/test_mine.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/pytests/integration/runners/test_mine.py b/tests/pytests/integration/runners/test_mine.py index f3bfbf6d1527..3acda7f6fc8f 100644 --- a/tests/pytests/integration/runners/test_mine.py +++ b/tests/pytests/integration/runners/test_mine.py @@ -9,6 +9,7 @@ def salt_minion_id(): return "test-mine" + @pytest.fixture(scope="session") def master_id(): master_id = "test-mine"