From 59c18e36e371278625bb61e536e481d9e57ab47d Mon Sep 17 00:00:00 2001 From: Thomas Phipps Date: Tue, 6 Feb 2024 17:15:40 +0000 Subject: [PATCH 1/4] the fix for grabbing just our events and not sseapes --- salt/client/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/client/__init__.py b/salt/client/__init__.py index 307ce8a0ad41..ebfbea48e7a2 100644 --- a/salt/client/__init__.py +++ b/salt/client/__init__.py @@ -1204,7 +1204,7 @@ def get_iter_returns( continue # Anything below this point is expected to be a job return event. - if not raw["tag"].startswith(f"salt/job/{jid}/ret"): + if not raw["tag"].startswith(f"salt/job/{jid}/ret/"): log.debug("Skipping non return event: %s", raw["tag"]) continue if "return" not in raw["data"]: From d2db8cc88d114ac6b9f86c166083d7d9e5502b16 Mon Sep 17 00:00:00 2001 From: Thomas Phipps Date: Tue, 6 Feb 2024 17:18:57 +0000 Subject: [PATCH 2/4] add changelog --- changelog/65727.fixed.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/65727.fixed.md diff --git a/changelog/65727.fixed.md b/changelog/65727.fixed.md new file mode 100644 index 000000000000..fe507ce4f8cd --- /dev/null +++ b/changelog/65727.fixed.md @@ -0,0 +1 @@ +catch only ret/ events not all returning events. From 2a8428f4e949070dc2023ef9981f48841765da58 Mon Sep 17 00:00:00 2001 From: "Daniel A. Wozniak" Date: Thu, 8 Feb 2024 14:17:40 -0700 Subject: [PATCH 3/4] Add test for return fix --- tests/pytests/unit/test_client.py | 41 +++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/pytests/unit/test_client.py b/tests/pytests/unit/test_client.py index 48a218736970..fde31f459fb9 100644 --- a/tests/pytests/unit/test_client.py +++ b/tests/pytests/unit/test_client.py @@ -247,3 +247,44 @@ def test_pub_win32(salt_master_factory): "test.ping", tgt_type="nodegroup", ) + + +def test_invalid_event_tag_65727(master_opts, caplog): + """ + LocalClient.get_iter_returns handles non return event tags. + """ + minions = () + jid = "0815" + raw_return = {"id": "fake-id", "jid": jid, "data": "", "return": "fake-return"} + expected_return = {"fake-id": {"ret": "fake-return"}} + + def returns_iter(): + # Invalid return + yield { + "tag": "salt/job/0815/return/", + "data": { + "return": "fpp", + "id": "fake-id", + }, + } + # Valid return + yield { + "tag": "salt/job/0815/ret/", + "data": { + "return": "fpp", + "id": "fake-id", + }, + } + + with client.LocalClient(mopts=master_opts) as local_client: + # Returning a truthy value, the real method returns a salt returner but it's not used. + local_client.returns_for_job = MagicMock(return_value=True) + # Mock iter returns, we'll return one invalid and one valid return event. + local_client.get_returns_no_block = MagicMock(return_value=returns_iter()) + with caplog.at_level(logging.DEBUG): + # Validate we don't choke on the bad return, the method returns a + # valid respons and the invalid event tag is getting logged to + # debug. + for ret in local_client.get_iter_returns(jid, {"fake-id"}): + assert ret == {"fake-id": {"ret": "fpp"}} + assert "Skipping non return event: salt/job/0815/return/" in caplog.text From 0e6534d017487817666d4651e1cb06eb23b299af Mon Sep 17 00:00:00 2001 From: Thomas Phipps Date: Fri, 9 Feb 2024 20:23:26 +0000 Subject: [PATCH 4/4] fix tests/pytests/functional/cli/test_batch.py::test_batch_issue_56273 --- tests/pytests/functional/cli/test_batch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/pytests/functional/cli/test_batch.py b/tests/pytests/functional/cli/test_batch.py index e721b729cfe4..8c69b48cf4a3 100644 --- a/tests/pytests/functional/cli/test_batch.py +++ b/tests/pytests/functional/cli/test_batch.py @@ -140,7 +140,7 @@ def _ret(self, jid, minion_id, fun, _return=True, _retcode=0): }, use_bin_type=True, ) - tag = "salt/job/{}/ret".format(jid).encode() + tag = f"salt/job/{jid}/ret/{minion_id}".encode() return b"".join([tag, b"\n\n", dumped]) def connect(self, timeout=None):