Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3006.x] return event greednes fix. #66010

Merged
merged 6 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/65727.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
catch only ret/ events not all returning events.
2 changes: 1 addition & 1 deletion salt/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]:
Expand Down
2 changes: 1 addition & 1 deletion tests/pytests/functional/cli/test_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
41 changes: 41 additions & 0 deletions tests/pytests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading