Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3007.x] Fix #66194: Exchange HTTPClient by AsyncHTTPClient in salt.utils.http #66330

Open
wants to merge 3 commits into
base: 3007.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/66330.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fix #66194: Exchange HTTPClient by AsyncHTTPClient in salt.utils.http
13 changes: 7 additions & 6 deletions salt/utils/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import tornado.httpclient
import tornado.httputil
import tornado.simple_httpclient
from tornado.httpclient import HTTPClient
from tornado.httpclient import AsyncHTTPClient

import salt.config
import salt.loader
Expand All @@ -43,6 +43,7 @@
import salt.utils.yaml
import salt.version
from salt.template import compile_template
from salt.utils.asynchronous import SyncWrapper
from salt.utils.decorators.jinja import jinja_filter

try:
Expand Down Expand Up @@ -598,7 +599,7 @@ def query(
salt.config.DEFAULT_MINION_OPTS["http_request_timeout"],
)

tornado.httpclient.AsyncHTTPClient.configure(None)
AsyncHTTPClient.configure(None)
client_argspec = salt.utils.args.get_function_argspec(
tornado.simple_httpclient.SimpleAsyncHTTPClient.initialize
)
Expand Down Expand Up @@ -629,10 +630,10 @@ def query(
req_kwargs = salt.utils.data.decode(req_kwargs, to_str=True)

try:
download_client = (
HTTPClient(max_body_size=max_body)
if supports_max_body_size
else HTTPClient()
download_client = SyncWrapper(
AsyncHTTPClient,
kwargs={"max_body_size": max_body} if supports_max_body_size else {},
async_methods=["fetch"],
)
result = download_client.fetch(url_full, **req_kwargs)
except tornado.httpclient.HTTPError as exc:
Expand Down
29 changes: 29 additions & 0 deletions tests/pytests/integration/pillar/test_httpclient_in_pillar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
def test_pillar_using_http_query(salt_master, salt_minion, salt_cli, tmp_path):
pillar_top = """
base:
"*":
- http_pillar_test
"""
my_pillar = """
{%- set something = salt['http.query']('https://raw.githubusercontent.com/saltstack/salt/master/.pre-commit-config.yaml', raise_error=False, verify_ssl=False, status=True, timeout=5).status %}
http_query_test: {{ something }}
"""

with salt_master.pillar_tree.base.temp_file("top.sls", pillar_top):
krombel marked this conversation as resolved.
Show resolved Hide resolved
with salt_master.pillar_tree.base.temp_file("http_pillar_test.sls", my_pillar):
with salt_master.pillar_tree.base.temp_file(
"http_pillar_test.sls", my_pillar
):
ret = salt_cli.run("state.apply", minion_tgt=salt_minion.id)
assert ret.returncode == 1
assert (
ret.data["no_|-states_|-states_|-None"]["comment"]
== "No states found for this minion"
)

pillar_ret = salt_cli.run(
"pillar.item", "http_query_test", minion_tgt=salt_minion.id
)
assert pillar_ret.returncode == 0

assert '"http_query_test": 200' in pillar_ret.stdout