Skip to content

Commit

Permalink
Better handling when tape dismount
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikek committed Aug 13, 2024
1 parent dd39d96 commit 48702c0
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions ESSArch_Core/storage/backends/tape.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,21 @@ def lock_or_wait_for_drive(storage_medium, io_lock_key, wait_timeout=10 * 60):
def wait_for_media_transit(storage_medium, wait_timeout=10 * 60):
logger = logging.getLogger('essarch.storage.backends.tape')
timeout_at = time.monotonic() + wait_timeout
while storage_medium.tape_drive.locked:
logger.debug('Storage medium {} ({}) is in transit, sleeps for 5 seconds and checking again'.format(
storage_medium.medium_id, str(storage_medium.pk)))
if time.monotonic() > timeout_at:
raise ValueError("Timeout waiting for transit of storage medium {} ({})".format(
try:

Check warning on line 80 in ESSArch_Core/storage/backends/tape.py

View check run for this annotation

Codecov / codecov/patch

ESSArch_Core/storage/backends/tape.py#L80

Added line #L80 was not covered by tests
while storage_medium.tape_drive.locked:
logger.debug('Storage medium {} ({}) is in transit, sleeps for 5 seconds and checking again'.format(

Check warning on line 82 in ESSArch_Core/storage/backends/tape.py

View check run for this annotation

Codecov / codecov/patch

ESSArch_Core/storage/backends/tape.py#L82

Added line #L82 was not covered by tests
storage_medium.medium_id, str(storage_medium.pk)))
time.sleep(5)
storage_medium.refresh_from_db()
if time.monotonic() > timeout_at:
raise ValueError("Timeout waiting for transit of storage medium {} ({})".format(

Check warning on line 85 in ESSArch_Core/storage/backends/tape.py

View check run for this annotation

Codecov / codecov/patch

ESSArch_Core/storage/backends/tape.py#L85

Added line #L85 was not covered by tests
storage_medium.medium_id, str(storage_medium.pk)))
time.sleep(5)
storage_medium.refresh_from_db()
except AttributeError as e:

Check warning on line 89 in ESSArch_Core/storage/backends/tape.py

View check run for this annotation

Codecov / codecov/patch

ESSArch_Core/storage/backends/tape.py#L87-L89

Added lines #L87 - L89 were not covered by tests
if storage_medium.tape_drive is None:
logger.debug('Storage medium {} ({}) was in transit but is now unmounted'.format(

Check warning on line 91 in ESSArch_Core/storage/backends/tape.py

View check run for this annotation

Codecov / codecov/patch

ESSArch_Core/storage/backends/tape.py#L91

Added line #L91 was not covered by tests
storage_medium.medium_id, str(storage_medium.pk)))
else:
raise e

Check warning on line 94 in ESSArch_Core/storage/backends/tape.py

View check run for this annotation

Codecov / codecov/patch

ESSArch_Core/storage/backends/tape.py#L94

Added line #L94 was not covered by tests

def prepare_for_io(self, storage_medium, io_lock_key=None, wait_timeout=10 * 60):
logger = logging.getLogger('essarch.storage.backends.tape')
Expand Down

0 comments on commit 48702c0

Please sign in to comment.