mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-02 08:56:07 +00:00
fix(jobs): a busy message names what the job in the way works on
A verification of a chain's base refused a verification of its incremental with "Verify backup is running on this resource": which backup held it was not said. The job's resource label now follows its name for who may see the job, as on the Jobs page; not in an audit row or a bulk migration's error, which others read.
This commit is contained in:
parent
7b23c75bf5
commit
57e90e0d27
6 changed files with 24 additions and 5 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue