Skip to content
Snippets Groups Projects
Commit 5fc93c41 authored by Charlotte Hausman's avatar Charlotte Hausman
Browse files

fix tests

parent 9354c4d2
No related branches found
No related tags found
3 merge requests!1606catch 2.8.3 up with main,!1605Merge 2.8.2.3 work to main,!1601don't create artifacts tars for curation
Pipeline #14673 passed
...@@ -440,12 +440,18 @@ class IngestionManifestBuilder: ...@@ -440,12 +440,18 @@ class IngestionManifestBuilder:
destination_dir=self.manifest_destination_dir, destination_dir=self.manifest_destination_dir,
) )
artifacts_ap = self._build_artifacts_product() if is_full_curation:
# find the existing artifacts tar file name
artifacts_ap = self._find_existing_record(self.files_found)
else:
# build new artifacts tar
artifacts_ap = self._build_artifacts_product()
if artifacts_ap not in manifest.output_group.ancillary_products: if artifacts_ap not in manifest.output_group.ancillary_products:
manifest.output_group.ancillary_products.append(artifacts_ap) manifest.output_group.ancillary_products.append(artifacts_ap)
manifest_file = manifest.write() manifest_file = manifest.write()
if not self.curation_type: if not is_full_curation:
# curator doesn't need a new artifacts tar, skip it. # we're running initial ingestion, make a new artifacts tar
self.write_ingestion_artifacts_tar(self.manifest_destination_dir / artifacts_ap.filename) self.write_ingestion_artifacts_tar(self.manifest_destination_dir / artifacts_ap.filename)
return manifest, manifest_file return manifest, manifest_file
...@@ -550,6 +556,18 @@ class IngestionManifestBuilder: ...@@ -550,6 +556,18 @@ class IngestionManifestBuilder:
AncillaryProductType.INGESTION_ARTIFACTS, IngestionManifestBuilder._build_artifacts_filename() AncillaryProductType.INGESTION_ARTIFACTS, IngestionManifestBuilder._build_artifacts_filename()
) )
@staticmethod
def _find_existing_record(available_files: list) -> AncillaryProduct:
"""
Find an existing artifacts tar for curation
:param available_files: existing files list
:return: Ancillary Product of existing tar
"""
for file in available_files:
if INGESTION_ARTIFACTS_NAME in file.name:
return AncillaryProduct(AncillaryProductType.INGESTION_ARTIFACTS, file.name)
def write_ingestion_artifacts_tar(self, artifacts_path: Path) -> tarfile.TarFile: def write_ingestion_artifacts_tar(self, artifacts_path: Path) -> tarfile.TarFile:
""" """
Take the list of files and write a tar file for inclusion in the archive. Take the list of files and write a tar file for inclusion in the archive.
......
...@@ -244,6 +244,9 @@ def populate_fake_tmpx_ratuqh_ingest_path( ...@@ -244,6 +244,9 @@ def populate_fake_tmpx_ratuqh_ingest_path(
fake_files_to_create.append(OUTPUT_SCIENCE_PRODUCT_K.filename) fake_files_to_create.append(OUTPUT_SCIENCE_PRODUCT_K.filename)
fake_files_to_create.append(OUTPUT_SCIENCE_PRODUCT_X.filename) fake_files_to_create.append(OUTPUT_SCIENCE_PRODUCT_X.filename)
if is_for_curation_test:
fake_files_to_create.append(INGESTION_AF_ANCILLARY.filename)
files = [] files = []
for filename in fake_files_to_create: for filename in fake_files_to_create:
file = staging_source_dir / filename file = staging_source_dir / filename
...@@ -321,9 +324,8 @@ def find_ingestion_artifacts_tar(staging_source_dir: Path): ...@@ -321,9 +324,8 @@ def find_ingestion_artifacts_tar(staging_source_dir: Path):
if file.name.startswith(AncillaryProductType.INGESTION_ARTIFACTS.value) and file.name.endswith(TARFILE_EXT) if file.name.startswith(AncillaryProductType.INGESTION_ARTIFACTS.value) and file.name.endswith(TARFILE_EXT)
] ]
if len(ing_artifacts_tars) == 0: if len(ing_artifacts_tars) == 0:
# curation currently has no need of artifacts tars # we're testing curation, no new tar in directory
# assertions handled in calling test return None
return ing_artifacts_tars
# otherwise ensure there is only 1 tar file present # otherwise ensure there is only 1 tar file present
assert len(ing_artifacts_tars) == 1 assert len(ing_artifacts_tars) == 1
return ing_artifacts_tars[0] return ing_artifacts_tars[0]
...@@ -299,16 +299,14 @@ def test_manifest_full_curation_image(use_file_list: bool, ingest_path: Path, al ...@@ -299,16 +299,14 @@ def test_manifest_full_curation_image(use_file_list: bool, ingest_path: Path, al
assert weblog_candidates[0].type == AncillaryProductType.PIPELINE_WEBLOG assert weblog_candidates[0].type == AncillaryProductType.PIPELINE_WEBLOG
ingest_artifacts_tar = find_ingestion_artifacts_tar(manifest_destination_dir) ingest_artifacts_tar = find_ingestion_artifacts_tar(manifest_destination_dir)
assert len(ingest_artifacts_tar) == 0 if use_file_list:
# assert ingest_artifacts_candidates[0].type == AncillaryProductType.INGESTION_ARTIFACTS # there is not a file on disk, but we know it exists for this product
# """ assert ingest_artifacts_tar is None
# The ingestion_artifacts tar should contain ONLY the ingestion manifest else:
# """ # We are running with a real directory and there should be an artifacts tar available
# with tarfile.open(ingest_artifacts_tar, "r") as tar: ingest_artifacts_candidates = [ap for ap in aps if ap.filename == ingest_artifacts_tar.name]
# members = tar.getmembers() assert len(ingest_artifacts_candidates) == 1
# assert len(members) == 1 assert ingest_artifacts_candidates[0].type == AncillaryProductType.INGESTION_ARTIFACTS
# for member in members:
# assert member.name.endswith(CURATOR_MANIFEST_FILENAME)
# Inspect the manifest's JSON dict # Inspect the manifest's JSON dict
""" """
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment