Skip to content

Adding re-installation #24471

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Feb 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions Tests/Marketplace/search_and_install_packs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down