1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-08 11:16:47 +00:00

fix(storages): an unexpected ISO upload failure is logged

The upload view sent the error of an unexpected failure to the browser
but left nothing in the server log, so whoever runs the server had no
trace of it. It is logged with its traceback now; the superuser still
sees the message.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
catborise 2026-10-21 21:38:34 +03:00
parent 2144b3fe20
commit ef1faf57c8
2 changed files with 10 additions and 0 deletions

View file

@ -644,6 +644,13 @@ class UploadViewTests(LocalPool, UploadTestCase):
response = self.post()
self.assertEqual((response.status_code, response.json()["error"]), (400, "ISO image already exists"))
def test_an_unexpected_failure_is_logged(self):
with patch("storages.views.write_chunk", side_effect=OSError("disk gone")), \
self.assertLogs("storages.views", "ERROR") as logs:
response = self.post()
self.assertEqual((response.status_code, response.json()["error"]), (500, "disk gone"))
self.assertIn("OSError: disk gone", logs.output[0])
def test_a_busy_session_is_retried(self):
self.post(0, total=2, size="6")
claims.admit({f"upload:{self.job().pk}": Claim.EXCLUSIVE}, holder="192.0.2.30:1:1")

View file

@ -1,3 +1,5 @@
import logging
from admin.decorators import superuser_only
from appsettings.settings import app_settings
from computes.models import Compute
@ -49,6 +51,7 @@ def _handle_iso_upload(request, conn, compute, pool):
except (ValueError, jobs.SubmissionConflict, OperationError) as e:
return JsonResponse({"error": str(e)}, status=400)
except Exception as e:
logging.getLogger(__name__).exception("ISO upload chunk failed")
return JsonResponse({"error": str(e)}, status=500)
return JsonResponse({"success": True, "job": str(op.pk)})