1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-01 16:36:06 +00:00

fix(computes): a compute is not edited while a job on it is admitted

A job resolves its compute's connection when it runs. Changing the
compute's hostname meanwhile sent the job to another host, where a VM
with the same UUID (a copy) could be deleted or changed instead. An edit
now holds the compute as a delete does, and is refused while a job or VM
operation on it is admitted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea
This commit is contained in:
catborise 2026-11-09 21:23:16 +03:00
parent a2f4d3fe06
commit 12e33f7964
3 changed files with 15 additions and 2 deletions

View file

@ -54,6 +54,17 @@ class ComputeAuditRowTests(TestCase):
self.assertFalse(row.success)
self.assertTrue(Compute.objects.exists())
def test_a_compute_with_a_job_is_not_changed(self):
# the job would run on whatever host the compute names when it starts
compute = Compute.objects.create(name="c1", hostname="192.0.2.5", login="admin", password="secret", type=1)
claims.admit({claims.compute_key(compute.id): Claim.SHARED}, holder="192.0.2.30:1:1")
self.client.post(reverse("compute_update", args=[compute.id]), self.form_data("192.0.2.6"))
res = self.client.patch(f"/api/v1/computes/{compute.id}/", {"hostname": "192.0.2.6"},
content_type="application/json")
self.assertEqual(res.status_code, 409)
self.assertEqual(Compute.objects.get().hostname, "192.0.2.5")
self.assertEqual([r.success for r in Logs.objects.all()], [False, False])
def test_the_api_writes_the_same_rows(self):
data = {"name": "c1", "hostname": "192.0.2.5", "login": "admin", "password": "secret", "type": 1}
res = self.client.post("/api/v1/computes/", data, content_type="application/json")