From cc13090daae9a5e4cad4e488e0abbf828a5c30d5 Mon Sep 17 00:00:00 2001 From: Megan Wilhite Date: Thu, 13 Oct 2022 13:42:04 -0600 Subject: [PATCH] Add test for namespaces with http json pillar --- changelog/{61335.fixed => 61335.added} | 0 salt/pillar/http_json.py | 3 ++- .../unit/pillar/test_http_json_pillar.py | 25 +++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) rename changelog/{61335.fixed => 61335.added} (100%) diff --git a/changelog/61335.fixed b/changelog/61335.added similarity index 100% rename from changelog/61335.fixed rename to changelog/61335.added diff --git a/salt/pillar/http_json.py b/salt/pillar/http_json.py index b73fcf92a8c..78fdd505740 100644 --- a/salt/pillar/http_json.py +++ b/salt/pillar/http_json.py @@ -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 :py:func:`utils.http.query function `: -.. versionchanged:: TBD +.. versionchanged:: 3006 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 @@ -81,6 +81,7 @@ def ext_pillar( :param str username: username for auth :param str pasword: password for auth :param str namespace: (Optional) A pillar key to namespace the values under. + .. versionadded:: 3006 :return: A dictionary of the pillar data to add. :rtype: dict diff --git a/tests/pytests/unit/pillar/test_http_json_pillar.py b/tests/pytests/unit/pillar/test_http_json_pillar.py index a32041d50e0..5040c2e7a14 100644 --- a/tests/pytests/unit/pillar/test_http_json_pillar.py +++ b/tests/pytests/unit/pillar/test_http_json_pillar.py @@ -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) 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}