@@ -137,10 +137,19 @@ def wait_for_task(module, version, connection, task_id):
137
137
completed_tasks = 0
138
138
for task in response ['tasks' ]:
139
139
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 :
141
150
module .fail_json (msg = 'Task {0} with task id {1} failed. Message: {2} - Look at the logs for more '
142
151
'details '
143
- .format (task ['task-name' ], task ['task-id' ], task [ 'comments' ] ))
152
+ .format (task ['task-name' ], task ['task-id' ], status_description ))
144
153
else :
145
154
module .fail_json (msg = 'Task {0} with task id {1} failed. Look at the logs for more details'
146
155
.format (task ['task-name' ], task ['task-id' ]))
@@ -159,13 +168,32 @@ def wait_for_task(module, version, connection, task_id):
159
168
return response
160
169
161
170
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
+
162
184
# if failed occurred, in some cases we want to discard changes before exiting. We also notify the user about the `discard`
163
185
def discard_and_fail (module , code , response , connection , version ):
164
186
discard_code , discard_response = send_request (connection , version , 'discard' )
165
187
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
+
169
197
module .fail_json (msg = parse_fail_message (code , response ) + ' Unpublished changes were discarded' )
170
198
171
199
@@ -401,7 +429,9 @@ def is_equals_with_all_params(payload, connection, version, api_call_object, is_
401
429
code , response = send_request (connection , version , 'show-' + api_call_object , payload_for_show )
402
430
exist_action = response ['action' ]['name' ]
403
431
if exist_action != payload ['action' ]:
404
- return False
432
+ if payload ['action' ] != 'Apply Layer' or exist_action != 'Inner Layer' :
433
+ return False
434
+
405
435
# here the action is equals, so check the position param
406
436
if not is_equals_with_position_param (payload , connection , version , api_call_object ):
407
437
return False
0 commit comments