diff --git a/lib/pbench/server/api/resources/intake_base.py b/lib/pbench/server/api/resources/intake_base.py index c98d629849..a3cb2fd8c9 100644 --- a/lib/pbench/server/api/resources/intake_base.py +++ b/lib/pbench/server/api/resources/intake_base.py @@ -23,12 +23,7 @@ ApiSchema, ) import pbench.server.auth.auth as Auth -from pbench.server.cache_manager import ( - BadDirpath, - CacheManager, - DuplicateTarball, - MetadataError, -) +from pbench.server.cache_manager import CacheManager, DuplicateTarball, MetadataError from pbench.server.database.models.audit import ( Audit, AuditReason, @@ -383,11 +378,6 @@ def _intake( # Move the files to their final location try: tarball = cache_m.create(tar_full_path) - except BadDirpath as exc: - raise APIAbort( - HTTPStatus.BAD_REQUEST, - exc, - ) from exc except DuplicateTarball as exc: raise APIAbort( HTTPStatus.BAD_REQUEST, diff --git a/lib/pbench/server/cache_manager.py b/lib/pbench/server/cache_manager.py index 11946faf59..21b52f5ea0 100644 --- a/lib/pbench/server/cache_manager.py +++ b/lib/pbench/server/cache_manager.py @@ -496,7 +496,7 @@ def _get_metadata(tarball_path: Path) -> Optional[JSONOBJECT]: return None else: metadata_log = MetadataLog() - metadata_log.read_file(data) + metadata_log.read_file(e.decode() for e in data) metadata = {s: dict(metadata_log.items(s)) for s in metadata_log.sections()} return metadata diff --git a/lib/pbench/test/unit/server/test_cache_manager.py b/lib/pbench/test/unit/server/test_cache_manager.py index b21795d629..5f4f065da3 100644 --- a/lib/pbench/test/unit/server/test_cache_manager.py +++ b/lib/pbench/test/unit/server/test_cache_manager.py @@ -896,8 +896,8 @@ def test_filestream( with monkeypatch.context() as m: m.setattr(Tarball, "__init__", TestCacheManager.MockTarball.__init__) m.setattr(Controller, "__init__", TestCacheManager.MockController.__init__) - m.setattr(Tarball, "extract", lambda _s, _t: exp_stream) - m.setattr(Path, "open", lambda _s, _m: exp_stream) + m.setattr(Tarball, "extract", lambda _t, _p: exp_stream) + m.setattr(Path, "open", lambda _s, _m="rb": exp_stream) tb = Tarball(tar, Controller(Path("/mock/archive"), cache, None)) tar_dir = TestCacheManager.MockController.generate_test_result_tree( tmp_path, "dir_name" diff --git a/lib/pbench/test/unit/server/test_datasets_inventory.py b/lib/pbench/test/unit/server/test_datasets_inventory.py index 26f9d6641c..13011839c7 100644 --- a/lib/pbench/test/unit/server/test_datasets_inventory.py +++ b/lib/pbench/test/unit/server/test_datasets_inventory.py @@ -48,7 +48,6 @@ def __init__(self, path: Path, controller: Controller): self.unpacked = None def filestream(self, target): - print("FS") info = { "name": "f1.json", "type": CacheType.FILE, @@ -109,8 +108,12 @@ def test_not_a_file(self, query_get_as, monkeypatch): } def test_dataset_in_given_path(self, query_get_as, monkeypatch): + class MockBytesIO(io.BytesIO): + def close(self): + super().close() + mock_args: Optional[tuple[Path, dict[str, Any]]] = None - exp_stream = io.BytesIO(b"file_as_a_byte_stream") + exp_stream = MockBytesIO(b"file_as_a_byte_stream") filestream_dict = { "name": "f1.json", "type": CacheType.FILE,