From 9d3d218fbbb70f09981e00556822fd97eac87097 Mon Sep 17 00:00:00 2001 From: catborise Date: Thu, 15 Oct 2026 00:07:50 +0300 Subject: [PATCH] docs: clone and create run as jobs --- README.md | 1 + instances/tests/test_live_jobs.py | 33 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/README.md b/README.md index 1095abc7..05d0cb00 100644 --- a/README.md +++ b/README.md @@ -601,6 +601,7 @@ When the restored version predates the worker, `supervisorctl` reports that `web - A storage volume a VM still needs (a disk, a backing file or a snapshot's file) is no longer deleted from the storage page or the API; the delete is refused with the reason. Only VMs on the same compute are checked. - Docker no longer publishes port 6080; the console goes through nginx on the panel's port (`WS_PUBLIC_PORT`, default 80). - 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. - 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 1a16f3dc..ac86ae0b 100644 --- a/instances/tests/test_live_jobs.py +++ b/instances/tests/test_live_jobs.py @@ -11,6 +11,7 @@ from django.test import TransactionTestCase from vrtManager.connection import connection_manager from vrtManager.instance import wvmInstance +from appsettings.settings import get_settings from computes.models import Compute from instances.jobs import DeleteExternalSnapshot from instances.models import Instance @@ -60,6 +61,7 @@ class LiveJobsTestCase(TransactionTestCase): raise AssertionError("Live tests changed objects outside the test namespace") def setUp(self): + get_settings() host, login, password, conn_type = self.args self.compute = Compute.objects.create(name=P + "compute", hostname=host, login=login, password=password, type=conn_type) @@ -90,3 +92,34 @@ class LiveJobsTestCase(TransactionTestCase): Operation.objects.filter(pk=op.pk).update(state=Operation.RUNNING) op.refresh_from_db() self.assertEqual(DeleteExternalSnapshot().reconcile(op).state, Operation.SUCCEEDED) + + def run_job(self, op): + worker = Worker(concurrency=1, tick=0.1, heartbeat_every=1, progress_every=1, exit_on_lost_lease=False) + thread = fakes.start_worker(worker) + try: + self.assertTrue(wait_for(lambda: Operation.objects.get(pk=op.pk).state in Operation.TERMINAL, 300)) + finally: + fakes.stop_worker(worker, thread) + op.refresh_from_db() + self.assertEqual(op.state, Operation.SUCCEEDED, op.error) + return op + + def test_clone_create_and_volume_clone_run_as_jobs(self): + dom, _vm = self.vm("smoke-src") + source = Instance.objects.create(compute=self.compute, name=dom.name(), uuid=dom.UUIDString()) + op = self.run_job(jobs.submit("instance.clone", self.admin, { + "instance": source.pk, "name": P + "smoke-clone", "disk-vda": P + "smoke-clone.qcow2", + "clone-net-mac-0": "52:54:00:00:31:01"}, "key-smoke001")) + self.assertEqual(self.conn.lookupByUUIDString(op.intent["uuid"]).name(), P + "smoke-clone") + self.run_job(jobs.submit("volume.clone", self.admin, { + "compute": self.compute.pk, "pool": livetest.POOL, "image": P + "smoke-src.qcow2", + "name": P + "smoke-copy"}, "key-smoke002")) + self.assertTrue(livetest.volume_exists(self.conn, f"{livetest.POOL_PATH}/{P}smoke-copy.qcow2")) + op = self.run_job(jobs.submit("instance.create", self.admin, { + "name": P + "smoke-new", "firmware": "BIOS", "vcpu": 1, "vcpu_mode": "host-model", "memory": 256, + "networks": "default", "storage": livetest.POOL, "template": P + "smoke-copy.qcow2", "images": "", + "hdd_size": 0, "cache_mode": "none", "meta_prealloc": False, "virtio": True, "qemu_ga": False, + "mac": "", "nwfilter": "", "net_model": "virtio", "add_cdrom": "None", "add_input": "default", + "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")