Files
ProxMenux/oci/tests/test_same_image.py
T
MacRimi 1f9d2acef5 feat(oci): recover applications after a Proxmox reinstall, cluster records and AMD GPU profiles
The installation record of an OCI application travels with its container:
a copy inside the container and another in /etc/pve, written together
with the one kept on the host. A container restored on a newly installed
Proxmox, restored with another ID or moved to another node of a cluster
is recognised and registered again, with its private network, hookscript,
Rclone mount, host firewall rule and NVIDIA runtime. The Monitor offers
the same recovery from the Updates tab.

AMD GPUs are offered by generation. A GPU the ROCm image supports takes
the profile as it is; one of a supported family (Radeon 680M, 780M) is an
experimental option that asks for confirmation and is never proposed; an
older one is not offered. The GPU is checked with a real inference before
the installation accepts it. Recreate changes what runs recognition in an
installed Immich, between the CPU and a GPU of the host.

Updates:
- A failed update that is restored and checked removes its temporary
  container and the disks of the failed attempt.
- Every container volume is part of the backups, so Jellyfin, Plex and
  Hugo update with their default installation.
- An image published with a Docker-format manifest is recognised by its
  layers and build time and updates.
- The Proxmox notes of a multi-container application link to its LAN
  address.
2026-10-04 20:32:17 +02:00

48 lines
2.4 KiB
Python

"""An image is the same in the registry and in the archive made from it,
whichever format the registry publishes its manifest in."""
from pathlib import Path
import sys
import unittest
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / "remote"))
from oci_installation_state import same_image
REGISTRY = "sha256:" + "a" * 64
ARCHIVE = "sha256:" + "b" * 64
LAYERS = ["sha256:" + "c" * 64, "sha256:" + "d" * 64]
BUILT = "2026-09-15T01:13:55.019799592Z"
class SameImageTests(unittest.TestCase):
def test_an_oci_manifest_keeps_its_digest(self):
self.assertTrue(same_image({"manifest_digest": REGISTRY}, {"manifest_digest": REGISTRY}))
def test_a_docker_manifest_is_recognised_by_its_layers_and_when_it_was_built(self):
self.assertTrue(same_image({"manifest_digest": REGISTRY, "layers": LAYERS, "created": BUILT},
{"manifest_digest": ARCHIVE, "layers": list(LAYERS), "created": BUILT}))
def test_another_image_is_not_the_same(self):
candidate = {"manifest_digest": REGISTRY, "layers": LAYERS, "created": BUILT}
self.assertFalse(same_image(candidate, {"manifest_digest": ARCHIVE, "layers": LAYERS[:1], "created": BUILT}))
self.assertFalse(same_image(candidate, {"manifest_digest": ARCHIVE, "layers": LAYERS[::-1], "created": BUILT}))
# The same layers rebuilt with another configuration are another image.
self.assertFalse(same_image(candidate, {"manifest_digest": ARCHIVE, "layers": LAYERS,
"created": "2026-10-01T00:00:00Z"}))
def test_what_is_missing_never_matches(self):
self.assertFalse(same_image({"manifest_digest": REGISTRY}, {"manifest_digest": ARCHIVE}))
self.assertFalse(same_image({"manifest_digest": REGISTRY, "layers": [], "created": BUILT},
{"manifest_digest": ARCHIVE, "layers": [], "created": BUILT}))
self.assertFalse(same_image({"manifest_digest": REGISTRY, "layers": LAYERS, "created": None},
{"manifest_digest": ARCHIVE, "layers": LAYERS, "created": None}))
# A record saved before the layers were kept is compared by its digest alone.
self.assertFalse(same_image({"manifest_digest": REGISTRY, "layers": LAYERS, "created": BUILT},
{"manifest_digest": ARCHIVE}))
if __name__ == "__main__":
unittest.main()