1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-11 12:46:49 +00:00

fix(computes): a VM gone from its compute gives no copy its owners

When a VM left its compute and its UUID was listed on another, its owners
moved there: an out-of-band move. With the UUID on two other computes,
the first record found got them, which may be an independent copy, giving
its owners another VM and charging their quota for it. The owners now
move only when one other compute lists the UUID; otherwise they are kept
on the Removed VMs page.

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:24:38 +03:00
parent b95f2a28d7
commit 30da02e25e
2 changed files with 21 additions and 5 deletions

View file

@ -98,6 +98,21 @@ class OwnershipTestCase(TestCase):
self.assertEqual(self.ownership(self.host_a), (True, [(self.owner, True, False, True)]))
self.assertEqual(self.ownership(self.host_b), (False, []))
def test_a_move_to_one_of_two_copies_gives_the_owners_to_neither(self):
host_c = self.compute("host-c")
self.owned_vm(self.host_a)
self.on(self.host_a, [("vm", UUID)])
for host in (self.host_b, host_c):
self.on(host, [("vm", UUID)])
refresh_instance_database(host)
self.on(self.host_a, [])
refresh_instance_database(self.host_a)
self.assertEqual(self.ownership(self.host_b), (False, []))
self.assertEqual(self.ownership(host_c), (False, []))
self.assertEqual(InstanceTombstone.objects.get().owners,
[{"user": self.owner.id, "is_change": True, "is_delete": False, "is_vnc": True}])
@override_settings(INSTANCE_OWNERSHIP_RETENTION_DAYS=30)
def test_ownership_is_kept_for_a_bounded_time(self):
self.owned_vm(self.host_a)

View file

@ -85,11 +85,12 @@ def forget(inst):
"""Remove an instance whose VM its compute no longer lists, or whose
compute is deleted. Its ownership goes to the same UUID on another
compute (an out-of-band move) or is kept in a tombstone in case the VM
comes back."""
elsewhere = Instance.objects.filter(uuid=inst.uuid).exclude(compute_id=inst.compute_id).first()
if elsewhere:
move_ownership(inst, elsewhere)
_log(inst, f"owners moved to {elsewhere.compute.name}")
comes back. Two other computes with the UUID: either may be a copy, so
the Removed VMs page shows the owners for an administrator to add."""
elsewhere = list(Instance.objects.filter(uuid=inst.uuid).exclude(compute_id=inst.compute_id)[:2])
if len(elsewhere) == 1:
move_ownership(inst, elsewhere[0])
_log(inst, f"owners moved to {elsewhere[0].compute.name}")
else:
_bury(inst)
inst.delete()