@@ -137,10 +137,19 @@ def wait_for_task(module, version, connection, task_id):
137137 completed_tasks = 0
138138 for task in response ['tasks' ]:
139139 if task ['status' ] == 'failed' :
140- if 'comments' in task and task ['comments' ]:
140+ status_description , comments = get_status_description_and_comments (task )
141+ if comments and status_description :
142+ module .fail_json (
143+ msg = 'Task {0} with task id {1} failed. Message: {2} with description: {3} - '
144+ 'Look at the logs for more details '
145+ .format (task ['task-name' ], task ['task-id' ], comments , status_description ))
146+ elif comments :
147+ module .fail_json (msg = 'Task {0} with task id {1} failed. Message: {2} - Look at the logs for more details '
148+ .format (task ['task-name' ], task ['task-id' ], comments ))
149+ elif status_description :
141150 module .fail_json (msg = 'Task {0} with task id {1} failed. Message: {2} - Look at the logs for more '
142151 'details '
143- .format (task ['task-name' ], task ['task-id' ], task [ 'comments' ] ))
152+ .format (task ['task-name' ], task ['task-id' ], status_description ))
144153 else :
145154 module .fail_json (msg = 'Task {0} with task id {1} failed. Look at the logs for more details'
146155 .format (task ['task-name' ], task ['task-id' ]))
@@ -159,13 +168,32 @@ def wait_for_task(module, version, connection, task_id):
159168 return response
160169
161170
171+ # Getting a status description and comments of task failure details
172+ def get_status_description_and_comments (task ):
173+ status_description = None
174+ comments = None
175+ if 'comments' in task and task ['comments' ]:
176+ comments = task ['comments' ]
177+ if 'task-details' in task and task ['task-details' ]:
178+ task_details = task ['task-details' ][0 ]
179+ if 'statusDescription' in task_details :
180+ status_description = task_details ['statusDescription' ]
181+ return status_description , comments
182+
183+
162184# if failed occurred, in some cases we want to discard changes before exiting. We also notify the user about the `discard`
163185def discard_and_fail (module , code , response , connection , version ):
164186 discard_code , discard_response = send_request (connection , version , 'discard' )
165187 if discard_code != 200 :
166- module .fail_json (msg = parse_fail_message (code , response ) + ' Failed to discard session {0}'
167- ' with error {1} with message {2}' .format (connection .get_session_uid (),
168- discard_code , discard_response ))
188+ try :
189+ module .fail_json (msg = parse_fail_message (code , response ) + ' Failed to discard session {0}'
190+ ' with error {1} with message {2}' .format (connection .get_session_uid (),
191+ discard_code , discard_response ))
192+ except Exception :
193+ # Read-only mode without UID
194+ module .fail_json (msg = parse_fail_message (code , response ) + ' Failed to discard session'
195+ ' with error {0} with message {1}' .format (discard_code , discard_response ))
196+
169197 module .fail_json (msg = parse_fail_message (code , response ) + ' Unpublished changes were discarded' )
170198
171199
@@ -401,7 +429,9 @@ def is_equals_with_all_params(payload, connection, version, api_call_object, is_
401429 code , response = send_request (connection , version , 'show-' + api_call_object , payload_for_show )
402430 exist_action = response ['action' ]['name' ]
403431 if exist_action != payload ['action' ]:
404- return False
432+ if payload ['action' ] != 'Apply Layer' or exist_action != 'Inner Layer' :
433+ return False
434+
405435 # here the action is equals, so check the position param
406436 if not is_equals_with_position_param (payload , connection , version , api_call_object ):
407437 return False
0 commit comments