Skip to content

Commit

Permalink
Select -> Fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
mephenor committed Oct 1, 2024
1 parent 94b0708 commit 2732f9f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/ghga_datasteward_kit/file_ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@ def file_ingest(
output_metadata = models.OutputMetadata.load(
input_path=in_path,
selected_alias=config.selected_storage_alias,
selected_bucket=config.fallback_bucket_id,
fallback_bucket=config.fallback_bucket_id,
)
endpoint = config.file_ingest_federated_endpoint
LOG.info("Selected non-legacy endpoint %s for file %s.", endpoint, in_path)
except (KeyError, ValidationError):
output_metadata = models.LegacyOutputMetadata.load(
input_path=in_path,
selected_alias=config.selected_storage_alias,
selected_bucket=config.fallback_bucket_id,
fallback_bucket=config.fallback_bucket_id,
)
endpoint = config.file_ingest_legacy_endpoint
LOG.info("Selected legacy endpoint %s for file %s.", endpoint, in_path)
Expand Down
12 changes: 6 additions & 6 deletions src/ghga_datasteward_kit/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def serialize(self, output_path: Path):
os.chmod(path=output_path, mode=0o400)

@classmethod
def load(cls, input_path: Path, selected_alias: str, selected_bucket: str):
def load(cls, input_path: Path, selected_alias: str, fallback_bucket: str):
"""Load metadata from serialized file"""
with input_path.open("r") as infile:
data = json.load(infile)
Expand All @@ -149,9 +149,9 @@ def load(cls, input_path: Path, selected_alias: str, selected_bucket: str):
except KeyError:
LOG.warning(
"Could not find bucket ID in metadata, populating with configured bucket '%s' instead.",
selected_bucket,
fallback_bucket,
)
bucket_id = selected_bucket
bucket_id = fallback_bucket

file_id = data["File UUID"]
part_size = int(data["Part Size"].rpartition(" MiB")[0]) * 1024**2
Expand Down Expand Up @@ -225,7 +225,7 @@ def serialize(self, output_path: Path):
os.chmod(path=output_path, mode=0o400)

@classmethod
def load(cls, input_path: Path, selected_alias: str, selected_bucket: str):
def load(cls, input_path: Path, selected_alias: str, fallback_bucket: str):
"""Load metadata from serialized file"""
with input_path.open("r") as infile:
data = json.load(infile)
Expand All @@ -245,9 +245,9 @@ def load(cls, input_path: Path, selected_alias: str, selected_bucket: str):
except KeyError:
LOG.warning(
"Could not find bucket ID in metadata, populating with configured bucket '%s' instead.",
selected_bucket,
fallback_bucket,
)
bucket_id = selected_bucket
bucket_id = fallback_bucket

file_id = data["File UUID"]
part_size = int(data["Part Size"].rpartition(" MiB")[0]) * 1024**2
Expand Down
6 changes: 3 additions & 3 deletions tests/fixtures/ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
)

SELECTED_STORAGE_ALIAS = "test"
SELECTED_BUCKET_ID = "selected-test-bucket"
FALLBACK_BUCKET_ID = "fallback-test-bucket"


@dataclass
Expand Down Expand Up @@ -100,7 +100,7 @@ def legacy_ingest_fixture() -> Generator[IngestFixture, None, None]:
map_files_fields=["study_files"],
submission_store_dir=Path(submission_store_dir),
selected_storage_alias=SELECTED_STORAGE_ALIAS,
fallback_bucket_id=SELECTED_BUCKET_ID,
fallback_bucket_id=FALLBACK_BUCKET_ID,
)

submission_store = SubmissionStore(config=config)
Expand Down Expand Up @@ -151,7 +151,7 @@ def ingest_fixture() -> Generator[IngestFixture, None, None]:
map_files_fields=["study_files"],
submission_store_dir=Path(submission_store_dir),
selected_storage_alias=SELECTED_STORAGE_ALIAS,
fallback_bucket_id=SELECTED_BUCKET_ID,
fallback_bucket_id=FALLBACK_BUCKET_ID,
)

submission_store = SubmissionStore(config=config)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_file_ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async def test_alias_to_accession(legacy_ingest_fixture: IngestFixture): # noqa
metadata = models.LegacyOutputMetadata.load(
input_path=legacy_ingest_fixture.file_path,
selected_alias=legacy_ingest_fixture.config.selected_storage_alias,
selected_bucket=legacy_ingest_fixture.config.fallback_bucket_id,
fallback_bucket=legacy_ingest_fixture.config.fallback_bucket_id,
)

accession = alias_to_accession(
Expand Down Expand Up @@ -234,7 +234,7 @@ def test_fallbacks(
metadata = metadata_model.load( # type: ignore[attr-defined]
input_path=modified_metadata_path,
selected_alias=storage_alias,
selected_bucket=bucket_id,
fallback_bucket=bucket_id,
)
assert metadata.bucket_id == bucket_id
assert metadata.storage_alias == storage_alias

0 comments on commit 2732f9f

Please sign in to comment.