Skip to content

Commit

Permalink
implement storage list and add rudimentary test
Browse files Browse the repository at this point in the history
  • Loading branch information
Panaetius committed Sep 28, 2023
1 parent 64ca6b2 commit 1ab5953
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 23 deletions.
22 changes: 8 additions & 14 deletions renku/command/format/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,8 @@
def tabular(cloud_storages: List[CloudStorage], *, columns: Optional[str] = None):
"""Format cloud_storages with a tabular output."""
if not columns:
columns = "id,start_time,status,provider,url"

if any(s.ssh_enabled for s in cloud_storages):
columns += ",ssh"

return tabulate(collection=cloud_storages, columns=columns, columns_mapping=cloud_storage_COLUMNS)
columns = "id,name,private,type"
return tabulate(collection=cloud_storages, columns=columns, columns_mapping=CLOUD_STORAGE_COLUMNS)


def log(cloud_storages: List[CloudStorage], *, columns: Optional[str] = None):
Expand All @@ -54,12 +50,10 @@ def log(cloud_storages: List[CloudStorage], *, columns: Optional[str] = None):
"""Valid formatting options."""

CLOUD_STORAGE_COLUMNS = {
"id": ("id", "id"),
"status": ("status", "status"),
"url": ("url", "url"),
"ssh": ("ssh_enabled", "SSH enabled"),
"start_time": ("start_time", "start_time"),
"commit": ("commit", "commit"),
"branch": ("branch", "branch"),
"provider": ("provider", "provider"),
"id": ("storage_id", "id"),
"name": ("name", "name"),
"source_path": ("source_path", "source path"),
"target_path": ("target_path", "target path"),
"private": ("private", "private"),
"type": ("storage_type", "type"),
}
3 changes: 2 additions & 1 deletion renku/command/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Cloud storage commands."""
from renku.command.command_builder.command import Command


def list_storage_command():
"""Command to list configured cloud storage."""
from renku.core.storage import list_storage

return Command().command(list_storage).require_login().with_database()
return Command().command(list_storage).with_database().require_login().with_gitlab_api().with_storage_api()
2 changes: 1 addition & 1 deletion renku/core/session/renkulab.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def get_cloudstorage(self):
continue
field = next(f for f in private_fields if f["name"] == name)

secret = communication.prompt(f"{field['help']}\nPlease provide a value for secret '{name}':")
secret = communication.prompt(f"{field['help']}\nPlease provide a value for secret '{name}'")
storage.configuration[name] = secret

storages_to_mount.append({"storage_id": storage.storage_id, "configuration": storage.configuration})
Expand Down
2 changes: 1 addition & 1 deletion renku/core/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@
def list_storage(storage_service: IStorageService):
"""List configured cloud storage for project."""
project_id = storage_service.project_id
storages = storage_service.ls(project_id)
storages = storage_service.list(project_id)
return storages
6 changes: 4 additions & 2 deletions renku/ui/cli/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ def ls(columns, format):
"""List configured cloud storage for a project."""
from renku.command.storage import list_storage_command

storages = list_storage_command().build().execute()
result = list_storage_command().build().execute()

click.echo(STORAGE_FORMATS[format](storages.output, columns=columns))
storages = [s.storage for s in result.output]

click.echo(CLOUD_STORAGE_FORMATS[format](storages, columns=columns))


# =============================================
Expand Down
2 changes: 1 addition & 1 deletion renku/ui/service/views/v1/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def migration_check_project_view_1_5(user_data, cache):
from renku.ui.service.serializers.rpc import JsonRPCResponse
from renku.ui.service.views.error_handlers import pretty_print_error

ctrl = MigrationsCheckCtrl(cache, user_data, dict(request.args), GitlabAPIProvider())
ctrl = MigrationsCheckCtrl(cache, user_data, dict(request.args), GitlabAPIProvider)

if "project_id" in ctrl.context: # type: ignore
result = ctrl.execute_op()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#
# Copyright 2017-2023 - Swiss Data Science Center (SDSC)
# Copyright Swiss Data Science Center (SDSC)
# A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and
# Eidgenössische Technische Hochschule Zürich (ETHZ).
#
Expand All @@ -14,7 +13,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Storage command tests."""
"""LFS command tests."""

import os
import subprocess
Expand Down
56 changes: 56 additions & 0 deletions tests/core/test_storage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright Swiss Data Science Center (SDSC)
# A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and
# Eidgenössische Technische Hochschule Zürich (ETHZ).
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Tests for storage service."""

from unittest.mock import MagicMock

import renku.infrastructure.storage.storage_service as storage_service
from renku.command.command_builder.command import inject, remove_injector
from renku.core.interface.git_api_provider import IGitAPIProvider


def test_storage_service_list(monkeypatch):
"""Test listing storage."""
inject.configure(lambda binder: binder.bind(IGitAPIProvider, MagicMock()), bind_in_runtime=False)

try:
with monkeypatch.context() as monkey:

def _send_request(*_, **__):
return [
{
"storage": {
"storage_id": "ABCDEFG",
"name": "mystorage",
"source_path": "source/path",
"target_path": "target/path",
"private": True,
"configuration": {"type": "s3", "endpoint": "example.com"},
},
"sensitive_fields": {},
}
]

monkey.setattr(storage_service.StorageService, "_send_request", _send_request)
monkey.setattr(storage_service, "get_renku_url", lambda: "http://example.com")
svc = storage_service.StorageService()
storages = svc.list("123456")
assert len(storages) == 1
assert storages[0].storage.name == "mystorage"
assert storages[0].storage.storage_type == "s3"

finally:
remove_injector()

0 comments on commit 1ab5953

Please sign in to comment.