diff --git a/computes/jobs.py b/computes/jobs.py index b1003df0..4e7fc261 100644 --- a/computes/jobs.py +++ b/computes/jobs.py @@ -110,7 +110,7 @@ class Migrations(Kind): except claims.Busy as busy: if busy.blocker is not None and busy.blocker.state == Operation.UNCERTAIN: # it holds its claims until someone resolves it - refused.append(f"{names[vm]}: {utils.busy_message(busy, op.user)}") + refused.append(f"{names[vm]}: {utils.busy_message(busy, op.user, named=False)}") else: waiting.append(move) # another job holds the VM or a host: asked again on the next round except Exception as err: diff --git a/instances/tests/test_snapshot_delete_job.py b/instances/tests/test_snapshot_delete_job.py index e88d2121..3b075ade 100644 --- a/instances/tests/test_snapshot_delete_job.py +++ b/instances/tests/test_snapshot_delete_job.py @@ -1,6 +1,7 @@ """External snapshot delete is a job: the request queues it; the worker deletes through libvirt; recovery follows the reconcile table.""" +import re from datetime import timedelta from types import SimpleNamespace from unittest.mock import MagicMock, patch @@ -72,7 +73,7 @@ class SnapshotDeleteJobTestCase(TransactionTestCase): self.post(key="key-00000001") response = self.post(key="key-00000002") self.assertEqual(Operation.objects.count(), 1) - self.assertTrue(any("Delete snapshot is queued" in str(m) for m in response.wsgi_request._messages)) + self.assertTrue(any(re.match(r"Delete snapshot \(.+\) is queued", str(m)) for m in response.wsgi_request._messages)) def test_a_long_name_is_kept_whole(self): # its truncated prefix could name another snapshot diff --git a/logs/audit.py b/logs/audit.py index 2863a041..91621835 100644 --- a/logs/audit.py +++ b/logs/audit.py @@ -62,7 +62,7 @@ def reason(exc, user): from vrtManager.util import OperationError if isinstance(exc, claims.Busy): - return busy_message(exc, user) + return busy_message(exc, user, named=False) # a VM's owner may read its row if isinstance(exc, OperationError): return exc.args[0] # English: str() is the reader's language if isinstance(exc, libvirt.libvirtError): diff --git a/operations/tests/test_views.py b/operations/tests/test_views.py index b5d5f7c7..ca4c750b 100644 --- a/operations/tests/test_views.py +++ b/operations/tests/test_views.py @@ -28,6 +28,20 @@ class BusyMessageTestCase(SimpleTestCase): self.assertIn(" çalışıyor ", text) self.assertNotIn("running", text) + def test_the_job_in_the_way_is_named_with_what_it_works_on_to_who_may_see_it(self): + from types import SimpleNamespace + + from operations.utils import busy_message + op = Operation(kind="backup.verify", state=Operation.RUNNING, created_at=django_timezone.now(), user_id=2, + username="admin", resource_label="vm1 2026-11-19 16:00") + text = busy_message(SimpleNamespace(blocker=op), SimpleNamespace(is_superuser=True, pk=1)) + self.assertTrue(text.startswith("Verify backup (vm1 2026-11-19 16:00) is running on this resource"), text) + text = busy_message(SimpleNamespace(blocker=op), SimpleNamespace(is_superuser=False, pk=1)) + self.assertTrue(text.startswith("Verify backup is running on this resource"), text) + # kept in an audit row, which a VM's owner may read + text = busy_message(SimpleNamespace(blocker=op), SimpleNamespace(is_superuser=True, pk=1), named=False) + self.assertTrue(text.startswith("Verify backup is running on this resource"), text) + class StateColorsTestCase(SimpleTestCase): def test_every_state_has_its_colour(self): diff --git a/operations/utils.py b/operations/utils.py index a61b398b..cb366d85 100644 --- a/operations/utils.py +++ b/operations/utils.py @@ -191,12 +191,16 @@ def summary(op, user): return base -def busy_message(busy, user): +def busy_message(busy, user, named=True): + """Why busy refused user. named: with what the job in the way works on; not in a text kept where others + read it (an audit row, a job's error).""" op = busy.blocker if op is None: return _("A short operation is in progress on this resource; try again in a moment.") values = {"label": _(jobs.label_of(op.kind)), "state": pgettext("job state", op.state), "since": timesince(op.created_at, timezone.now())} if may_see(op, user): + if named and op.resource_label: # which backup, VM or volume it works on: one in the way may be another + values["label"] = f"{values['label']} ({shown_label(op, user)})" return _("%(label)s is %(state)s on this resource (started by %(user)s, %(since)s ago); " "see the Jobs page.") % {**values, "user": op.username} return _("%(label)s is %(state)s on this resource (since %(since)s).") % values diff --git a/storages/tests/test_upload_job.py b/storages/tests/test_upload_job.py index ebac695d..1ac1ef36 100644 --- a/storages/tests/test_upload_job.py +++ b/storages/tests/test_upload_job.py @@ -673,7 +673,7 @@ class UploadViewTests(LocalPool, UploadTestCase): self.post(0, total=2, size="6") response = self.post(0, total=2, size="6", key="upload-key-0002") self.assertEqual(response.status_code, 400) - self.assertIn("Upload ISO image is running on this resource", response.json()["error"]) + self.assertRegex(response.json()["error"], r"^Upload ISO image \(.+\) is running on this resource") def test_submission_keys_are_per_user(self): self.post(0, total=2, size="6")