Skip to content

Commit 971ed19

Browse files
authored
Fix some problems with archive-only behavior (#3497)
* Fix some problems with archive-only behavior PBENCH-1215 Webb pointed out a broken functional test in #3496. Once it was testing what I had wanted it to test, I realized that it wasn't quite working. This contains some server and functional test changes to make archive-only dataset queries work correctly and to be sure that's adequately tested in the functional test cases.
1 parent e119384 commit 971ed19

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

lib/pbench/server/api/resources/query_apis/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,8 @@ def _call(self, method: Callable, params: ApiParams, context: ApiContext):
398398
es_request.get("kwargs").get("json"),
399399
)
400400
except Exception as e:
401+
if isinstance(e, APIAbort):
402+
raise
401403
raise APIInternalError("Elasticsearch assembly error") from e
402404

403405
try:

lib/pbench/server/api/resources/query_apis/datasets/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,16 @@ def get_index(self, dataset: Dataset, root_index_name: AnyStr) -> AnyStr:
118118
"""Retrieve the list of ES indices from the metadata table based on a
119119
given root_index_name.
120120
"""
121+
122+
# Datasets marked "archiveonly" aren't indexed, and can't be referenced
123+
# in APIs that rely on Elasticsearch. Instead, we'll raise a CONFLICT
124+
# error.
125+
if Metadata.getvalue(dataset, Metadata.SERVER_ARCHIVE):
126+
raise APIAbort(HTTPStatus.CONFLICT, "Dataset indexing was disabled")
127+
121128
try:
122129
index_map = Metadata.getvalue(dataset=dataset, key=Metadata.INDEX_MAP)
123130
except MetadataError as exc:
124-
if Metadata.getvalue(dataset, Metadata.SERVER_ARCHIVE):
125-
raise APIAbort(HTTPStatus.CONFLICT, "Dataset is not indexed")
126131
raise APIInternalError(
127132
f"Required metadata {Metadata.INDEX_MAP} missing"
128133
) from exc

lib/pbench/test/functional/server/test_datasets.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ class Tarball:
3232
access: str
3333

3434

35+
def all_tarballs() -> list[Path]:
36+
return list(TARBALL_DIR.glob("*.tar.xz")) + list(SPECIAL_DIR.glob("*.tar.xz"))
37+
38+
3539
class TestPut:
3640
"""Test success and failure cases of PUT dataset upload"""
3741

@@ -198,12 +202,6 @@ def test_archive_only(server_client: PbenchServerClient, login_user):
198202
assert operations["UPLOAD"]["state"] == "OK"
199203
assert "INDEX" not in operations
200204

201-
# Delete it so we can run the test case again without manual cleanup
202-
response = server_client.remove(md5)
203-
assert (
204-
response.ok
205-
), f"delete failed with {response.status_code}, {response.text}"
206-
207205
@staticmethod
208206
def test_no_metadata(server_client: PbenchServerClient, login_user):
209207
"""Test handling for a tarball without a metadata.log.
@@ -248,12 +246,6 @@ def test_no_metadata(server_client: PbenchServerClient, login_user):
248246
assert operations["UPLOAD"]["state"] == "OK"
249247
assert "INDEX" not in operations
250248

251-
# Delete it so we can run the test case again without manual cleanup
252-
response = server_client.remove(md5)
253-
assert (
254-
response.ok
255-
), f"delete failed with {response.status_code}, {response.text}"
256-
257249
@staticmethod
258250
def check_indexed(server_client: PbenchServerClient, datasets):
259251
indexed = []
@@ -402,7 +394,9 @@ def test_details(self, server_client: PbenchServerClient, login_user):
402394
== detail["runMetadata"]["script"]
403395
)
404396
else:
405-
assert response.status_code == HTTPStatus.CONFLICT
397+
assert (
398+
response.status_code == HTTPStatus.CONFLICT
399+
), f"Unexpected {response.json()['message']}"
406400
print(f"\t\t... {d.name} is archiveonly")
407401

408402

@@ -439,7 +433,7 @@ def test_list_api_key(self, server_client: PbenchServerClient, login_user):
439433

440434
expected = [
441435
{"resource_id": Dataset.md5(f), "name": Dataset.stem(f), "metadata": {}}
442-
for f in TARBALL_DIR.glob("*.tar.xz")
436+
for f in all_tarballs()
443437
]
444438
expected.sort(key=lambda e: e["resource_id"])
445439
actual = [d.json for d in datasets]
@@ -583,6 +577,8 @@ def test_contents(self, server_client: PbenchServerClient, login_user):
583577
metadata=["server.archiveonly"],
584578
)
585579

580+
with_toc = False
581+
without_toc = False
586582
for dataset in datasets:
587583
response = server_client.get(
588584
API.DATASETS_CONTENTS,
@@ -591,9 +587,14 @@ def test_contents(self, server_client: PbenchServerClient, login_user):
591587
)
592588
archive = dataset.metadata["server.archiveonly"]
593589
if archive:
594-
assert response.status_code == HTTPStatus.CONFLICT
595-
return
590+
assert (
591+
response.status_code == HTTPStatus.CONFLICT
592+
), f"Unexpected {response.json()['message']}"
593+
assert response.json()["message"] == "Dataset indexing was disabled"
594+
without_toc = True
595+
continue
596596

597+
with_toc = True
597598
assert (
598599
response.ok
599600
), f"CONTENTS {dataset.name} failed {response.status_code}:{response.json()['message']}"
@@ -625,6 +626,7 @@ def test_contents(self, server_client: PbenchServerClient, login_user):
625626
{"dataset": dataset.resource_id, "target": f["name"]},
626627
)
627628
assert f["uri"] == uri, f"{f['name']} uri is incorrect: {f['uri']}"
629+
assert with_toc and without_toc, "expected archiveonly and indexed datasets"
628630

629631
@pytest.mark.dependency(name="visualize", depends=["upload"], scope="session")
630632
def test_visualize(self, server_client: PbenchServerClient, login_user):
@@ -778,7 +780,7 @@ def test_delete_all(self, server_client: PbenchServerClient, login_user):
778780
f"Unexpected HTTP error, url = {exc.response.url}, status code"
779781
f" = {exc.response.status_code}, text = {exc.response.text!r}"
780782
)
781-
for t in TARBALL_DIR.glob("*.tar.xz"):
783+
for t in all_tarballs():
782784
resource_id = datasets_hash.get(t.name)
783785
assert resource_id, f"Expected to find tar ball {t.name} to delete"
784786
response = server_client.remove(resource_id)

0 commit comments

Comments
 (0)