def test_ext_pillar(etcd_client_mock, instance): """ Test ext_pillar functionality """ with patch("salt.utils.etcd_util.get_conn", etcd_client_mock): # Test pillar with no root given instance.tree.return_value = {"key": "value"} assert etcd_pillar.ext_pillar("test-id", {}, "etcd_profile") == { "key": "value" } instance.tree.assert_called_with("/") # Test pillar with a root given instance.tree.return_value = {"key": "value"} assert etcd_pillar.ext_pillar("test-id", {}, "etcd_profile root=/salt") == { "key": "value" } instance.tree.assert_called_with("/salt") # Test pillar with a root given that uses the minion id instance.tree.return_value = {"key": "value"} assert etcd_pillar.ext_pillar( "test-id", {}, "etcd_profile root=/salt/%(minion_id)s") == { "key": "value" } instance.tree.assert_called_with("/salt/test-id") # Test pillar with a root given that uses the minion id instance.tree.side_effect = KeyError assert etcd_pillar.ext_pillar("test-id", {"key": "value"}, "etcd_profile") == {}
def test_ext_pillar(subtests, profile_name, prefix, etcd_client): """ Test ext_pillar functionality """ updated = { "1": "not one", "2": { "3": "two-three", "4": "two-four", }, } etcd_client.update(updated, path=prefix) with subtests.test("We should be able to use etcd as an external pillar"): expected = { "salt": { "pillar": { "test": updated, }, }, } assert etcd_pillar.ext_pillar("minion_id", {}, profile_name) == expected