Skip to content

Commit

Permalink
Merge pull request #55 from chkp-shirango/master
Browse files Browse the repository at this point in the history
Bugs fix
  • Loading branch information
chkp-shirango authored Jan 17, 2022
2 parents 6f4b5cd + 7f8b95f commit 4d009ff
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
4 changes: 3 additions & 1 deletion plugins/httpapi/checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ def login(self, username, password):

try:
self.connection._auth = {'X-chkp-sid': response_data['sid']}
self.connection._session_uid = response_data['uid']
except KeyError:
raise ConnectionError(
'Server returned response without token info during connection authentication: %s' % response)
# Case of read-only
if 'uid' in response_data.keys():
self.connection._session_uid = response_data['uid']

def logout(self):
url = '/web_api/logout'
Expand Down
42 changes: 36 additions & 6 deletions plugins/module_utils/checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,19 @@ def wait_for_task(module, version, connection, task_id):
completed_tasks = 0
for task in response['tasks']:
if task['status'] == 'failed':
if 'comments' in task and task['comments']:
status_description, comments = get_status_description_and_comments(task)
if comments and status_description:
module.fail_json(
msg='Task {0} with task id {1} failed. Message: {2} with description: {3} - '
'Look at the logs for more details '
.format(task['task-name'], task['task-id'], comments, status_description))
elif comments:
module.fail_json(msg='Task {0} with task id {1} failed. Message: {2} - Look at the logs for more details '
.format(task['task-name'], task['task-id'], comments))
elif status_description:
module.fail_json(msg='Task {0} with task id {1} failed. Message: {2} - Look at the logs for more '
'details '
.format(task['task-name'], task['task-id'], task['comments']))
.format(task['task-name'], task['task-id'], status_description))
else:
module.fail_json(msg='Task {0} with task id {1} failed. Look at the logs for more details'
.format(task['task-name'], task['task-id']))
Expand All @@ -159,13 +168,32 @@ def wait_for_task(module, version, connection, task_id):
return response


# Getting a status description and comments of task failure details
def get_status_description_and_comments(task):
status_description = None
comments = None
if 'comments' in task and task['comments']:
comments = task['comments']
if 'task-details' in task and task['task-details']:
task_details = task['task-details'][0]
if 'statusDescription' in task_details:
status_description = task_details['statusDescription']
return status_description, comments


# if failed occurred, in some cases we want to discard changes before exiting. We also notify the user about the `discard`
def discard_and_fail(module, code, response, connection, version):
discard_code, discard_response = send_request(connection, version, 'discard')
if discard_code != 200:
module.fail_json(msg=parse_fail_message(code, response) + ' Failed to discard session {0}'
' with error {1} with message {2}'.format(connection.get_session_uid(),
discard_code, discard_response))
try:
module.fail_json(msg=parse_fail_message(code, response) + ' Failed to discard session {0}'
' with error {1} with message {2}'.format(connection.get_session_uid(),
discard_code, discard_response))
except Exception:
# Read-only mode without UID
module.fail_json(msg=parse_fail_message(code, response) + ' Failed to discard session'
' with error {0} with message {1}'.format(discard_code, discard_response))

module.fail_json(msg=parse_fail_message(code, response) + ' Unpublished changes were discarded')


Expand Down Expand Up @@ -401,7 +429,9 @@ def is_equals_with_all_params(payload, connection, version, api_call_object, is_
code, response = send_request(connection, version, 'show-' + api_call_object, payload_for_show)
exist_action = response['action']['name']
if exist_action != payload['action']:
return False
if payload['action'] != 'Apply Layer' or exist_action != 'Inner Layer':
return False

# here the action is equals, so check the position param
if not is_equals_with_position_param(payload, connection, version, api_call_object):
return False
Expand Down

0 comments on commit 4d009ff

Please sign in to comment.