mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-11 04:36:48 +00:00
feat(logs): every VM operation writes an audit row the VM's Logs tab finds by UUID
Operations on a VM now write their rows the way the admin audit does: one
row per operation, done or failed with a safe reason, with the user, IP and
host. Each row names the VM ("VM web-1: delete snapshot snap1") and carries
its UUID in the new Logs.instance_uuid column.
- audit_vm and failed_vm wrap audit() and failed() for a VM. A failure the
view turns into a message is caught outside the block, so its failed row
is written; busy claims, permission and quota refusals and invalid input
write nothing. No password, key or XML goes into a row.
- All VM page operations move from addlogmsg to audit_vm, and addlogmsg
goes. QoS changes and defining a VM from XML are logged now; a gstfsd
error reply (root password, SSH key) is a failed row, not a done one.
- Partial results are rows of their own: the VM delete, then each disk
delete; the disk detach, then the volume delete; the migration, then a
failed autostart restore, NVRAM removal or record on the target.
- Migration rows use the compute name as the host column, as every other
row does.
- VM job rows (create, clone, snapshots) and their resolutions carry the
VM's UUID; snapshot job intents now record it. The owner rows of the VM
page and the accounts pages, and the ownership system rows, carry it too.
- The Logs tab loads vm_logs/<pk>/ and shows the rows with the VM's UUID,
so a rename keeps the history, two VMs with one name are told apart and
a VM on two computes is one VM. It gains a Result column. Rows from
before this change have no UUID and stay on the Logs page only.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
49cf16ecbe
commit
c1d36053d6
24 changed files with 639 additions and 524 deletions
|
|
@ -8,9 +8,9 @@ from django.db import IntegrityError, transaction
|
|||
from django.test import RequestFactory, TestCase
|
||||
|
||||
from computes.models import Compute
|
||||
from logs.audit import audit, changed_fields, failed, request_ip, snapshot, write
|
||||
from instances.models import Instance
|
||||
from logs.audit import audit, audit_vm, changed_fields, failed, failed_vm, request_ip, snapshot, write
|
||||
from logs.models import Logs
|
||||
from logs.views import addlogmsg
|
||||
from operations import claims
|
||||
from vrtManager.util import OperationError
|
||||
|
||||
|
|
@ -62,12 +62,9 @@ class WriteTests(TestCase):
|
|||
self.assertIsNone(request_ip(rf.get("/", REMOTE_ADDR="127.0.0.1", HTTP_X_REAL_IP="fe80::1%eth0")))
|
||||
self.assertIsNone(request_ip(rf.get("/", REMOTE_ADDR="")))
|
||||
|
||||
def test_addlogmsg_still_writes(self):
|
||||
addlogmsg("u", "h", "vm", "Destroy")
|
||||
row = Logs.objects.get()
|
||||
self.assertEqual((row.user, row.host, row.instance, row.message), ("u", "h", "vm", "Destroy"))
|
||||
self.assertIsNone(row.success)
|
||||
self.assertIsNone(row.ip)
|
||||
def test_a_row_without_a_vm_has_no_uuid(self):
|
||||
write("u", "h", "", "Network lab: start", True)
|
||||
self.assertEqual(Logs.objects.get().instance_uuid, "")
|
||||
|
||||
|
||||
class AuditTests(TestCase):
|
||||
|
|
@ -135,6 +132,26 @@ class AuditTests(TestCase):
|
|||
self.assertEqual(row.host, "-")
|
||||
self.assertIs(row.success, False)
|
||||
|
||||
def test_vm_rows_name_the_vm_and_carry_its_uuid(self):
|
||||
vm = Instance(compute=self.compute, name="web-1", uuid="11111111-2222-3333-4444-555555555555")
|
||||
with audit_vm(self.request, vm, "power on"):
|
||||
pass
|
||||
with self.assertRaises(OperationError):
|
||||
with audit_vm(self.request, vm, "power off"):
|
||||
raise OperationError("not running")
|
||||
failed_vm(self.request, vm, "reset root password", "gstfsd error: timed out")
|
||||
self.assertEqual(
|
||||
list(Logs.objects.order_by("id").values_list("host", "instance", "instance_uuid", "message", "success")), [
|
||||
("c", "web-1", vm.uuid, "VM web-1: power on", True),
|
||||
("c", "web-1", vm.uuid, "VM web-1: power off: not running", False),
|
||||
("c", "web-1", vm.uuid, "VM web-1: reset root password: gstfsd error: timed out", False),
|
||||
])
|
||||
|
||||
def test_the_block_may_set_the_uuid_it_learns(self):
|
||||
with audit(self.request, self.compute, "VM web-1", "define from XML", instance="web-1") as entry:
|
||||
entry.uuid = "11111111-2222-3333-4444-555555555555"
|
||||
self.assertEqual(self.row().instance_uuid, "11111111-2222-3333-4444-555555555555")
|
||||
|
||||
def test_changed_fields(self):
|
||||
compute = Compute.objects.create(name="c", hostname="192.0.2.5", type=1, password="pw")
|
||||
before = snapshot(compute)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue