Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(service): disable migration check optimization for anonymous sessions #2541

Merged
merged 5 commits into from
Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 8 additions & 7 deletions renku/service/controllers/cache_migrations_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from renku.core.utils.contexts import click_context
from renku.service.controllers.api.abstract import ServiceCtrl
from renku.service.controllers.api.mixins import RenkuOperationMixin
from renku.service.controllers.utils.remote_project import ANONYMOUS_SESSION
from renku.service.interfaces.git_api_provider import IGitAPIProvider
from renku.service.serializers.cache import ProjectMigrationCheckRequest, ProjectMigrationCheckResponseRPC
from renku.service.views import result_response
Expand Down Expand Up @@ -61,7 +60,7 @@ def _fast_op_without_cache(self):
tempdir,
remote=self.ctx["git_url"],
ref=self.request_data.get("ref", None),
token=self.user_data.get("token", ANONYMOUS_SESSION),
token=self.user_data.get("token", None),
)
with click_context(tempdir, "renku_op"):
return self.renku_op()
Expand All @@ -72,9 +71,11 @@ def renku_op(self):

def to_response(self):
"""Execute controller flow and serialize to service response."""
return result_response(self.RESPONSE_SERIALIZER, self.execute_op())

if "project_id" in self.context:
# use regular flow using cache
return result_response(self.RESPONSE_SERIALIZER, self.execute_op())

return result_response(self.RESPONSE_SERIALIZER, self._fast_op_without_cache())
# TODO: Enable this optimization. See https://github.com/SwissDataScienceCenter/renku-python/issues/2546
# if "project_id" in self.context:
# # use regular flow using cache
# return result_response(self.RESPONSE_SERIALIZER, self.execute_op())
#
# return result_response(self.RESPONSE_SERIALIZER, self._fast_op_without_cache())
3 changes: 2 additions & 1 deletion renku/service/views/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
accepts_json,
handle_common_except,
handle_migration_except,
optional_identity,
requires_cache,
requires_identity,
)
Expand Down Expand Up @@ -182,7 +183,7 @@ def migrate_project_view(user_data, cache):
@cache_blueprint.route("/cache.migrations_check", methods=["GET"], provide_automatic_options=False, versions=[V1_0])
@handle_common_except
@requires_cache
@requires_identity
@optional_identity
def migration_check_project_view(user_data, cache):
"""
Retrieve migration information for a project.
Expand Down
4 changes: 2 additions & 2 deletions renku/service/views/v0_9/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
from renku.service.gateways.gitlab_api_provider import GitlabAPIProvider
from renku.service.serializers.v0_9.cache import ProjectMigrationCheckResponseRPC_0_9
from renku.service.views.api_versions import V0_9
from renku.service.views.decorators import handle_common_except, requires_cache, requires_identity
from renku.service.views.decorators import handle_common_except, optional_identity, requires_cache


@handle_common_except
@requires_cache
@requires_identity
@optional_identity
def migration_check_project_view_0_9(user_data, cache):
"""
Retrieve migration information for a project.
Expand Down
6 changes: 6 additions & 0 deletions tests/service/fixtures/service_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ def it_remote_repo_url():
return IT_REMOTE_REPO_URL


@pytest.fixture(scope="module")
def it_remote_public_repo_url():
"""Returns a remote path to a public integration test repository."""
return "https://dev.renku.ch/gitlab/renku-python-integration-tests/no-renku"


@pytest.fixture(scope="function")
def it_remote_repo_url_temp_branch(it_remote_repo_url):
"""Returns a remote path to integration test repository."""
Expand Down
13 changes: 13 additions & 0 deletions tests/service/views/test_cache_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,3 +806,16 @@ def test_cache_gets_synchronized(

assert any(d.name == "my_dataset" for d in datasets)
assert any(d.name == payload["name"] for d in datasets)


@pytest.mark.service
@pytest.mark.integration
def test_check_migrations_remote_anonymous(svc_client, it_remote_public_repo_url):
"""Test anonymous users can check for migration of public projects."""
response = svc_client.get(
"/1.0/cache.migrations_check", query_string={"git_url": it_remote_public_repo_url}, headers={}
)

assert 200 == response.status_code

assert response.json["result"]["core_compatibility_status"]["migration_required"] is True
13 changes: 13 additions & 0 deletions tests/service/views/v0_9/test_cache_views_0_9.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,16 @@ def test_check_no_migrations_0_9(svc_client_with_repo):
assert not response.json["result"]["template_update_possible"]
assert not response.json["result"]["docker_update_possible"]
assert response.json["result"]["project_supported"]


@pytest.mark.service
@pytest.mark.integration
def test_check_migrations_remote_anonymous_0_9(svc_client, it_remote_public_repo_url):
"""Test anonymous users can check for migration of public projects."""
response = svc_client.get(
"/0.9/cache.migrations_check", query_string={"git_url": it_remote_public_repo_url}, headers={}
)

assert 200 == response.status_code

assert response.json["result"]["migration_required"] is True