1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-09 03:36:48 +00:00

fix(instances): the revert confirmation says the VM restarts

Reverting a running or paused VM to a disk-only external snapshot
powers it off: libvirt starts it again from the snapshot's disks, as
after a power cut. The confirmation now says so for such a snapshot; a
snapshot with memory resumes the VM as it was saved.
This commit is contained in:
catborise 2026-10-13 07:50:51 +03:00
parent 5388743053
commit 64ea12b0ce
2 changed files with 8 additions and 1 deletions

View file

@ -147,7 +147,7 @@
{% csrf_token %}
<input type="hidden" name="name" value="{{ ext_snap.name }}">
<button type="submit" class="btn btn-sm btn-primary" name="revert_external_snapshot" title="{% trans 'Revert to this Snapshot' %}"
data-confirm="{% trans 'Revert to this snapshot? Changes made since it are lost.' %}{% if ext_snap.detaches %} {% trans 'These disks are detached; their writes since the current snapshot are discarded and their files are kept:' %} {% for d in ext_snap.detaches %}{{ d.dev }} ({{ d.path }}){% if not forloop.last %}, {% endif %}{% endfor %}.{% endif %}{% if instance.nvram %} {% trans 'Firmware variables (NVRAM) are not restored.' %}{% endif %}"
data-confirm="{% trans 'Revert to this snapshot? Changes made since it are lost.' %}{% if not ext_snap.memory %}{% if instance.status == 1 or instance.status == 3 %} {% trans "The VM is powered off and starts again from the snapshot's disks, as after a power cut." %}{% endif %}{% endif %}{% if ext_snap.detaches %} {% trans 'These disks are detached; their writes since the current snapshot are discarded and their files are kept:' %} {% for d in ext_snap.detaches %}{{ d.dev }} ({{ d.path }}){% if not forloop.last %}, {% endif %}{% endfor %}.{% endif %}{% if instance.nvram %} {% trans 'Firmware variables (NVRAM) are not restored.' %}{% endif %}"
onclick="return confirm(this.dataset.confirm)" {% if busy %}disabled{% endif %}>
<span>{% bs_icon 'download' %} </span>
</button>

View file

@ -137,6 +137,13 @@ class SnapshotTabTestCase(TestCase):
doc = self.page(external=[self.snap("e")], jobs=libvirt.libvirtError("no job info"))
self.assertEqual(len(doc.xpath("//button[@name='revert_external_snapshot']")), 1)
def test_revert_confirm_says_a_disk_only_revert_restarts_the_guest(self):
for status, memory, restarts in ((1, False, True), (3, False, True), (5, False, False), (1, True, False)):
with self.subTest(status=status, memory=memory):
doc = self.page(external=[self.snap("e", memory=memory)], status=status)
[button] = doc.xpath("//button[@name='revert_external_snapshot']")
self.assertEqual("powered off" in button.get("data-confirm"), restarts)
def test_memory_checkbox_only_for_a_running_vm(self):
self.assertFalse(self.page(status=1).xpath("//input[@name='memory']")[0].get("disabled"))
self.assertIsNotNone(self.page(status=5).xpath("//input[@name='memory']")[0].get("disabled"))