diff --git a/changelog/69405.fixed.md b/changelog/69405.fixed.md new file mode 100644 index 000000000000..21a0e1dbf75e --- /dev/null +++ b/changelog/69405.fixed.md @@ -0,0 +1 @@ +Decode binary pillars for salt-ssh to align the behaviour with salt-minion. diff --git a/salt/client/ssh/state.py b/salt/client/ssh/state.py index 516b2432e0f5..588d157d4882 100644 --- a/salt/client/ssh/state.py +++ b/salt/client/ssh/state.py @@ -15,6 +15,7 @@ import salt.minion import salt.roster import salt.state +import salt.utils.data import salt.utils.files import salt.utils.json import salt.utils.path @@ -220,6 +221,7 @@ def prep_trans_tar( salt.utils.json.dump(chunks, fp_) if pillar: with salt.utils.files.fopen(pillarfn, "w+") as fp_: + pillar = salt.utils.data.decode_dict(pillar) salt.utils.json.dump(pillar, fp_) if roster_grains: with salt.utils.files.fopen(roster_grainsfn, "w+") as fp_: diff --git a/tests/pytests/unit/client/ssh/test_state.py b/tests/pytests/unit/client/ssh/test_state.py new file mode 100644 index 000000000000..3f1424f3ddb4 --- /dev/null +++ b/tests/pytests/unit/client/ssh/test_state.py @@ -0,0 +1,56 @@ +import pytest + +from salt.client.ssh.state import prep_trans_tar +from tests.support.mock import patch + + +@pytest.mark.parametrize( + "inpt,expected", + [ + ( + { + "pillar_data_n1": 1, + "pillar_data_t2": "text2", + "pillar_data_d3": { + "text1": "text1", + "text2": "text2", + }, + }, + { + "pillar_data_n1": 1, + "pillar_data_t2": "text2", + "pillar_data_d3": { + "text1": "text1", + "text2": "text2", + }, + }, + ), + ( + { + "pillar_data_n1": 1, + "pillar_data_t2": "text2", + "pillar_data_b3": b"text3", + "pillar_data_d4": { + "bin1": b"bin1", + "bin2": b"bin2", + }, + }, + { + "pillar_data_n1": 1, + "pillar_data_t2": "text2", + "pillar_data_b3": "text3", + "pillar_data_d4": { + "bin1": "bin1", + "bin2": "bin2", + }, + }, + ), + ], +) +def test_prep_trans_tar_with_binary_pillar(inpt, expected): + """ + Test binary pillar serialization + """ + with patch("salt.utils.json.dump", return_value="") as json_dump_mock: + trans_tar = prep_trans_tar(None, [], [], pillar=inpt) + assert expected == json_dump_mock.call_args[0][0]