mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-01 16:36:06 +00:00
fix: backups and snapshots keep their order when the clock goes back
Backup retention kept the last --keep backups by name, and a name is the panel's local time. Where the clock goes back an hour in autumn (TIME_ZONE=Europe/Berlin), a backup at 02:10 CET forty minutes after one at 02:50 CEST sorted first, and --keep 1 deleted the new one. Retention now keeps the newest by when they were made (the directory's mtime); the names stay as they were. Snapshot times from libvirt (epoch seconds) became naive local times, which the snapshot list sorts newest first: in the same hour the older snapshot came first. They are now aware UTC times; the page still shows them in the panel's time zone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea
This commit is contained in:
parent
0d20d07b29
commit
25e49c2aa2
4 changed files with 26 additions and 7 deletions
|
|
@ -65,7 +65,7 @@ from libvirt import (
|
|||
from libvirt_qemu import qemuAgentCommand
|
||||
|
||||
from collections import OrderedDict
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
from xml.etree import ElementTree
|
||||
|
||||
from lxml import etree
|
||||
|
|
@ -2136,7 +2136,8 @@ class wvmInstance(wvmConnect):
|
|||
detaches.setdefault(dev, path)
|
||||
snapshots.append(
|
||||
{
|
||||
"date": datetime.fromtimestamp(int(tree.findtext("creationTime"))),
|
||||
# aware: sorted in UTC, shown in the panel's time zone
|
||||
"date": datetime.fromtimestamp(int(tree.findtext("creationTime")), timezone.utc),
|
||||
"name": snap.getName(),
|
||||
"description": tree.findtext("description") or "",
|
||||
"memory": tree.find("memory[@snapshot='external']") is not None,
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ cases are in vrtManager/tests/test_live_snapshots.py."""
|
|||
|
||||
import json
|
||||
import unittest
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import libvirt
|
||||
|
|
@ -110,7 +110,8 @@ class SnapshotListTestCase(unittest.TestCase):
|
|||
[entry] = p.get_snapshot(EXTERNAL)
|
||||
self.assertEqual(entry["name"], "one")
|
||||
self.assertEqual(entry["description"], "d & e")
|
||||
self.assertEqual(entry["date"], datetime.fromtimestamp(1700000000))
|
||||
# aware: two snapshots an hour apart around an autumn clock change stay in order
|
||||
self.assertEqual(entry["date"], datetime(2023, 11, 14, 22, 13, 20, tzinfo=timezone.utc))
|
||||
self.assertTrue(entry["memory"])
|
||||
self.assertTrue(entry["current"])
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue