diff --git a/computes/tests/test_ownership.py b/computes/tests/test_ownership.py index a074cdf3..b68912ce 100644 --- a/computes/tests/test_ownership.py +++ b/computes/tests/test_ownership.py @@ -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) diff --git a/computes/utils.py b/computes/utils.py index d2d29a1f..1d21f651 100644 --- a/computes/utils.py +++ b/computes/utils.py @@ -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()