mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-11 12:46:49 +00:00
feat(instances): a running VM's XML can be edited for its next start
The XML editor of a running or paused VM only showed its XML. It now shows the persistent definition, the one the VM starts with next (with secrets, like the other edit forms), and Change saves it through the same review dialog; the running VM keeps its live configuration until it restarts. The tab and the saved message say so. The check against a definition changed since the editor was opened covers this case too.
This commit is contained in:
parent
3f329b50dd
commit
ec679d4d7a
6 changed files with 49 additions and 55 deletions
|
|
@ -7,15 +7,18 @@ from django.test import TestCase
|
|||
from django.urls import reverse
|
||||
from instances.models import Instance
|
||||
from libvirt import libvirtError
|
||||
from vrtManager.instance import PERSISTENT_XML
|
||||
from logs.models import Logs
|
||||
|
||||
CURRENT = "<domain>\n <name>xml-vm</name>\n <memory>1024</memory>\n</domain>"
|
||||
LIVE = "<domain id='3'>\n <name>xml-vm</name>\n <memory>512</memory>\n</domain>"
|
||||
EDITED = "<domain>\n <name>xml-vm</name>\n <memory>2048</memory>\n</domain>"
|
||||
|
||||
|
||||
class ChangeXmlTestCase(TestCase):
|
||||
"""The XML editor shows what a change does before it is saved, and saves
|
||||
only over the definition it was opened with."""
|
||||
only over the definition it was opened with: the persistent one, which a
|
||||
running VM uses at its next start."""
|
||||
|
||||
def setUp(self):
|
||||
self.client.force_login(get_user_model().objects.create_superuser("xml_admin", "x@example.com", "pw"))
|
||||
|
|
@ -28,7 +31,7 @@ class ChangeXmlTestCase(TestCase):
|
|||
data["confirm"] = "1"
|
||||
with patch("instances.models.wvmInstance") as wvm:
|
||||
wvm.return_value.get_status.return_value = status
|
||||
wvm.return_value._XMLDesc.return_value = CURRENT
|
||||
wvm.return_value._XMLDesc.side_effect = lambda flags: CURRENT if flags == PERSISTENT_XML else LIVE
|
||||
wvm.return_value._defineXML.side_effect = define_error
|
||||
response = self.client.post(reverse("instances:change_xml", args=[self.instance.id]), data)
|
||||
return response, wvm.return_value._defineXML
|
||||
|
|
@ -67,13 +70,12 @@ class ChangeXmlTestCase(TestCase):
|
|||
row = Logs.objects.get(instance_uuid=self.instance.uuid)
|
||||
self.assertEqual((row.message, row.success), ("VM xml-vm: change XML: unsupported configuration: bad memory", False))
|
||||
|
||||
def test_running_or_paused_vm_is_refused(self):
|
||||
def test_a_running_or_paused_vm_gets_the_definition_for_its_next_start(self):
|
||||
for status in (1, 3):
|
||||
with self.subTest(status=status):
|
||||
response, define = self.post(status, confirm=True)
|
||||
define.assert_not_called()
|
||||
self.assertEqual(response.status_code, 409)
|
||||
self.assertIn("Power off", response.json()["error"])
|
||||
define.assert_called_once_with(EDITED)
|
||||
self.assertIn("next start", " ".join(str(m) for m in get_messages(response.wsgi_request)))
|
||||
|
||||
def test_the_line_breaks_a_form_posts_are_the_same_definition(self):
|
||||
response, _ = self.post(base=CURRENT.replace("\n", "\r\n"))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue