From 0ff689a31536d81268ddae360910c054528e3b7e Mon Sep 17 00:00:00 2001 From: Sumit Jaiswal Date: Mon, 8 Apr 2019 21:37:52 +0530 Subject: [PATCH] Resolves handling of error and failure scenarios from Checkpoint module end (#54890) * handle failure case Signed-off-by: Sumit Jaiswal * handle failure case Signed-off-by: Sumit Jaiswal * handle failure case Signed-off-by: Sumit Jaiswal --- .../network/checkpoint/checkpoint_access_rule.py | 9 +++++++-- .../modules/network/checkpoint/checkpoint_host.py | 11 +++++++---- .../modules/network/checkpoint/checkpoint_session.py | 3 ++- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/ansible/modules/network/checkpoint/checkpoint_access_rule.py b/lib/ansible/modules/network/checkpoint/checkpoint_access_rule.py index 104ed75c598..7247f25b549 100644 --- a/lib/ansible/modules/network/checkpoint/checkpoint_access_rule.py +++ b/lib/ansible/modules/network/checkpoint/checkpoint_access_rule.py @@ -228,6 +228,8 @@ def main(): if code == 200: if needs_update(module, response): code, response = update_access_rule(module, connection) + if code != 200: + module.fail_json(msg=response) if module.params['auto_publish_session']: publish(connection) @@ -240,7 +242,8 @@ def main(): pass elif code == 404: code, response = create_access_rule(module, connection) - + if code != 200: + module.fail_json(msg=response) if module.params['auto_publish_session']: publish(connection) @@ -252,7 +255,8 @@ def main(): else: if code == 200: code, response = delete_access_rule(module, connection) - + if code != 200: + module.fail_json(msg=response) if module.params['auto_publish_session']: publish(connection) @@ -260,6 +264,7 @@ def main(): install_policy(connection, module.params['policy_package'], module.params['targets']) result['changed'] = True + result['checkpoint_access_rules'] = response elif code == 404: pass diff --git a/lib/ansible/modules/network/checkpoint/checkpoint_host.py b/lib/ansible/modules/network/checkpoint/checkpoint_host.py index b90aaa0ad8f..bd3e752bb12 100644 --- a/lib/ansible/modules/network/checkpoint/checkpoint_host.py +++ b/lib/ansible/modules/network/checkpoint/checkpoint_host.py @@ -134,7 +134,6 @@ def update_host(module, connection): def delete_host(module, connection): name = module.params['name'] - ip_address = module.params['ip_address'] payload = {'name': name} @@ -170,7 +169,8 @@ def main(): if code == 200: if needs_update(module, response): code, response = update_host(module, connection) - + if code != 200: + module.fail_json(msg=response) if module.params['auto_publish_session']: publish(connection) @@ -183,7 +183,8 @@ def main(): pass elif code == 404: code, response = create_host(module, connection) - + if code != 200: + module.fail_json(msg=response) if module.params['auto_publish_session']: publish(connection) @@ -196,7 +197,8 @@ def main(): if code == 200: # Handle deletion code, response = delete_host(module, connection) - + if code != 200: + module.fail_json(msg=response) if module.params['auto_publish_session']: publish(connection) @@ -204,6 +206,7 @@ def main(): install_policy(connection, module.params['policy_package'], module.params['targets']) result['changed'] = True + result['checkpoint_hosts'] = response elif code == 404: pass diff --git a/lib/ansible/modules/network/checkpoint/checkpoint_session.py b/lib/ansible/modules/network/checkpoint/checkpoint_session.py index 0f42d7733fc..1c039caca7a 100644 --- a/lib/ansible/modules/network/checkpoint/checkpoint_session.py +++ b/lib/ansible/modules/network/checkpoint/checkpoint_session.py @@ -104,7 +104,8 @@ def main(): code, response = connection.send_request('/web_api/publish', payload) else: code, response = connection.send_request('/web_api/discard', payload) - + if code != 200: + module.fail_json(msg=response) result['checkpoint_session'] = response else: module.fail_json(msg='Check Point device returned error {0} with message {1}'.format(code, response))