Skip to content

Commit 782dcff

Browse files
committed
feat: add openBIS test connection
1 parent 7ecbe77 commit 782dcff

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

components/renku_data_services/storage/rclone.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,16 @@ def validate_sensitive_data(
361361
continue
362362
raise errors.ValidationError(message=f"The '{key}' property is not marked as sensitive.")
363363

364+
def get_real_config(self, configuration: Union["RCloneConfig", dict[str, Any]]) -> dict[str, Any]:
365+
"""Converts a Renku rclone configuration to a real rclone config."""
366+
real_config = dict(configuration)
367+
if configuration["type"] == "openbis":
368+
real_config["type"] = "sftp"
369+
real_config["port"] = "2222"
370+
real_config["user"] = "?"
371+
real_config["pass"] = real_config.pop("session_token")
372+
return real_config
373+
364374
async def test_connection(
365375
self, configuration: Union["RCloneConfig", dict[str, Any]], source_path: str
366376
) -> ConnectionResult:
@@ -371,7 +381,7 @@ async def test_connection(
371381
return ConnectionResult(False, str(e))
372382

373383
# Obscure configuration and transform if needed
374-
obscured_config = await self.obscure_config(configuration)
384+
obscured_config = await self.obscure_config(self.get_real_config(configuration))
375385
transformed_config = self.transform_polybox_switchdriver_config(obscured_config)
376386

377387
with tempfile.NamedTemporaryFile(mode="w+", delete=False, encoding="utf-8") as f:
@@ -381,6 +391,8 @@ async def test_connection(
381391
proc = await asyncio.create_subprocess_exec(
382392
"rclone",
383393
"lsf",
394+
"--low-level-retries=1", # Connection tests should fail fast.
395+
"--retries=1", # Connection tests should fail fast.
384396
"--config",
385397
f.name,
386398
f"temp:{source_path}",

test/bases/renku_data_services/data_api/test_storage.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from renku_data_services.data_api.app import register_all_handlers
1212
from renku_data_services.migrations.core import run_migrations_for_app
1313
from renku_data_services.storage.rclone import RCloneValidator
14+
from renku_data_services.utils.core import get_openbis_session_token
1415
from test.utils import SanicReusableASGITestClient
1516

1617
_valid_storage: dict[str, Any] = {
@@ -538,7 +539,7 @@ async def test_storage_validate_connection(storage_test_client) -> None:
538539
_, res = await storage_test_client.post("/api/data/storage_schema/test_connection", data=json.dumps(body))
539540
assert res.status_code == 422
540541

541-
body = {"configuration": {"type": "s3", "provider": "AWS"}, "source_path": "doesntexistatall/"}
542+
body = {"configuration": {"type": "s3", "provider": "AWS"}, "source_path": "does_not_exist_at_all/"}
542543
_, res = await storage_test_client.post("/api/data/storage_schema/test_connection", data=json.dumps(body))
543544
assert res.status_code == 422
544545

@@ -547,6 +548,39 @@ async def test_storage_validate_connection(storage_test_client) -> None:
547548
assert res.status_code == 204
548549

549550

551+
@pytest.mark.myskip(1 == 1, reason="Depends on a remote openBIS host which may not always be available.")
552+
@pytest.mark.asyncio
553+
async def test_openbis_storage_validate_connection(storage_test_client) -> None:
554+
openbis_session_token = await get_openbis_session_token(
555+
host="openbis-eln-lims.ethz.ch", # Public openBIS demo instance.
556+
username="observer",
557+
password="1234",
558+
)
559+
storage_test_client, _ = storage_test_client
560+
561+
body = {
562+
"configuration": {
563+
"type": "openbis",
564+
"host": "openbis-eln-lims.ethz.ch",
565+
"session_token": openbis_session_token,
566+
},
567+
"source_path": "does_not_exist_at_all/",
568+
}
569+
_, res = await storage_test_client.post("/api/data/storage_schema/test_connection", data=json.dumps(body))
570+
assert res.status_code == 422
571+
572+
body = {
573+
"configuration": {
574+
"type": "openbis",
575+
"host": "openbis-eln-lims.ethz.ch",
576+
"session_token": openbis_session_token,
577+
},
578+
"source_path": "/",
579+
}
580+
_, res = await storage_test_client.post("/api/data/storage_schema/test_connection", data=json.dumps(body))
581+
assert res.status_code == 204
582+
583+
550584
@pytest.mark.asyncio
551585
async def test_storage_validate_error(storage_test_client) -> None:
552586
storage_test_client, _ = storage_test_client

0 commit comments

Comments
 (0)