mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 09:26:03 +00:00
fix(instances): a new VM's disk cache goes with the disk I/O of Settings
Settings refuse disk I/O native with a cache other than none or directsync, which libvirt refuses. A new VM took the I/O from Settings and its cache from the create form, unchecked: native I/O with a writeback cache was queued, the disks were made, and libvirt then refused the VM. The create job now refuses such a pair when it is asked for, and again when it runs, before it makes a disk: Settings may have changed meanwhile. Two administrators saving the I/O and the cache at once each checked the pair as their page read it, and both saves made one libvirt refuses. The pair is now checked again as saved, with its rows locked, when a change of it is saved; the log row keeps the reason in English.
This commit is contained in:
parent
7bbc951082
commit
5a52bcf43e
8 changed files with 207 additions and 122 deletions
|
|
@ -870,6 +870,16 @@ def _check_macs(conn, data):
|
|||
mac=", ".join(sorted(used & macs)))
|
||||
|
||||
|
||||
def _disk_io(params):
|
||||
"""The disk I/O of Settings for the new VM's disks, refused with a cache
|
||||
libvirt does not take with it, before any disk is made."""
|
||||
io_mode = app_settings.INSTANCE_VOLUME_DEFAULT_IO
|
||||
if io_mode == "native" and params["cache_mode"] not in ("none", "directsync"):
|
||||
raise util.OperationError(_("Disk cache %(cache)s does not go with disk I/O native, which Settings set: "
|
||||
"choose none or directsync"), cache=params["cache_mode"])
|
||||
return io_mode
|
||||
|
||||
|
||||
@register
|
||||
class CreateInstance(Kind):
|
||||
name = "instance.create"
|
||||
|
|
@ -908,6 +918,7 @@ class CreateInstance(Kind):
|
|||
_check_disk_name(conn, data)
|
||||
if data["cache_mode"] not in conn.get_cache_modes():
|
||||
raise util.OperationError(_("Invalid cache mode"))
|
||||
_disk_io(data)
|
||||
if data["vcpu_mode"] not in cpu_choices(conn.get_dom_capabilities(data["arch"], data["machine"])):
|
||||
raise util.OperationError(_("This host offers no CPU mode or model %(mode)s"), mode=data["vcpu_mode"])
|
||||
if data["net_model"] and data["net_model"] not in conn.get_network_models(data["arch"]):
|
||||
|
|
@ -949,6 +960,7 @@ class CreateInstance(Kind):
|
|||
|
||||
def run(self, op, ctx):
|
||||
data = op.params
|
||||
io_mode = _disk_io(data) # Settings may have changed since the job was asked for
|
||||
c = Compute.objects.get(pk=data["compute"])
|
||||
conn = wvmCreate(c.hostname, c.login, c.password, c.type)
|
||||
meta_prealloc = bool(data["meta_prealloc"])
|
||||
|
|
@ -967,7 +979,7 @@ class CreateInstance(Kind):
|
|||
"cache_mode": data["cache_mode"],
|
||||
"discard_mode": app_settings.INSTANCE_VOLUME_DEFAULT_DISCARD,
|
||||
"detect_zeroes_mode": app_settings.INSTANCE_VOLUME_DEFAULT_DETECT_ZEROES,
|
||||
"io_mode": app_settings.INSTANCE_VOLUME_DEFAULT_IO,
|
||||
"io_mode": io_mode,
|
||||
}
|
||||
|
||||
ctx.record_intent()
|
||||
|
|
|
|||
|
|
@ -80,6 +80,29 @@ class CreateJobTestCase(TransactionTestCase):
|
|||
self.assertEqual(response.status_code, 400)
|
||||
self.assertFalse(Operation.objects.exists())
|
||||
|
||||
def test_a_cache_that_does_not_go_with_the_settings_io_is_refused_and_the_io_kept(self):
|
||||
# libvirt refuses native I/O with a cache other than none or directsync, after the disks are made
|
||||
from appsettings.models import AppSettings
|
||||
|
||||
self.conn.get_cache_modes.return_value = {"none": "Disable cache", "writeback": "Write back"}
|
||||
# a TransactionTestCase run before may have emptied the table
|
||||
AppSettings.objects.update_or_create(key="INSTANCE_VOLUME_DEFAULT_IO", defaults={
|
||||
"name": "Disk IO Type", "value": "native", "choices": "default,native,threads"})
|
||||
url = f"/api/v1/computes/{self.compute.pk}/instances/create/x86_64/q35/"
|
||||
response = self.client.post(url, {**BODY, "cache_mode": "writeback"}, content_type="application/json")
|
||||
self.assertEqual(response.status_code, 400)
|
||||
self.assertIn("does not go with disk I/O native", str(response.json()))
|
||||
self.assertEqual(self.client.post(url, BODY, content_type="application/json").status_code, 202)
|
||||
# a pair Settings made one libvirt refuses after the job was asked for: refused before a disk is made
|
||||
op = Operation.objects.get()
|
||||
Operation.objects.filter(pk=op.pk).update(params={**op.params, "cache_mode": "writeback"})
|
||||
acquire("wvc-test:1:a", "wvc-test")
|
||||
Operation.objects.filter(pk=op.pk).update(state=Operation.RUNNING, worker="wvc-test:1:a")
|
||||
op.refresh_from_db()
|
||||
with self.assertRaisesRegex(OperationError, "does not go with disk I/O native"):
|
||||
CreateInstance().run(op, Context(op, SimpleNamespace(identity="wvc-test:1:a")))
|
||||
self.conn.create_volume.assert_not_called()
|
||||
|
||||
def test_the_cpu_is_a_mode_or_a_model_the_host_offers(self):
|
||||
url = f"/api/v1/computes/{self.compute.pk}/instances/create/x86_64/q35/"
|
||||
# a model name longer than 20 characters is taken; none, or one the host lacks, is refused
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue