mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Ensure file_tree pillar returns unicode
This commit is contained in:
parent
e21fa5d518
commit
99e4e75c33
3 changed files with 33 additions and 9 deletions
1
changelog/58794.fixed
Normal file
1
changelog/58794.fixed
Normal file
|
@ -0,0 +1 @@
|
|||
Ensure file_tree pillar returns unicode.
|
|
@ -259,9 +259,9 @@ def _construct_pillar(
|
|||
whitelist=renderer_whitelist,
|
||||
)
|
||||
if salt.utils.stringio.is_readable(data):
|
||||
pillar_node[file_name] = data.getvalue()
|
||||
pillar_node[file_name] = salt.utils.stringutils.to_unicode(data.getvalue())
|
||||
else:
|
||||
pillar_node[file_name] = data
|
||||
pillar_node[file_name] = salt.utils.stringutils.to_unicode(data)
|
||||
|
||||
return pillar
|
||||
|
||||
|
|
|
@ -27,18 +27,18 @@ MINION_ID = "test-host"
|
|||
NODEGROUP_PATH = os.path.join("nodegroups", "test-group", "files")
|
||||
HOST_PATH = os.path.join("hosts", MINION_ID, "files")
|
||||
|
||||
BASE_PILLAR_CONTENT = {"files": {"hostfile": b"base", "groupfile": b"base"}}
|
||||
BASE_PILLAR_CONTENT = {"files": {"hostfile": "base", "groupfile": "base"}}
|
||||
DEV_PILLAR_CONTENT = {
|
||||
"files": {
|
||||
"hostfile": b"base",
|
||||
"groupfile": b"dev2",
|
||||
"hostfile1": b"dev1",
|
||||
"groupfile1": b"dev1",
|
||||
"hostfile2": b"dev2",
|
||||
"hostfile": "base",
|
||||
"groupfile": "dev2",
|
||||
"hostfile1": "dev1",
|
||||
"groupfile1": "dev1",
|
||||
"hostfile2": "dev2",
|
||||
}
|
||||
}
|
||||
PARENT_PILLAR_CONTENT = {
|
||||
"files": {"hostfile": b"base", "groupfile": b"base", "hostfile2": b"dev2"}
|
||||
"files": {"hostfile": "base", "groupfile": "base", "hostfile2": "dev2"}
|
||||
}
|
||||
|
||||
FILE_DATA = {
|
||||
|
@ -159,3 +159,26 @@ class FileTreePillarTestCase(TestCase, LoaderModuleMockMixin):
|
|||
break
|
||||
else:
|
||||
raise AssertionError("Did not find error message")
|
||||
|
||||
def test_file_tree_no_bytes(self):
|
||||
"""
|
||||
test file_tree pillar does not return bytes
|
||||
"""
|
||||
absolute_path = os.path.join(self.pillar_path, "base")
|
||||
with patch(
|
||||
"salt.utils.minions.CkMinions.check_minions",
|
||||
MagicMock(return_value=_CHECK_MINIONS_RETURN),
|
||||
):
|
||||
mypillar = file_tree.ext_pillar(MINION_ID, None, absolute_path)
|
||||
self.assertEqual(BASE_PILLAR_CONTENT, mypillar)
|
||||
|
||||
with patch.dict(file_tree.__opts__, {"pillarenv": "dev"}):
|
||||
mypillar = file_tree.ext_pillar(MINION_ID, None, absolute_path)
|
||||
for key,value in mypillar.items():
|
||||
if isinstance(value, dict):
|
||||
for ikey,ivalue in value.items():
|
||||
self.assertTrue(isinstance(ikey, str))
|
||||
self.assertTrue(isinstance(ivalue, str))
|
||||
else:
|
||||
self.assertTrue(isinstance(value, str))
|
||||
self.assertTrue(isinstance(key, str))
|
||||
|
|
Loading…
Add table
Reference in a new issue