Skip to content

Commit

Permalink
YDA-5924: Copytovault: check if in research space
Browse files Browse the repository at this point in the history
  • Loading branch information
claravox authored and lwesterhof committed Aug 28, 2024
1 parent 09589a5 commit a3467bc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
18 changes: 15 additions & 3 deletions folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions vault_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down

0 comments on commit a3467bc

Please sign in to comment.