mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
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
This commit is contained in:
parent
11c7611ced
commit
6cf674485f
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):
|
def __init__(self):
|
||||||
self.content = None
|
self.content = None
|
||||||
self.status_code = None
|
self.status_code = None
|
||||||
|
self.stderr = None
|
||||||
|
|
||||||
def json(self):
|
def json(self):
|
||||||
return json.loads(self.content)
|
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'])
|
msg = "Memset API returned a {0} response ({1}, {2})." . format(response.status_code, response.json()['error_type'], response.json()['error'])
|
||||||
else:
|
else:
|
||||||
msg = "Memset API returned an error ({0}, {1})." . format(response.json()['error_type'], response.json()['error'])
|
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:
|
if msg is None:
|
||||||
msg = response.json()
|
msg = response.json()
|
||||||
|
|
|
@ -139,7 +139,10 @@ def reload_dns(args=None):
|
||||||
# manifest themselves at this point so we need to ensure the user is
|
# manifest themselves at this point so we need to ensure the user is
|
||||||
# informed of the reason.
|
# informed of the reason.
|
||||||
retvals['failed'] = has_failed
|
retvals['failed'] = has_failed
|
||||||
|
if response.status_code is not None:
|
||||||
retvals['memset_api'] = response.json()
|
retvals['memset_api'] = response.json()
|
||||||
|
else:
|
||||||
|
retvals['stderr'] = response.stderr
|
||||||
retvals['msg'] = msg
|
retvals['msg'] = msg
|
||||||
return retvals
|
return retvals
|
||||||
|
|
||||||
|
|
|
@ -134,7 +134,10 @@ def get_facts(args=None):
|
||||||
# informed of the reason.
|
# informed of the reason.
|
||||||
retvals['failed'] = has_failed
|
retvals['failed'] = has_failed
|
||||||
retvals['msg'] = msg
|
retvals['msg'] = msg
|
||||||
|
if response.status_code is not None:
|
||||||
retvals['stderr'] = "API returned an error: {0}" . format(response.status_code)
|
retvals['stderr'] = "API returned an error: {0}" . format(response.status_code)
|
||||||
|
else:
|
||||||
|
retvals['stderr'] = "{0}" . format(response.stderr)
|
||||||
return retvals
|
return retvals
|
||||||
|
|
||||||
# we don't want to return the same thing twice
|
# we don't want to return the same thing twice
|
||||||
|
|
|
@ -259,7 +259,10 @@ def get_facts(args=None):
|
||||||
# informed of the reason.
|
# informed of the reason.
|
||||||
retvals['failed'] = has_failed
|
retvals['failed'] = has_failed
|
||||||
retvals['msg'] = msg
|
retvals['msg'] = msg
|
||||||
|
if response.status_code is not None:
|
||||||
retvals['stderr'] = "API returned an error: {0}" . format(response.status_code)
|
retvals['stderr'] = "API returned an error: {0}" . format(response.status_code)
|
||||||
|
else:
|
||||||
|
retvals['stderr'] = "{0}" . format(response.stderr)
|
||||||
return retvals
|
return retvals
|
||||||
|
|
||||||
# we don't want to return the same thing twice
|
# we don't want to return the same thing twice
|
||||||
|
|
|
@ -264,6 +264,9 @@ def create_or_delete(args=None):
|
||||||
retvals['failed'] = _has_failed
|
retvals['failed'] = _has_failed
|
||||||
retvals['msg'] = _msg
|
retvals['msg'] = _msg
|
||||||
|
|
||||||
|
if response.stderr is not None:
|
||||||
|
retvals['stderr'] = response.stderr
|
||||||
|
|
||||||
return retvals
|
return retvals
|
||||||
|
|
||||||
zone_exists, _msg, counter, _zone_id = get_zone_id(zone_name=args['name'], current_zones=response.json())
|
zone_exists, _msg, counter, _zone_id = get_zone_id(zone_name=args['name'], current_zones=response.json())
|
||||||
|
|
|
@ -195,7 +195,10 @@ def create_or_delete_domain(args=None):
|
||||||
# informed of the reason.
|
# informed of the reason.
|
||||||
retvals['failed'] = has_failed
|
retvals['failed'] = has_failed
|
||||||
retvals['msg'] = msg
|
retvals['msg'] = msg
|
||||||
|
if response.status_code is not None:
|
||||||
retvals['stderr'] = "API returned an error: {0}" . format(response.status_code)
|
retvals['stderr'] = "API returned an error: {0}" . format(response.status_code)
|
||||||
|
else:
|
||||||
|
retvals['stderr'] = response.stderr
|
||||||
return retvals
|
return retvals
|
||||||
|
|
||||||
zone_exists, msg, counter, zone_id = get_zone_id(zone_name=args['zone'], current_zones=response.json())
|
zone_exists, msg, counter, zone_id = get_zone_id(zone_name=args['zone'], current_zones=response.json())
|
||||||
|
|
|
@ -313,7 +313,10 @@ def create_or_delete(args=None):
|
||||||
# informed of the reason.
|
# informed of the reason.
|
||||||
retvals['failed'] = _has_failed
|
retvals['failed'] = _has_failed
|
||||||
retvals['msg'] = msg
|
retvals['msg'] = msg
|
||||||
|
if response.status_code is not None:
|
||||||
retvals['stderr'] = "API returned an error: {0}" . format(response.status_code)
|
retvals['stderr'] = "API returned an error: {0}" . format(response.status_code)
|
||||||
|
else:
|
||||||
|
retvals['stderr'] = response.stderr
|
||||||
return retvals
|
return retvals
|
||||||
|
|
||||||
zone_exists, _msg, counter, zone_id = get_zone_id(zone_name=args['zone'], current_zones=response.json())
|
zone_exists, _msg, counter, zone_id = get_zone_id(zone_name=args['zone'], current_zones=response.json())
|
||||||
|
|
Loading…
Reference in a new issue