diff --git a/Tests/Marketplace/search_and_install_packs.py b/Tests/Marketplace/search_and_install_packs.py index d810f16da4c5..83a31ee68de3 100644 --- a/Tests/Marketplace/search_and_install_packs.py +++ b/Tests/Marketplace/search_and_install_packs.py @@ -343,9 +343,10 @@ def __init__(self, error_msg): self.error_msg = error_msg super().__init__() - def call_install_packs_request(packs): + def call_install_packs_request(packs, attempts_count=1): try: - logging.debug(f'Installing the following packs on server {host}:\n{[pack["id"] for pack in packs]}') + logging.info(f'Installing packs {", ".join([p.get("id") for p in packs_to_install])} on server {host}. ' + f'Attempts left on failure: {attempts_count}.') response_data, status_code, _ = demisto_client.generic_request_func(client, path='/contentpacks/marketplace/install', method='POST', @@ -362,20 +363,25 @@ def call_install_packs_request(packs): except ApiException as ex: try: - if 'timeout awaiting response' in ex.body: + if ex.status in [502, 599]: + if attempts_count <= 1: + raise ex + else: + call_install_packs_request(packs, attempts_count - 1) + elif 'timeout awaiting response' in ex.body: raise GCPTimeOutException(ex.body) - if malformed_ids := find_malformed_pack_id(ex.body): + elif malformed_ids := find_malformed_pack_id(ex.body): raise MalformedPackException(malformed_ids) - if 'Item not found' in ex.body: + elif 'Item not found' in ex.body: raise GeneralItemNotFoundError(ex.body) - raise ex + else: + raise ex except Exception: - logging.debug(f'The error occurred during parsing the install error: {str(ex)}') + logging.debug(f'An error occurred during parsing the install error: {str(ex)}') raise ex try: - logging.info(f'Installing packs {", ".join([p.get("id") for p in packs_to_install])} on server {host}') try: - call_install_packs_request(packs_to_install) + call_install_packs_request(packs_to_install, attempts_count=3) except MalformedPackException as e: # if this is malformed pack error, remove malformed packs and retry until success @@ -457,7 +463,8 @@ def search_pack_and_its_dependencies(client: demisto_client, lock.acquire() if one_pack_and_its_dependencies_in_batch: - batch_packs_install_request_body.append(current_packs_to_install) # type:ignore[union-attr] + pack_and_its_dependencies = {p['id']: p for p in current_packs_to_install} + batch_packs_install_request_body.append(list(pack_and_its_dependencies.values())) # type:ignore[union-attr] else: for pack in current_packs_to_install: if pack['id'] not in packs_to_install: