From 41e1fcd4b9e96f71b47009b9997289a4644b699d Mon Sep 17 00:00:00 2001 From: catborise Date: Thu, 15 Oct 2026 21:38:25 +0300 Subject: [PATCH] docs: migration runs as a job --- README.md | 1 + instances/tests/test_live_jobs.py | 27 ++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 90ede644..9960c5f1 100644 --- a/README.md +++ b/README.md @@ -603,6 +603,7 @@ When the restored version predates the worker, `supervisorctl` reports that `web - Long operations run as jobs in a worker process (`manage.py run_worker`); follow them on the VM page and on the Jobs page. - Cloning a VM or a volume and creating a VM run as jobs: the page returns at once and the job panel follows them. The API's VM create answers 202 with the job and needs a new `submission_key` per request. The create form no longer takes a console password; set it on the VM page. - Taking and reverting a snapshot run as jobs, like deleting an external snapshot: the page returns at once and the job panel follows them. Deleting an internal snapshot stays immediate. +- Migrating a VM runs as a job: the page returns at once, the job panel shows its progress, and a running migration can be cancelled there (the VM keeps running on its source host). The 540 s limit is gone. The API's migrate answers 202 with the job and needs a new `submission_key` per request. - Manual installs that keep their own `settings.py` copy the SQLite `OPTIONS` and `TEST` entries from `settings.py.template` and add `"operations"` to `INSTALLED_APPS`. - The SQLite database must be on a local file system (WAL). - Outside compose, stop the Docker container with `docker stop -t 95` so the worker can finish running jobs. diff --git a/instances/tests/test_live_jobs.py b/instances/tests/test_live_jobs.py index 0e133455..0bf494cc 100644 --- a/instances/tests/test_live_jobs.py +++ b/instances/tests/test_live_jobs.py @@ -1,6 +1,8 @@ """Live checks for the instance jobs: the worker runs them against libvirt and recovery reads the same outcome back. Runs only with TEST_LIBVIRT_HOST -set (see instances/tests/livetest.py).""" +set (see instances/tests/livetest.py). The migration needs a second host: +TEST_LIBVIRT_SSH_HOST (and _LOGIN), with TEST_LIBVIRT_MIGRATE_ADDRESS as its +migration address.""" import os import time @@ -138,3 +140,26 @@ class LiveJobsTestCase(TransactionTestCase): "video": "vga", "listener_addr": "127.0.0.1", "compute": self.compute.pk, "arch": "x86_64", "machine": "q35"}, "key-smoke003")) self.assertEqual(self.conn.lookupByUUIDString(op.intent["uuid"]).name(), P + "smoke-new") + + def test_a_migration_runs_as_a_job_there_and_back(self): + if not os.environ.get("TEST_LIBVIRT_SSH_HOST"): + self.skipTest("Set TEST_LIBVIRT_SSH_HOST to a second host to run the live migration test") + dest = Compute.objects.create(name=P + "dest", hostname=os.environ["TEST_LIBVIRT_SSH_HOST"], + login=os.environ.get("TEST_LIBVIRT_SSH_LOGIN", "root"), password="", type=2, + migration_address=os.environ.get("TEST_LIBVIRT_MIGRATE_ADDRESS", "")) + dest_conn = connection_manager.get_connection(dest.hostname, dest.login, "", 2) + dest_inventory = livetest.inventory(dest_conn) + self.addCleanup(lambda: self.assertEqual(livetest.inventory(dest_conn), dest_inventory)) + self.addCleanup(livetest.cleanup, dest_conn) + dom = livetest.define_vm(self.conn, P + "migrate", []) + dom.create() + uuid = dom.UUIDString() + instance = Instance.objects.create(compute=self.compute, name=dom.name(), uuid=uuid) + live = {"instance": instance.pk, "target": dest.pk, "live": True, "autoconverge": True} + self.run_job(jobs.submit("instance.migrate", self.admin, live, "key-mig00001")) + self.assertTrue(dest_conn.lookupByUUIDString(uuid).isActive()) + dest_conn.lookupByUUIDString(uuid).destroy() + offline = {"instance": instance.pk, "target": self.compute.pk, "offline": True} + self.run_job(jobs.submit("instance.migrate", self.admin, offline, "key-mig00002")) + self.assertFalse(self.conn.lookupByUUIDString(uuid).isActive()) # defined on the source again + self.assertEqual(Instance.objects.get(uuid=uuid).compute, self.compute)