mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-02 08:56:07 +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.
This commit is contained in:
parent
cdd724a19d
commit
4cd4af30ee
2 changed files with 21 additions and 5 deletions
|
|
@ -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_a), (True, [(self.owner, True, False, True)]))
|
||||||
self.assertEqual(self.ownership(self.host_b), (False, []))
|
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)
|
@override_settings(INSTANCE_OWNERSHIP_RETENTION_DAYS=30)
|
||||||
def test_ownership_is_kept_for_a_bounded_time(self):
|
def test_ownership_is_kept_for_a_bounded_time(self):
|
||||||
self.owned_vm(self.host_a)
|
self.owned_vm(self.host_a)
|
||||||
|
|
|
||||||
|
|
@ -85,11 +85,12 @@ def forget(inst):
|
||||||
"""Remove an instance whose VM its compute no longer lists, or whose
|
"""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 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
|
compute (an out-of-band move) or is kept in a tombstone in case the VM
|
||||||
comes back."""
|
comes back. Two other computes with the UUID: either may be a copy, so
|
||||||
elsewhere = Instance.objects.filter(uuid=inst.uuid).exclude(compute_id=inst.compute_id).first()
|
the Removed VMs page shows the owners for an administrator to add."""
|
||||||
if elsewhere:
|
elsewhere = list(Instance.objects.filter(uuid=inst.uuid).exclude(compute_id=inst.compute_id)[:2])
|
||||||
move_ownership(inst, elsewhere)
|
if len(elsewhere) == 1:
|
||||||
_log(inst, f"owners moved to {elsewhere.compute.name}")
|
move_ownership(inst, elsewhere[0])
|
||||||
|
_log(inst, f"owners moved to {elsewhere[0].compute.name}")
|
||||||
else:
|
else:
|
||||||
_bury(inst)
|
_bury(inst)
|
||||||
inst.delete()
|
inst.delete()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue