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

fix(instances): recording a migration holds the ownership lock

record_migration moved or merged a VM's owners without lock_ownership(),
which every other step that moves owners takes; on PostgreSQL a sync of
a third compute with the same UUID could move them at the same time, and
owners moved onto the source record went with its delete.
This commit is contained in:
catborise 2026-11-05 18:38:57 +03:00
parent 1a8edafd14
commit c8fb778d08
2 changed files with 13 additions and 0 deletions

View file

@ -228,3 +228,13 @@ class MigrateJobTestCase(TransactionTestCase):
resource_label="mig-src/mig-vm")
self.assertEqual(MigrateInstance().log_entry(queued, Operation.CANCELLED),
("mig-src", "mig-vm", UUID, "VM mig-vm: migrate to mig-dst (cancelled)"))
def test_recording_a_migration_holds_the_ownership_lock(self):
# a sync of a third compute must not move the owners at the same time
from instances import utils
with patch.object(utils, "lock_ownership") as lock:
utils.record_migration(self.vm, self.dest)
lock.assert_called_once_with()
self.vm.refresh_from_db()
self.assertEqual(self.vm.compute, self.dest)