From a3467bc49d7444fcf2865eee86a4f54b7b0b2bb4 Mon Sep 17 00:00:00 2001 From: claravox Date: Tue, 27 Aug 2024 14:33:15 +0200 Subject: [PATCH] YDA-5924: Copytovault: check if in research space --- folder.py | 18 +++++++++++++++--- vault_archive.py | 4 ++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/folder.py b/folder.py index f5ad0dd43..6cb88a9dd 100644 --- a/folder.py +++ b/folder.py @@ -204,6 +204,7 @@ def precheck_folder_secure(ctx, coll): found, last_run = get_last_run_time(ctx, coll) if (not correct_copytovault_start_status(ctx, coll) + or not correct_copytovault_start_location(coll) or not misc.last_run_time_acceptable(coll, found, last_run, config.vault_copy_backoff_time)): return False @@ -318,6 +319,18 @@ def correct_copytovault_start_status(ctx, coll): return False +def correct_copytovault_start_location(coll): + """Confirm that the folder to be copied is in the correct location. + For example: in a research or deposit folder and not in the trash. + + :param coll: Source collection (folder being secured) + + :returns: True when a valid start location + """ + space, _, _, _ = pathutil.info(coll) + return space in (pathutil.Space.RESEARCH, pathutil.Space.DEPOSIT) + + def get_last_run_time(ctx, coll): """Get the last run time, if found""" found = False @@ -420,9 +433,8 @@ def folder_secure_set_retry(ctx, coll): if new_retry_count > config.vault_copy_max_retries: folder_secure_fail(ctx, coll) send_folder_secure_notification(ctx, coll, "Data package failed to copy to vault after maximum retries") - else: - if not folder_secure_set_retry_avus(ctx, coll, new_retry_count): - send_folder_secure_notification(ctx, coll, "Failed to set retry state on data package") + elif not folder_secure_set_retry_avus(ctx, coll, new_retry_count): + send_folder_secure_notification(ctx, coll, "Failed to set retry state on data package") def folder_secure_set_retry_avus(ctx, coll, retry_count): diff --git a/vault_archive.py b/vault_archive.py index 4794b1b1f..893d67b56 100644 --- a/vault_archive.py +++ b/vault_archive.py @@ -134,11 +134,11 @@ def create_archive(ctx, coll): def extract_archive(ctx, coll): while True: state = ctx.dmattr(package_archive_path(ctx, coll), config.data_package_archive_fqdn, "")["arguments"][2] - if state != "UNM" and state != "MIG": + if state not in ("UNM", "MIG"): break time.sleep(10) - if state != "DUL" and state != "REG" and state != "INV": + if state not in ("DUL", "REG", "INV"): log.write(ctx, "Archive of data package <{}> is not available, state is <{}>".format(coll, state)) raise Exception("Archive is not available")