Handle errors correctly in rhn_channel (#54194)

* Handle errors correctly in rhn_channel

* also fail if required info is not available
This commit is contained in:
Brian Coca 2019-03-27 19:43:28 -04:00 committed by GitHub
parent 785afc7a53
commit fee4a0df94
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 4 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- handle xmlrpc errors in the correct fashion for rhn_channel

View file

@ -59,6 +59,7 @@ EXAMPLES = '''
delegate_to: localhost
'''
from ansible.module_utils._text import to_text
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six.moves import xmlrpc_client
@ -114,14 +115,29 @@ def main():
password = module.params['password']
# initialize connection
client = xmlrpc_client.Server(saturl)
session = client.auth.login(user, password)
client = xmlrpc_client.ServerProxy(saturl)
try:
session = client.auth.login(user, password)
except Exception as e:
module.fail_json(msg="Unable to establish session with Sattelite server: %s " % to_text(e))
if not session:
module.fail_json(msg="Failed to establish session with Sattelite server.")
# get systemid
sys_id = get_systemid(client, session, systname)
try:
sys_id = get_systemid(client, session, systname)
except Exception as e:
module.fail_json(msg="Unable to get system id: %s " % to_text(e))
if not sys_id:
module.fail_json(msg="Failed to get system id.")
# get channels for system
chans = base_channels(client, session, sys_id)
try:
chans = base_channels(client, session, sys_id)
except Exception as e:
module.fail_json(msg="Unable to get channel information: %s " % to_text(e))
try:
if state == 'present':
@ -137,6 +153,8 @@ def main():
else:
unsubscribe_channels(channelname, client, session, systname, sys_id)
module.exit_json(changed=True, msg="Channel %s removed" % channelname)
except Exception as e:
module.fail_json('Unable to %s channel (%s): %s' % ('add' if state == 'present' else 'remove', channelname, to_text(e)))
finally:
client.auth.logout(session)