Skip to content
Snippets Groups Projects
Commit 3f7a50cd authored by Sam Kagan's avatar Sam Kagan
Browse files

Fixed deliver delivering any dir with .ms in it

parent 8feb7f26
No related branches found
No related tags found
No related merge requests found
......@@ -259,7 +259,7 @@ class RestoreProduct(SpooledProduct):
with tarfile.open(auxproducts_paths[0], mode="r:gz") as auxproducts_tar:
for member in auxproducts_tar.getmembers():
for filename_regex in self.AUXPRODUCTS_FILENAME_REGEXES:
if re.match(filename_regex, member.name) is not None:
if re.fullmatch(filename_regex, member.name) is not None:
# tarfile library recommends using extractall even for individual members
# Source: https://docs.python.org/3.10/library/tarfile.html#tarfile.TarFile.extract
auxproducts_tar.extractall(path=auxproducts_paths[0].parent, members=[member])
......@@ -272,7 +272,7 @@ class RestoreProduct(SpooledProduct):
for subdir, filename_regexes in self.SUBDIR_FILENAME_REGEXES.items():
for file in (self.path / subdir).iterdir():
for filename_regex in filename_regexes:
if re.match(filename_regex, file.name) is not None:
if re.fullmatch(filename_regex, file.name) is not None:
pipedir.add_path_entry(
file, self._get_delivered_filename(file.name, filename_regex == self.WEBLOG_REGEX, subdir)
)
......
......@@ -35,6 +35,9 @@ def assert_restore_delivered_only_expected_files(
expected_files: set[pathlib.Path],
expected_dirs_to_file_counts: Counter[str],
actual_files_to_is_file: Optional[dict[pathlib.Path, bool]] = None,
# These are parts of the delivery path, so they'll show up as directories in the CLI tests' actual_files
project_code: Optional[str] = None,
pipeline_spec: Optional[str] = None,
):
"""Assert that exactly the expected files were delivered
......@@ -56,8 +59,18 @@ def assert_restore_delivered_only_expected_files(
assert actual_dirs_to_file_counts == expected_dirs_to_file_counts
# did we not get any unexpected files?
# Don't care about any paths inside of the expected directories, just how many there are (checked above)
is_path_in_an_expected_dir: Callable[[pathlib.Path], bool] = lambda filepath: any(
Path(expected_dir) in filepath.parents for expected_dir in expected_dirs_to_file_counts.keys()
)
for filepath in actual_files:
if filepath.is_file():
assert filepath in expected_files or any(
str(filepath).startswith(expected_dir) for expected_dir in expected_dirs_to_file_counts.keys()
if actual_is_file(filepath):
assert filepath in expected_files or is_path_in_an_expected_dir(filepath)
else:
# breakpoint()
assert (
str(filepath) in expected_dirs_to_file_counts.keys()
or (project_code is not None and filepath.name == project_code)
or (pipeline_spec is not None and filepath.name == pipeline_spec)
or is_path_in_an_expected_dir(filepath)
)
......@@ -120,7 +120,13 @@ def test_local_restore_no_tar(restore_directory: pathlib.Path, tmpdir_factory, c
expected_files.add(pathlib.Path(temp_directory + "/SHA1SUMS"))
expected_files = {pathlib.Path(file).resolve() for file in expected_files}
actual_files = list(p.resolve() for p in pathlib.Path(temp_directory).rglob("*"))
assert_restore_delivered_only_expected_files(actual_files, expected_files, expected_dirs_to_file_counts)
assert_restore_delivered_only_expected_files(
actual_files,
expected_files,
expected_dirs_to_file_counts,
project_code=TEST_RESTORE_METADATA.project_code,
pipeline_spec=TEST_RESTORE_METADATA.pipeline_spec,
)
# ensure that we actually got a delivery file with the proper contents
with open("delivery.json", "r") as delivery_results_file:
......@@ -154,7 +160,13 @@ def test_local_restore_no_tar_with_flagtemplate(
expected_files.add(pathlib.Path(dest_dir + "/SHA1SUMS"))
expected_files = {pathlib.Path(file).resolve() for file in expected_files}
actual_files = list(p.resolve() for p in pathlib.Path(dest_dir).rglob("*"))
assert_restore_delivered_only_expected_files(actual_files, expected_files, expected_dirs_to_file_counts)
assert_restore_delivered_only_expected_files(
actual_files,
expected_files,
expected_dirs_to_file_counts,
project_code=TEST_RESTORE_METADATA.project_code,
pipeline_spec=TEST_RESTORE_METADATA.pipeline_spec,
)
# ensure that we actually got a delivery file with the proper contents
with open("delivery.json", "r") as delivery_results_file:
......@@ -219,7 +231,13 @@ def test_local_restore_with_tar(restore_directory: pathlib.Path, tmpdir_factory,
expected_files, expected_dirs_to_filecounts = get_expected_files_and_dirs_for_restore(
str(extraction_dir / TEST_RESTORE_METADATA.project_code / TEST_RESTORE_METADATA.pipeline_spec)
)
assert_restore_delivered_only_expected_files(actual_files, expected_files, expected_dirs_to_filecounts)
assert_restore_delivered_only_expected_files(
actual_files,
expected_files,
expected_dirs_to_filecounts,
project_code=TEST_RESTORE_METADATA.project_code,
pipeline_spec=TEST_RESTORE_METADATA.pipeline_spec,
)
with open("delivery.json", "r") as delivery_results_file:
results = json.load(delivery_results_file)
......
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