1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-08 11:16:47 +00:00

fix(instances): a clone size of a digit that is no number gets the form's refusal

clone_data checked the clone's vCPUs and memory with str.isdigit(), which
takes characters such as a superscript two that int() refuses: the user
saw Python's "invalid literal for int()" instead of the refusal. It now
checks with str.isdecimal(), whose characters int() reads.
This commit is contained in:
catborise 2026-11-05 08:46:27 +03:00
parent 337063bf7b
commit 02ab78fe94
2 changed files with 9 additions and 1 deletions

View file

@ -137,7 +137,7 @@ def clone_data(user, instance, fields):
("memory", instance.config_memory,
_("Enter a whole number of memory (MiB) for the clone"))):
value = fields.get(f"clone-{key}") or str(source)
if not value.isdigit() or int(value) < 1:
if not value.isdecimal() or int(value) < 1:
raise util.OperationError(refusal)
# None: as the VM, nothing to change after the copy
data[key] = int(value) if int(value) != source else None

View file

@ -6,6 +6,7 @@ from uuid import uuid4
import libvirt
from django.contrib.auth import get_user_model
from django.contrib.messages import get_messages
from django.core.exceptions import PermissionDenied
from django.test import TransactionTestCase
from django.urls import reverse
@ -116,6 +117,13 @@ class CloneJobTestCase(TransactionTestCase):
self.assertIsNone(op)
self.proxy.clone_instance.assert_not_called()
def test_a_digit_that_is_not_a_number_is_refused_with_the_reason(self):
# superscript two: str.isdigit() takes it, int() does not
response = self.client.post(reverse("instances:clone", args=[self.source.pk]),
{"name": "copy", "disk-vda": "copy.qcow2", "clone-net-mac-0": "52:54:00:00:00:01",
"submission_key": "key-clone003", "clone-vcpu": "\u00b2"})
self.assertEqual([str(m) for m in get_messages(response.wsgi_request)], ["Enter a whole number of vCPUs for the clone"])
def test_a_clone_that_cannot_start_is_made_with_a_warning(self):
self.proxy.start.side_effect = libvirt.libvirtError("no memory")
op, result = self.clone_with(**{"clone-start": "true"})