Skip to content

Commit

Permalink
[PR #9608/d7f067dd backport][stable-10] apache2-mod-proxy: receive re…
Browse files Browse the repository at this point in the history
…sults from fetch_url as tuple of vars (#9610)

apache2-mod-proxy: receive results from fetch_url as tuple of vars (#9608)

* apache2-mod-proxy: receive results from fetch_url as tuple of vars

* add changelog frag

(cherry picked from commit d7f067d)

Co-authored-by: Alexei Znamensky <[email protected]>
  • Loading branch information
patchback[bot] and russoz authored Jan 23, 2025
1 parent dbd19a5 commit 769b22c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/9608-apache2-mod-proxy-revamp3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- apache2_mod_proxy - improve readability when using results from ``fecth_url()`` (https://github.com/ansible-collections/community.general/pull/9608).
24 changes: 12 additions & 12 deletions plugins/modules/apache2_mod_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,13 @@ def __init__(self, management_url, balancer_url, module):
def get_member_attributes(self):
""" Returns a dictionary of a balancer member's attributes."""

balancer_member_page = fetch_url(self.module, self.management_url)
resp, info = fetch_url(self.module, self.management_url)

if balancer_member_page[1]['status'] != 200:
self.module.fail_json(msg="Could not get balancer_member_page, check for connectivity! " + balancer_member_page[1])
if info['status'] != 200:
self.module.fail_json(msg="Could not get balancer_member_page, check for connectivity! " + str(info))
else:
try:
soup = BeautifulSoup(balancer_member_page[0])
soup = BeautifulSoup(resp)
except TypeError as exc:
self.module.fail_json(msg="Cannot parse balancer_member_page HTML! " + str(exc))
else:
Expand Down Expand Up @@ -292,12 +292,12 @@ def set_member_status(self, values):
'ignore_errors': '&w_status_I'}

request_body = regexp_extraction(self.management_url, EXPRESSION, 1)
values_url = "".join("{0}={1}".format(url_param, 1 if values[mode] else 0) for mode, url_param in iteritems(values_mapping))
values_url = "".join("{0}={1}".format(url_param, 1 if values[mode] else 0) for mode, url_param in values_mapping.items())
request_body = "{0}{1}".format(request_body, values_url)

response = fetch_url(self.module, self.management_url, data=request_body)
if response[1]['status'] != 200:
self.module.fail_json(msg="Could not set the member status! " + self.host + " " + response[1]['status'])
response, info = fetch_url(self.module, self.management_url, data=request_body)
if info['status'] != 200:
self.module.fail_json(msg="Could not set the member status! " + self.host + " " + info['status'])

attributes = property(get_member_attributes)
status = property(get_member_status, set_member_status)
Expand Down Expand Up @@ -332,11 +332,11 @@ def __init__(self, host, suffix, module, members=None, tls=False):

def fetch_balancer_page(self):
""" Returns the balancer management html page as a string for later parsing."""
page = fetch_url(self.module, str(self.url))
if page[1]['status'] != 200:
self.module.fail_json(msg="Could not get balancer page! HTTP status response: " + str(page[1]['status']))
resp, info = fetch_url(self.module, str(self.url))
if info['status'] != 200:
self.module.fail_json(msg="Could not get balancer page! HTTP status response: " + str(info['status']))
else:
content = page[0].read()
content = resp.read()
apache_version = regexp_extraction(content.upper(), APACHE_VERSION_EXPRESSION, 1)
if apache_version:
if not re.search(pattern=r"2\.4\.[\d]*", string=apache_version):
Expand Down

0 comments on commit 769b22c

Please sign in to comment.