Skip to content

Commit a8193fb

Browse files
kobymeirkobymeir
authored andcommitted
adding more attempts when installing packs on xsiam. (demisto#29158)
Co-authored-by: kobymeir <[email protected]>
1 parent f55d396 commit a8193fb

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

Diff for: Tests/Marketplace/search_and_install_packs.py

+14-9
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def get_pack_dependencies(client: demisto_client,
242242
logging.warning(f"API request to fetch dependencies of pack '{pack_id}' has failed.\n"
243243
f"Response code '{ex.status}'\nResponse: '{ex.body}'\nResponse Headers: '{ex.headers}'")
244244

245-
elif isinstance(ex, (HTTPError, HTTPWarning)):
245+
elif isinstance(ex, HTTPError | HTTPWarning):
246246
logging.warning(f"Failed to perform HTTP request : {ex}")
247247

248248
else:
@@ -349,11 +349,11 @@ def install_packs_private(client: demisto_client,
349349
test_pack_path=test_pack_path)
350350

351351

352-
def get_error_ids(body: str) -> set[str]:
352+
def get_error_ids(body: str) -> dict[int, str]:
353353
with contextlib.suppress(json.JSONDecodeError):
354354
response_info = json.loads(body)
355-
return {error["id"] for error in response_info.get("errors", []) if "id" in error}
356-
return set()
355+
return {error["id"]: error.get("details", "") for error in response_info.get("errors", []) if "id" in error}
356+
return {}
357357

358358

359359
def install_packs(client: demisto_client,
@@ -417,10 +417,15 @@ def install_packs(client: demisto_client,
417417
logging.error(f"Unable to install malformed packs: {malformed_ids}, retrying without them.")
418418
packs_to_install = [pack for pack in packs_to_install if pack['id'] not in malformed_ids]
419419

420-
if (error_ids := get_error_ids(ex.body)) and WLM_TASK_FAILED_ERROR_CODE in error_ids:
421-
# If we got this error code, it means that the modeling rules are not valid, exiting install flow.
422-
raise Exception(f"Got [{WLM_TASK_FAILED_ERROR_CODE}] error code - Modeling rules and Dataset validations "
423-
f"failed. Please look at GCP logs to understand why it failed.") from ex
420+
error_ids = get_error_ids(ex.body)
421+
if WLM_TASK_FAILED_ERROR_CODE in error_ids:
422+
if "polling request failed for task ID" in error_ids[WLM_TASK_FAILED_ERROR_CODE].lower():
423+
logging.error(f"Got {WLM_TASK_FAILED_ERROR_CODE} error code - polling request failed for task ID, "
424+
f"retrying.")
425+
else:
426+
# If we got this error code, it means that the modeling rules are not valid, exiting install flow.
427+
raise Exception(f"Got [{WLM_TASK_FAILED_ERROR_CODE}] error code - Modeling rules and Dataset validations "
428+
f"failed. Please look at GCP logs to understand why it failed.") from ex
424429

425430
if not attempt: # exhausted all attempts, understand what happened and exit.
426431
if 'timeout awaiting response' in ex.body:
@@ -508,7 +513,7 @@ def search_pack_and_its_dependencies(client: demisto_client,
508513
checked_packs=[pack_id])
509514

510515
except Exception as ex:
511-
logging.error(f"Error: {ex}\n\nStack trace:\n" + traceback.format_exc())
516+
logging.error(f"Error: {ex}\n\nStack trace:\n{traceback.format_exc()}")
512517
SUCCESS_FLAG = False
513518
return
514519

0 commit comments

Comments
 (0)