mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
[PR #6114/6cf67448 backport][stable-5] memset*.py: Fixed URLError handling (#6156)
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:
parent
6d03887c55
commit
afb16dc0a2
8 changed files with 30 additions and 5 deletions
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- "memset - fix memset urlerror handling (https://github.com/ansible-collections/community.general/pull/6114)."
|
|
@ -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()
|
||||
|
|
|
@ -132,7 +132,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
|
||||
|
||||
|
|
|
@ -127,7 +127,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
|
||||
|
|
|
@ -252,7 +252,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
|
||||
|
|
|
@ -257,6 +257,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())
|
||||
|
|
|
@ -188,7 +188,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())
|
||||
|
|
|
@ -306,7 +306,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())
|
||||
|
|
Loading…
Reference in a new issue