fix(storage): preserve retired Matrix containers during migration

This commit is contained in:
2026-09-28 14:00:27 +02:00
parent ec5e240ef1
commit e9b2e3e229
4 changed files with 111 additions and 16 deletions

View File

@@ -46,6 +46,45 @@ class HostSafetyTests(unittest.TestCase):
with self.assertRaises(m.Error):
m.validate_config(self.config, self.root)
def test_retired_matrix_remains_stopped_and_outside_compose(self):
container = {"Config": {"Labels": {"com.docker.compose.service": "matrix-redis"}},
"State": {"Running": False}, "HostConfig": {"RestartPolicy": {"Name": "no"}},
"Mounts": [{"Type": "volume", "Source": "/var/lib/docker/volumes/old/_data", "Destination": "/data"}]}
indexed, retained = m.index_containers(self.config, [container])
self.assertEqual(set(indexed), {"matrix-redis"})
self.assertEqual(retained, {"matrix-redis": {"volumes": []}})
self.assertNotIn("matrix-redis", self.config["services"])
mutations = [lambda c: c["State"].update(Running=True),
lambda c: c["State"].update(Restarting=True),
lambda c: c["State"].update(Paused=True),
lambda c: c["HostConfig"]["RestartPolicy"].update(Name="unless-stopped"),
lambda c: c["HostConfig"].update(AutoRemove=True),
lambda c: c["Config"]["Labels"].update({"com.docker.compose.service": "unknown"}),
lambda c: c["Config"]["Labels"].update({"com.docker.compose.oneoff": "True"}),
lambda c: c["Mounts"][0].update(Destination="/unexpected")]
for mutate in mutations:
changed = copy.deepcopy(container)
mutate(changed)
with self.assertRaises(m.Error):
m.index_containers(self.config, [changed])
with self.assertRaises(m.Error):
m.index_containers(self.config, [container, container])
def test_retired_matrix_bind_mounts_keep_strict_backup_validation(self):
container = {"Config": {"Labels": {"com.docker.compose.service": "matrix-db"}},
"State": {"Running": False}, "HostConfig": {"RestartPolicy": {"Name": "no"}},
"Mounts": [{"Type": "bind", "Source": "/outside/postgres", "Destination": "/var/lib/postgresql/data"}]}
migration = m.Migration(self.root)
_, retained = m.index_containers(self.config, [container])
migration.engine.current = {"services": retained}
migration.engine.retired_services = list(retained)
with self.assertRaises(m.Error):
migration.engine.validate_legacy_matrix()
(self.root / "matrix/postgres").mkdir(parents=True)
retained["matrix-db"]["volumes"][0]["source"] = str(self.root / "matrix/postgres")
migration.engine.validate_legacy_matrix()
self.assertEqual(migration.engine.matrix_backup_paths, ["matrix"])
def test_cold_index_detects_objects_hidden_by_minio_listing(self):
source = self.root / "minio"
(source / ".minio.sys").mkdir()