Skip to content

Commit

Permalink
feat: add openBIS test connection
Browse files Browse the repository at this point in the history
  • Loading branch information
olloz26 committed Sep 5, 2024
1 parent 675e621 commit 06cede5
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
18 changes: 15 additions & 3 deletions components/renku_data_services/storage/rclone.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,16 @@ def validate_sensitive_data(
continue
raise errors.ValidationError(message=f"The '{key}' property is not marked as sensitive.")

def get_real_config(self, configuration: Union["RCloneConfig", dict[str, Any]]) -> dict[str, Any]:
"""Converts a Renku rclone configuration to a real rclone config."""
real_config = dict(configuration)
if configuration["type"] == "openbis":
real_config["type"] = "sftp"
real_config["port"] = "2222"
real_config["user"] = "?"
real_config["pass"] = real_config.pop("session_token")
return real_config

async def test_connection(
self, configuration: Union["RCloneConfig", dict[str, Any]], source_path: str
) -> ConnectionResult:
Expand All @@ -255,15 +265,17 @@ async def test_connection(
except errors.ValidationError as e:
return ConnectionResult(False, str(e))

obscured_config = await self.obscure_config(configuration)
obscured_rclone_config = await self.obscure_config(self.get_real_config(configuration))

with tempfile.NamedTemporaryFile(mode="w+", delete=False, encoding="utf-8") as f:
config = "\n".join(f"{k}={v}" for k, v in obscured_config.items())
f.write(f"[temp]\n{config}")
obscured_rclone_config_string = "\n".join(f"{k}={v}" for k, v in obscured_rclone_config.items())
f.write(f"[temp]\n{obscured_rclone_config_string}")
f.close()
proc = await asyncio.create_subprocess_exec(
"rclone",
"lsf",
"--low-level-retries=1", # Connection tests should fail fast.
"--retries=1", # Connection tests should fail fast.
"--config",
f.name,
f"temp:{source_path}",
Expand Down
36 changes: 35 additions & 1 deletion test/bases/renku_data_services/data_api/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from renku_data_services.data_api.app import register_all_handlers
from renku_data_services.migrations.core import run_migrations_for_app
from renku_data_services.storage.rclone import RCloneValidator
from renku_data_services.utils.core import get_openbis_session_token

_valid_storage: dict[str, Any] = {
"project_id": "123456",
Expand Down Expand Up @@ -525,7 +526,7 @@ async def test_storage_validate_connection(storage_test_client) -> None:
_, res = await storage_test_client.post("/api/data/storage_schema/test_connection", data=json.dumps(body))
assert res.status_code == 422

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

Expand All @@ -534,6 +535,39 @@ async def test_storage_validate_connection(storage_test_client) -> None:
assert res.status_code == 204


@pytest.mark.myskip(1 == 1, reason="Depends on a remote openBIS host which may not always be available.")
@pytest.mark.asyncio
async def test_openbis_storage_validate_connection(storage_test_client) -> None:
openbis_session_token = await get_openbis_session_token(
host="openbis-eln-lims.ethz.ch", # Public openBIS demo instance.
username="observer",
password="1234",
)
storage_test_client, _ = storage_test_client

body = {
"configuration": {
"type": "openbis",
"host": "openbis-eln-lims.ethz.ch",
"session_token": openbis_session_token,
},
"source_path": "does_not_exist_at_all/",
}
_, res = await storage_test_client.post("/api/data/storage_schema/test_connection", data=json.dumps(body))
assert res.status_code == 422

body = {
"configuration": {
"type": "openbis",
"host": "openbis-eln-lims.ethz.ch",
"session_token": openbis_session_token,
},
"source_path": "/",
}
_, res = await storage_test_client.post("/api/data/storage_schema/test_connection", data=json.dumps(body))
assert res.status_code == 204


@pytest.mark.asyncio
async def test_storage_validate_error(storage_test_client) -> None:
storage_test_client, _ = storage_test_client
Expand Down

0 comments on commit 06cede5

Please sign in to comment.