1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

[PR #6114/6cf67448 backport][stable-6] memset*.py: Fixed URLError handling (#6157)

memset*.py: Fixed URLError handling (#6114)

* memset.py: Added URLError exception and stderr to Response() object

* memset_*.py: Check response.status_code and response.stderr

* Added changelog fragment

* memset.py: Fixed pep8

* Renamed changelog fragment with .yml file extension

(cherry picked from commit 6cf674485f)

Co-authored-by: Daniel Patrick <dani.p1991@gmail.com>
This commit is contained in:
patchback[bot] 2023-03-08 13:58:39 +01:00 committed by GitHub
parent 47514e1401
commit 36eff2fd99
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 30 additions and 5 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- "memset - fix memset urlerror handling (https://github.com/ansible-collections/community.general/pull/6114)."

View file

@ -26,6 +26,7 @@ class Response(object):
def __init__(self):
self.content = None
self.status_code = None
self.stderr = None
def json(self):
return json.loads(self.content)
@ -75,6 +76,10 @@ def memset_api_call(api_key, api_method, payload=None):
msg = "Memset API returned a {0} response ({1}, {2})." . format(response.status_code, response.json()['error_type'], response.json()['error'])
else:
msg = "Memset API returned an error ({0}, {1})." . format(response.json()['error_type'], response.json()['error'])
except urllib_error.URLError as e:
has_failed = True
msg = "An URLError occured ({0})." . format(type(e))
response.stderr = "{0}" . format(e)
if msg is None:
msg = response.json()

View file

@ -139,7 +139,10 @@ def reload_dns(args=None):
# manifest themselves at this point so we need to ensure the user is
# informed of the reason.
retvals['failed'] = has_failed
retvals['memset_api'] = response.json()
if response.status_code is not None:
retvals['memset_api'] = response.json()
else:
retvals['stderr'] = response.stderr
retvals['msg'] = msg
return retvals

View file

@ -134,7 +134,10 @@ def get_facts(args=None):
# informed of the reason.
retvals['failed'] = has_failed
retvals['msg'] = msg
retvals['stderr'] = "API returned an error: {0}" . format(response.status_code)
if response.status_code is not None:
retvals['stderr'] = "API returned an error: {0}" . format(response.status_code)
else:
retvals['stderr'] = "{0}" . format(response.stderr)
return retvals
# we don't want to return the same thing twice

View file

@ -259,7 +259,10 @@ def get_facts(args=None):
# informed of the reason.
retvals['failed'] = has_failed
retvals['msg'] = msg
retvals['stderr'] = "API returned an error: {0}" . format(response.status_code)
if response.status_code is not None:
retvals['stderr'] = "API returned an error: {0}" . format(response.status_code)
else:
retvals['stderr'] = "{0}" . format(response.stderr)
return retvals
# we don't want to return the same thing twice

View file

@ -264,6 +264,9 @@ def create_or_delete(args=None):
retvals['failed'] = _has_failed
retvals['msg'] = _msg
if response.stderr is not None:
retvals['stderr'] = response.stderr
return retvals
zone_exists, _msg, counter, _zone_id = get_zone_id(zone_name=args['name'], current_zones=response.json())

View file

@ -195,7 +195,10 @@ def create_or_delete_domain(args=None):
# informed of the reason.
retvals['failed'] = has_failed
retvals['msg'] = msg
retvals['stderr'] = "API returned an error: {0}" . format(response.status_code)
if response.status_code is not None:
retvals['stderr'] = "API returned an error: {0}" . format(response.status_code)
else:
retvals['stderr'] = response.stderr
return retvals
zone_exists, msg, counter, zone_id = get_zone_id(zone_name=args['zone'], current_zones=response.json())

View file

@ -313,7 +313,10 @@ def create_or_delete(args=None):
# informed of the reason.
retvals['failed'] = _has_failed
retvals['msg'] = msg
retvals['stderr'] = "API returned an error: {0}" . format(response.status_code)
if response.status_code is not None:
retvals['stderr'] = "API returned an error: {0}" . format(response.status_code)
else:
retvals['stderr'] = response.stderr
return retvals
zone_exists, _msg, counter, zone_id = get_zone_id(zone_name=args['zone'], current_zones=response.json())