Add test for namespaces with http json pillar

This commit is contained in:
Megan Wilhite 2022-10-13 13:42:04 -06:00
parent ec1e6c975b
commit cc13090daa
No known key found for this signature in database
GPG key ID: C69F308012C0B283
3 changed files with 27 additions and 1 deletions

View file

@ -21,7 +21,7 @@ Set the following Salt config to setup http json result as external pillar sourc
You can pass additional parameters, they will be added to the http.query call You can pass additional parameters, they will be added to the http.query call
:py:func:`utils.http.query function <salt.utils.http.query>`: :py:func:`utils.http.query function <salt.utils.http.query>`:
.. versionchanged:: TBD .. versionchanged:: 3006
If namespace is defined, the data will be added under the specified subkeys in the Pillar structure. If namespace is defined, the data will be added under the specified subkeys in the Pillar structure.
If the with_grains parameter is set, grain keys wrapped in can be provided (wrapped If the with_grains parameter is set, grain keys wrapped in can be provided (wrapped
@ -81,6 +81,7 @@ def ext_pillar(
:param str username: username for auth :param str username: username for auth
:param str pasword: password for auth :param str pasword: password for auth
:param str namespace: (Optional) A pillar key to namespace the values under. :param str namespace: (Optional) A pillar key to namespace the values under.
.. versionadded:: 3006
:return: A dictionary of the pillar data to add. :return: A dictionary of the pillar data to add.
:rtype: dict :rtype: dict

View file

@ -39,3 +39,28 @@ def test_ext_pillar_can_take_http_query_kwargs(backend, httpserver):
actual = http_json.ext_pillar("test-minion-id", {}, url, header_dict=header_dict) actual = http_json.ext_pillar("test-minion-id", {}, url, header_dict=header_dict)
assert actual == response assert actual == response
@pytest.mark.requires_network
@pytest.mark.parametrize("backend", ["requests", "tornado", "urllib2"])
def test_ext_pillar_namespace(backend, httpserver):
response = {
"dict": {
"backend": backend,
"pillar_type": "http_json",
},
}
header_dict = {"custom-backend-header": backend}
namespace = "test_namespace"
# If the headers in header_dict are not in the request, httpserver will return an empty dictionary, so we know it will fail
httpserver.expect_request(
"/http_json_pillar/{}".format(backend),
headers={"custom-backend-header": backend},
).respond_with_data(salt.utils.json.dumps(response), content_type="text/plain")
url = httpserver.url_for("/http_json_pillar/{}".format(backend))
actual = http_json.ext_pillar(
"test-minion-id", {}, url, header_dict=header_dict, namespace=namespace
)
assert actual == {namespace: response}