Skip to content

Commit

Permalink
Link to Airlock for viewing log outputs
Browse files Browse the repository at this point in the history
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
  • Loading branch information
evansd committed Sep 3, 2024
1 parent 4ec94ff commit b8d4cc8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 31 deletions.
23 changes: 5 additions & 18 deletions jobserver/views/jobs.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 3 additions & 6 deletions templates/job/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,12 @@ <h1 class="min-w-0 text-3xl break-words md:text-4xl font-bold text-slate-900">
<p>A User has requested this Job is cancelled.</p>
{% endif %}

{% if log_path %}
{% if log_path_url %}
<p class="text-slate-600">
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" %}
</p>
<p class="text-slate-600">
Alternatively, view the file on the {{ job.job_request.backend.name }} server at: <pre class="text-slate-500 break-all whitespace-pre-wrap">{{ log_path }}</pre>
</p>
{% endif %}
{% endif %}
</div>
{% /description_item %}

Expand Down
10 changes: 3 additions & 7 deletions tests/unit/jobserver/views/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)


Expand Down

0 comments on commit b8d4cc8

Please sign in to comment.