1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-03 17:36:05 +00:00

fix(logs): a job's rows carry the address it was asked from, and a cancel its own user

A job keeps the client address of its submission (Operation.client_ip,
migration operations.0003); the rows the worker writes for it, including the
migration's and the VM delete's own rows, carry it. A cancel is written under
the user who asked and from their address, also when an administrator
cancels another user's job; a running job's cancel gets a row when asked,
and its end a row when it stops. A resolution carries the administrator's
address.
This commit is contained in:
catborise 2026-11-07 14:25:18 +03:00
parent e9e514a7e9
commit 21b83062f7
9 changed files with 85 additions and 14 deletions

View file

@ -226,7 +226,7 @@ def _finish_clone(op, clone, warning):
except libvirtError as err:
notes += say(_("The clone is made, but not as asked: %(error)s"), error=err)
write(op.username, c.name, op.intent["name"], f"VM {op.intent['name']}: resize or start the clone: "
f"{safe_text(err)}", False, uuid=op.intent["uuid"])
f"{safe_text(err)}", False, op.client_ip, op.intent["uuid"])
return {"warning": notes} if notes else {}
@ -972,7 +972,7 @@ def _moved(op, dest):
target = Compute.objects.get(pk=op.params["target"]).name
def failed(action, err): # as migrate_instance logs its later steps
write(op.username, source, name, f"VM {name}: {action}: {safe_text(err)}", False, uuid=op.intent["uuid"])
write(op.username, source, name, f"VM {name}: {action}: {safe_text(err)}", False, op.client_ip, op.intent["uuid"])
if op.intent.get("autostart"):
try:
@ -1043,7 +1043,7 @@ class MigrateInstance(Kind):
ctx.set_phase(gettext_noop("Migrating the VM"))
try:
utils.migrate_instance(Compute.objects.get(pk=p["target"]), instance, op.user,
disk_pools=p["disk_pools"],
disk_pools=p["disk_pools"], ip=op.client_ip,
on_moved=lambda: ctx.record_intent(outcome_logged=True),
**{k: p[k] for k in MIGRATE_OPTIONS})
except Exception as err:
@ -1276,7 +1276,7 @@ def _removed(op, recovering=False):
continue
notes += say(DISK_NOT_DELETED, path=path, err=err)
write(op.username, compute.name, op.intent["name"], f"VM {op.intent['name']}: delete volume {path}: "
f"{safe_text(err)}", False, uuid=op.intent["uuid"])
f"{safe_text(err)}", False, op.client_ip, op.intent["uuid"])
try:
while (path := conn.backing_path(path)) and path not in kept:
kept.add(path)
@ -1284,7 +1284,7 @@ def _removed(op, recovering=False):
kept.update(op.intent["to_delete"]) # the files it needs are unknown: none of the rest goes
else:
write(op.username, compute.name, op.intent["name"], f"VM {op.intent['name']}: delete volume {path}",
True, uuid=op.intent["uuid"])
True, op.client_ip, op.intent["uuid"])
for path in op.intent["shared"]:
notes += say(DISK_SHARED, path=path)
return {"open": reverse("instances:index"), **({"warning": notes} if notes else {})}

View file

@ -152,6 +152,9 @@ class CloneJobTestCase(TransactionTestCase):
# the job succeeded: Logs has the step that failed too
self.assertTrue(Logs.objects.filter(instance_uuid=op.intent["uuid"], success=False,
message="VM copy: resize or start the clone: no memory").exists())
# the worker writes them with the address the form came from
self.assertEqual(set(Logs.objects.filter(instance_uuid=op.intent["uuid"]).values_list("ip", flat=True)),
{"127.0.0.1"})
def queued(self):
self.client.post(reverse("instances:clone", args=[self.source.pk]),

View file

@ -214,6 +214,7 @@ def migrate_instance(
compress=False,
delete_source=False,
disk_pools=None,
ip=None,
on_moved=None,
):
"""Migrates instance to new_compute and logs the outcome (the mode
@ -226,7 +227,7 @@ def migrate_instance(
def log(action, error=None):
message = f"VM {instance.name}: {action}" + (f": {reason(error, user)}" if error is not None else "")
write(user.username, source.name, instance.name, message, error is None, uuid=instance.uuid)
write(user.username, source.name, instance.name, message, error is None, ip, instance.uuid)
conn_migrate = None
try: