From b696c016d099d1dcf14994842a8f037f413074e1 Mon Sep 17 00:00:00 2001 From: Henrik Ek Date: Tue, 13 Aug 2024 23:32:02 +0200 Subject: [PATCH] Better handling when tape dismount (#2323) * Better handling when tape dismount * Migrate to Compose V2 --- .github/workflows/main.yml | 2 +- ESSArch_Core/storage/backends/tape.py | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 241942745..e2d2bcdd5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -155,7 +155,7 @@ jobs: - name: Build run: | cd docker - docker-compose build essarch + docker compose build essarch test-windows: runs-on: windows-latest diff --git a/ESSArch_Core/storage/backends/tape.py b/ESSArch_Core/storage/backends/tape.py index 624c840db..b84468a6f 100644 --- a/ESSArch_Core/storage/backends/tape.py +++ b/ESSArch_Core/storage/backends/tape.py @@ -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: + 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))) - time.sleep(5) - storage_medium.refresh_from_db() + if time.monotonic() > timeout_at: + raise ValueError("Timeout waiting for transit of storage medium {} ({})".format( + storage_medium.medium_id, str(storage_medium.pk))) + time.sleep(5) + storage_medium.refresh_from_db() + except AttributeError as e: + if storage_medium.tape_drive is None: + logger.debug('Storage medium {} ({}) was in transit but is now unmounted'.format( + storage_medium.medium_id, str(storage_medium.pk))) + else: + raise e def prepare_for_io(self, storage_medium, io_lock_key=None, wait_timeout=10 * 60): logger = logging.getLogger('essarch.storage.backends.tape')