mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 17:36:05 +00:00
fix(appsettings): settings that new VMs and clones cannot use are refused
Disk I/O native was saved with a disk cache other than none or
directsync; libvirt refuses such a disk ("io='native' needs either no
disk cache or directsync cache mode"), so every new VM failed. The pair
is now checked together when either is saved.
A clone name prefix with a space or another character a clone's name
cannot have was saved; every name the clone dialog then offered a user
who is not a superuser was refused, and they could not clone at all.
The prefix now takes letters, digits and '-' only.
This commit is contained in:
parent
d00f7d8841
commit
3bd519c935
6 changed files with 97 additions and 34 deletions
|
|
@ -73,6 +73,8 @@ class AppSettingsTestCase(TestCase):
|
|||
|
||||
def post(self, key, value):
|
||||
response = self.client.post(reverse("appsettings"), {key: value})
|
||||
# not followed: the messages would stay in the cookie for the next post
|
||||
self.client.cookies.pop("messages", None)
|
||||
return [str(m) for m in get_messages(response.wsgi_request)]
|
||||
|
||||
def test_a_listed_setting_takes_only_its_choices(self):
|
||||
|
|
@ -99,6 +101,30 @@ class AppSettingsTestCase(TestCase):
|
|||
page = self.client.get(reverse("appsettings")).content.decode()
|
||||
self.assertIn('name="CLONE_INSTANCE_DEFAULT_PREFIX" value="web-"', page)
|
||||
|
||||
def test_the_clone_name_prefix_makes_clone_names(self):
|
||||
# every name offered to a user who is not a superuser would be refused
|
||||
for bad in ("bad prefix", "web_"):
|
||||
with self.subTest(bad=bad):
|
||||
self.assertTrue(any("letters, digits and '-' only" in m for m in self.post("CLONE_INSTANCE_DEFAULT_PREFIX", bad)))
|
||||
self.assertEqual(AppSettings.objects.get(key="CLONE_INSTANCE_DEFAULT_PREFIX").value, "instance")
|
||||
|
||||
def test_native_disk_io_needs_a_cache_libvirt_takes_with_it(self):
|
||||
# libvirt: "io='native' needs either no disk cache or directsync cache mode"
|
||||
self.post("INSTANCE_VOLUME_DEFAULT_CACHE", "writeback")
|
||||
self.assertTrue(any("needs disk cache none or directsync" in m
|
||||
for m in self.post("INSTANCE_VOLUME_DEFAULT_IO", "native")))
|
||||
self.assertEqual(AppSettings.objects.get(key="INSTANCE_VOLUME_DEFAULT_IO").value, "default")
|
||||
response = self.client.post(reverse("appsettings"), {"INSTANCE_VOLUME_DEFAULT_CACHE": "none",
|
||||
"INSTANCE_VOLUME_DEFAULT_IO": "native"})
|
||||
self.assertEqual(response.status_code, 302)
|
||||
self.assertEqual(AppSettings.objects.get(key="INSTANCE_VOLUME_DEFAULT_IO").value, "native")
|
||||
self.assertTrue(any("needs disk cache" in m for m in self.post("INSTANCE_VOLUME_DEFAULT_CACHE", "unsafe")))
|
||||
self.assertEqual(AppSettings.objects.get(key="INSTANCE_VOLUME_DEFAULT_CACHE").value, "none")
|
||||
# a pair saved before does not block another setting
|
||||
AppSettings.objects.filter(key="INSTANCE_VOLUME_DEFAULT_CACHE").update(value="writeback")
|
||||
self.post("LOGS_PER_PAGE", "50")
|
||||
self.assertEqual(AppSettings.objects.get(key="LOGS_PER_PAGE").value, "50")
|
||||
|
||||
def page(self):
|
||||
from lxml import html
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue