Skip to content

Commit d1a0a23

Browse files
authored
Adding re-installation (#24471)
1 parent 3edcd3c commit d1a0a23

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

Tests/Marketplace/search_and_install_packs.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,10 @@ def __init__(self, error_msg):
343343
self.error_msg = error_msg
344344
super().__init__()
345345

346-
def call_install_packs_request(packs):
346+
def call_install_packs_request(packs, attempts_count=1):
347347
try:
348-
logging.debug(f'Installing the following packs on server {host}:\n{[pack["id"] for pack in packs]}')
348+
logging.info(f'Installing packs {", ".join([p.get("id") for p in packs_to_install])} on server {host}. '
349+
f'Attempts left on failure: {attempts_count}.')
349350
response_data, status_code, _ = demisto_client.generic_request_func(client,
350351
path='/contentpacks/marketplace/install',
351352
method='POST',
@@ -362,20 +363,25 @@ def call_install_packs_request(packs):
362363

363364
except ApiException as ex:
364365
try:
365-
if 'timeout awaiting response' in ex.body:
366+
if ex.status in [502, 599]:
367+
if attempts_count <= 1:
368+
raise ex
369+
else:
370+
call_install_packs_request(packs, attempts_count - 1)
371+
elif 'timeout awaiting response' in ex.body:
366372
raise GCPTimeOutException(ex.body)
367-
if malformed_ids := find_malformed_pack_id(ex.body):
373+
elif malformed_ids := find_malformed_pack_id(ex.body):
368374
raise MalformedPackException(malformed_ids)
369-
if 'Item not found' in ex.body:
375+
elif 'Item not found' in ex.body:
370376
raise GeneralItemNotFoundError(ex.body)
371-
raise ex
377+
else:
378+
raise ex
372379
except Exception:
373-
logging.debug(f'The error occurred during parsing the install error: {str(ex)}')
380+
logging.debug(f'An error occurred during parsing the install error: {str(ex)}')
374381
raise ex
375382
try:
376-
logging.info(f'Installing packs {", ".join([p.get("id") for p in packs_to_install])} on server {host}')
377383
try:
378-
call_install_packs_request(packs_to_install)
384+
call_install_packs_request(packs_to_install, attempts_count=3)
379385

380386
except MalformedPackException as e:
381387
# 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,
457463

458464
lock.acquire()
459465
if one_pack_and_its_dependencies_in_batch:
460-
batch_packs_install_request_body.append(current_packs_to_install) # type:ignore[union-attr]
466+
pack_and_its_dependencies = {p['id']: p for p in current_packs_to_install}
467+
batch_packs_install_request_body.append(list(pack_and_its_dependencies.values())) # type:ignore[union-attr]
461468
else:
462469
for pack in current_packs_to_install:
463470
if pack['id'] not in packs_to_install:

0 commit comments

Comments
 (0)