mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-10 20:26:48 +00:00
fix(appsettings): settings take only the values the panel can use
The Settings page saved whatever was posted, and some lists offered values the panel cannot use: - Quota Debug could not be turned off: "False" is a non-empty text and counted as on. - VM Clone Name Prefix showed as a True/False list, so no prefix could be typed, and touching it set the prefix to True. - Disk SCSI Controller listed " lsilogic" with a space, never shown as chosen, and virtio-blk, which is no SCSI controller. - VM Machine Type listed x86_64, an architecture; VM CD-ROM Device listed virtio, a bus a CD-ROM cannot use. - Logs per Page and Disk Owner UID/GID are read with int(): a letter broke the logs page and VM create. A migration fixes the lists and moves a value they no longer offer to the default (the clone prefix keeps its text). A listed setting now takes one of its choices, and every number setting a whole number in its range, checked before it is saved.
This commit is contained in:
parent
9cf2d55b6e
commit
7392a5b4d2
7 changed files with 132 additions and 9 deletions
|
|
@ -61,3 +61,29 @@ class WorkerSettingsTestCase(TestCase):
|
|||
limit = AppSettings._meta.get_field(field).max_length
|
||||
if limit:
|
||||
self.assertLessEqual(len(getattr(setting, field)), limit, f"{key} {field}")
|
||||
|
||||
|
||||
choices_fix = importlib.import_module("appsettings.migrations.0020_fix_setting_choices")
|
||||
|
||||
|
||||
class ChoicesFixTestCase(TestCase):
|
||||
"""Choices that offered values the panel cannot use, and a text setting
|
||||
that showed as a True/False list."""
|
||||
|
||||
def test_the_broken_choices_are_fixed_and_their_values_moved(self):
|
||||
broken = {
|
||||
"CLONE_INSTANCE_DEFAULT_PREFIX": ("instance", "True,False"),
|
||||
"INSTANCE_VOLUME_DEFAULT_SCSI_CONTROLLER": ("virtio-blk", "virtio-scsi, lsilogic, virtio-blk"),
|
||||
"INSTANCE_MACHINE_DEFAULT_TYPE": ("x86_64", "q35,x86_64,virt"),
|
||||
"INSTANCE_CDROM_ADD": ("virtio", "None,ide,sata,scsi,virtio"),
|
||||
}
|
||||
for key, (value, choices) in broken.items():
|
||||
AppSettings.objects.filter(key=key).update(value=value, choices=choices)
|
||||
choices_fix.fix_choices(apps, SimpleNamespace(connection=connection))
|
||||
fixed = {s.key: (s.value, s.choices) for s in AppSettings.objects.filter(key__in=broken)}
|
||||
self.assertEqual(fixed, {
|
||||
"CLONE_INSTANCE_DEFAULT_PREFIX": ("instance", ""),
|
||||
"INSTANCE_VOLUME_DEFAULT_SCSI_CONTROLLER": ("virtio-scsi", "virtio-scsi,lsilogic"),
|
||||
"INSTANCE_MACHINE_DEFAULT_TYPE": ("q35", "q35,pc,virt"),
|
||||
"INSTANCE_CDROM_ADD": ("sata", "None,ide,sata,scsi"),
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue