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

refactor(scanjob)!: drop restart/pause functionality #2637

Merged
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
54 changes: 0 additions & 54 deletions docs/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -872,33 +872,6 @@ paths:
description: "Not authorized"
404:
description: "Scan job inspection results not found"
/jobs/{scan_job_id}/pause/:
put:
tags:
- "Scan Job"
summary: "Pauses an existing scan job"
description: "Pauses a scan if it is currently running, fails otherwise"
operationId: "pauseScan"
produces:
- "application/json"
parameters:
- name: "scan_job_id"
in: "path"
description: "ID of scan job to pause"
required: true
type: "integer"
format: "int64"
responses:
200:
description: "Scan job paused"
schema:
$ref: "#/definitions/ScanJobOut"
400:
description: "Scan job not running"
401:
description: "Not authorized"
404:
description: "Scan job not found"
/jobs/{scan_job_id}/cancel/:
put:
tags:
Expand Down Expand Up @@ -926,33 +899,6 @@ paths:
description: "Not authorized"
404:
description: "Scan job not found"
/jobs/{scan_job_id}/restart/:
put:
tags:
- "Scan Job"
summary: "Restarts an existing scan job"
description: "Restarts a scan if it has been paused, fails otherwise"
operationId: "restartScan"
produces:
- "application/json"
parameters:
- name: "scan_job_id"
in: "path"
description: "ID of scan job to restart"
required: true
type: "integer"
format: "int64"
responses:
200:
description: "Scan job restarted"
schema:
$ref: "#/definitions/ScanJobOut"
400:
description: "Scan job was not in paused state"
401:
description: "Not authorized"
404:
description: "Scan job not found"
/reports/{report_id}/details/:
get:
tags:
Expand Down
48 changes: 1 addition & 47 deletions quipucords/api/scanjob/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
SystemConnectionResultSerializer,
SystemInspectionResultSerializer,
)
from api.signal.scanjob_signal import cancel_scan, pause_scan, restart_scan
from api.signal.scanjob_signal import cancel_scan

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -220,29 +220,6 @@ def inspection(self, request, pk=None):
return paginator.get_paginated_response(serializer.data)
return Response(status=404)

@action(detail=True, methods=["put"])
def pause(self, request, pk=None):
"""Pause the running scan."""
if not pk or (pk and not is_int(pk)):
error = {"id": [_(messages.COMMON_ID_INV)]}
raise ValidationError(error)
scan = get_object_or_404(self.queryset, pk=pk)

if scan.status == ScanTask.RUNNING:
# Kill job before changing job state
pause_scan.send(sender=self.__class__, instance=scan)
scan.status_pause()
serializer = ScanJobSerializerV1(scan)
json_scan = serializer.data
json_scan = expand_scanjob(json_scan)
return Response(json_scan, status=200)
elif scan.status == ScanTask.PAUSED:
err_msg = _(messages.ALREADY_PAUSED)
return JsonResponse({"non_field_errors": [err_msg]}, status=400)

err_msg = _(messages.NO_PAUSE)
return JsonResponse({"non_field_errors": [err_msg]}, status=400)

@action(detail=True, methods=["put"])
def cancel(self, request, pk=None):
"""Cancel the running scan."""
Expand All @@ -262,29 +239,6 @@ def cancel(self, request, pk=None):
json_scan = expand_scanjob(json_scan)
return Response(json_scan, status=200)

@action(detail=True, methods=["put"])
def restart(self, request, pk=None):
"""Restart a paused scan."""
if not pk or (pk and not is_int(pk)):
error = {"id": [_(messages.COMMON_ID_INV)]}
raise ValidationError(error)
scan = get_object_or_404(self.queryset, pk=pk)

if scan.status == ScanTask.PAUSED:
# Update job state before starting job
scan.status_restart()
restart_scan.send(sender=self.__class__, instance=scan)
serializer = ScanJobSerializerV1(scan)
json_scan = serializer.data
json_scan = expand_scanjob(json_scan)
return Response(json_scan, status=200)
elif scan.status == ScanTask.RUNNING:
err_msg = _(messages.ALREADY_RUNNING)
return JsonResponse({"non_field_errors": [err_msg]}, status=400)

err_msg = _(messages.NO_RESTART)
return JsonResponse({"non_field_errors": [err_msg]}, status=400)


class ScanJobViewSetV2(viewsets.ReadOnlyModelViewSet):
"""A viewset for ScanJobs."""
Expand Down
28 changes: 0 additions & 28 deletions quipucords/tests/api/scanjob/test_scanjob.py
Original file line number Diff line number Diff line change
Expand Up @@ -1348,20 +1348,6 @@ def test_delete(self, client_logged_in):
response = client_logged_in.delete(url)
assert response.status_code == status.HTTP_405_METHOD_NOT_ALLOWED

def test_pause_bad_state(self, client_logged_in):
"""Pause a scanjob."""
scan_job = ScanJobFactory()

url = reverse("v1:scanjob-pause", args=(scan_job.id,))
response = client_logged_in.put(url)
assert response.status_code == status.HTTP_400_BAD_REQUEST

def test_pause_bad_id(self, client_logged_in):
"""Pause a scanjob with bad id."""
url = reverse("v1:scanjob-pause", args=("string",))
response = client_logged_in.put(url)
assert response.status_code == status.HTTP_400_BAD_REQUEST

def test_cancel(self, client_logged_in):
"""Cancel a scanjob."""
scan_job = ScanJobFactory()
Expand All @@ -1375,20 +1361,6 @@ def test_cancel_bad_id(self, client_logged_in):
response = client_logged_in.put(url)
assert response.status_code == status.HTTP_400_BAD_REQUEST

def test_restart_bad_state(self, client_logged_in):
"""Restart a scanjob."""
scan_job = ScanJobFactory()

url = reverse("v1:scanjob-restart", args=(scan_job.id,))
response = client_logged_in.put(url)
assert response.status_code == status.HTTP_400_BAD_REQUEST

def test_restart_bad_id(self, client_logged_in):
"""Restart a scanjob with bad id."""
url = reverse("v1:scanjob-restart", args=("string",))
response = client_logged_in.put(url)
assert response.status_code == status.HTTP_400_BAD_REQUEST

def test_expand_scanjob(self):
"""Test view expand_scanjob."""
scan_job, scan_task = create_scan_job(
Expand Down
2 changes: 0 additions & 2 deletions quipucords/tests/api/test_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@
("v1:scanjob-detail", {"pk": 1}, "/api/v1/jobs/1/"),
("v1:scanjob-connection", {"pk": 1}, "/api/v1/jobs/1/connection/"),
("v1:scanjob-inspection", {"pk": 1}, "/api/v1/jobs/1/inspection/"),
("v1:scanjob-pause", {"pk": 1}, "/api/v1/jobs/1/pause/"),
("v1:scanjob-cancel", {"pk": 1}, "/api/v1/jobs/1/cancel/"),
("v1:scanjob-restart", {"pk": 1}, "/api/v1/jobs/1/restart/"),
# why users (plural)? other named views use singular...
("v1:users-current", {}, "/api/v1/users/current/"),
("v1:users-logout", {}, "/api/v1/users/logout/"),
Expand Down