From b8d4cc80d76cd427b62ce941321e0709802120fe Mon Sep 17 00:00:00 2001 From: David Evans Date: Tue, 3 Sep 2024 17:25:25 +0100 Subject: [PATCH] Link to Airlock for viewing log outputs This replaces both the link the output viewer and the reference to the old "Level 4 file sync" directory. Previously we restricted these links to only show for the TPP backend, but on the assumption that we will be running an instance of Airlock for every backend I have removed this restriction. Closes #4583 --- jobserver/views/jobs.py | 23 +++++------------------ templates/job/detail.html | 9 +++------ tests/unit/jobserver/views/test_jobs.py | 10 +++------- 3 files changed, 11 insertions(+), 31 deletions(-) diff --git a/jobserver/views/jobs.py b/jobserver/views/jobs.py index 6adb6f3005..9692aece32 100644 --- a/jobserver/views/jobs.py +++ b/jobserver/views/jobs.py @@ -1,12 +1,9 @@ -import os - from django.contrib import messages from django.core.exceptions import MultipleObjectsReturned from django.http import Http404 from django.shortcuts import get_object_or_404, redirect from django.template.response import TemplateResponse from django.views.generic import RedirectView, View -from furl import furl from .. import honeycomb from ..authorization import CoreDeveloper, has_permission, has_role, permissions @@ -69,22 +66,13 @@ def get(self, request, *args, **kwargs): # (previously status_tools). It isn't ideal to have here but until we # have more than one backend-specific error code it makes sense to keep # things together. - log_path = "" log_path_url = "" - if job.job_request.backend.slug == "tpp" and job.status_code == "nonzero_exit": - log_path = os.path.join( - job.job_request.backend.parent_directory, - job.job_request.workspace.name, - "metadata", - f"{job.action}.log", - ) - url = ( - furl(job.job_request.workspace.get_files_url()) - / "metadata" - / f"{job.action}.log" + if job.status_code == "nonzero_exit": + log_path_url = ( + f"https://{job.job_request.backend.slug}.backends.opensafely.org/" + f"workspaces/view/{job.job_request.workspace.name}/" + f"metadata/{job.action}.log" ) - url.path.normalize() - log_path_url = url.url honeycomb_links = {} if honeycomb_can_view_links: @@ -127,7 +115,6 @@ def get(self, request, *args, **kwargs): context = { "cancellation_requested": job.action in job.job_request.cancelled_actions, "job": job, - "log_path": log_path, "log_path_url": log_path_url, "object": job, "user_can_cancel_jobs": can_cancel_jobs, diff --git a/templates/job/detail.html b/templates/job/detail.html index 9ec30aed18..e03280c4e0 100644 --- a/templates/job/detail.html +++ b/templates/job/detail.html @@ -140,15 +140,12 @@

A User has requested this Job is cancelled.

{% endif %} - {% if log_path %} + {% if log_path_url %}

- You can check the log output in the {% link text="outputs viewer" href=log_path_url %} + You can check the log output in {% link text="Airlock" href=log_path_url %} {% pill text="VPN Required" variant="primary" %}

-

- Alternatively, view the file on the {{ job.job_request.backend.name }} server at:

{{ log_path }}
-

- {% endif %} + {% endif %} {% /description_item %} diff --git a/tests/unit/jobserver/views/test_jobs.py b/tests/unit/jobserver/views/test_jobs.py index 1df8720895..39c1a556e2 100644 --- a/tests/unit/jobserver/views/test_jobs.py +++ b/tests/unit/jobserver/views/test_jobs.py @@ -297,13 +297,9 @@ def test_jobdetail_with_nonzero_exit_code(rf): ) assert response.status_code == 200 - assert ( - response.context_data["log_path"] - == f"/var/test/{job_request.workspace.name}/metadata/my_action.log" - ) - assert ( - response.context_data["log_path_url"] - == f"{job.job_request.workspace.get_files_url()}metadata/my_action.log" + assert response.context_data["log_path_url"] == ( + f"https://tpp.backends.opensafely.org/workspaces/view/" + f"{job.job_request.workspace.name}/metadata/my_action.log" )