62 lines
2.8 KiB
Python
62 lines
2.8 KiB
Python
#!/usr/bin/env python3
|
|
"""The drill mover moves every service that carries the app's own image, also when two services share one image
|
|
(dawarich + dawarich-sidekiq on freikin/dawarich — the 2026-10-28 walk stopped with „FROM ref not found").
|
|
Run: python3 scripts/test_box_walk_drill_move.py"""
|
|
import os
|
|
import sys
|
|
import unittest
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
import box_walk as w # noqa: E402
|
|
|
|
TWO = """services:
|
|
dawarich:
|
|
image: freikin/dawarich:1.15.3
|
|
dawarich-sidekiq:
|
|
image: freikin/dawarich:1.15.3
|
|
dawarich-db:
|
|
image: postgis/postgis:17-3.5-alpine
|
|
"""
|
|
|
|
|
|
class DrillMove(unittest.TestCase):
|
|
def test_shared_image_moves_both_services(self):
|
|
out, missing = w.move_images(TWO, ["freikin/dawarich:1.15.3", "freikin/dawarich:1.15.3"],
|
|
["freikin/dawarich:1.19.0", "freikin/dawarich:1.19.0"])
|
|
self.assertIsNone(missing)
|
|
self.assertEqual(out.count("image: freikin/dawarich:1.19.0"), 2)
|
|
self.assertNotIn("1.15.3", out)
|
|
self.assertIn("image: postgis/postgis:17-3.5-alpine", out) # the engine sidecar stays
|
|
|
|
def test_two_images_move_each(self):
|
|
s = "a:\n image: x/back:v1\nb:\n image: x/front:v1\n"
|
|
out, missing = w.move_images(s, ["x/back:v1", "x/front:v1"], ["x/back:v2", "x/front:v2"])
|
|
self.assertIsNone(missing)
|
|
self.assertEqual(out, "a:\n image: x/back:v2\nb:\n image: x/front:v2\n")
|
|
|
|
def test_missing_from_is_refused(self):
|
|
out, missing = w.move_images(TWO, ["freikin/dawarich:1.14.0"], ["freikin/dawarich:1.19.0"])
|
|
self.assertEqual(missing, "freikin/dawarich:1.14.0")
|
|
self.assertEqual(out, TWO)
|
|
|
|
def test_one_image_two_targets_is_refused(self):
|
|
out, missing = w.move_images(TWO, ["freikin/dawarich:1.15.3", "freikin/dawarich:1.15.3"],
|
|
["freikin/dawarich:1.19.0", "freikin/dawarich:1.18.0"])
|
|
self.assertEqual(missing, "freikin/dawarich:1.15.3")
|
|
self.assertEqual(out, TWO)
|
|
|
|
def test_walk_loads_the_drill_into_the_box_before_the_install(self):
|
|
# 2026-10-28: a drill revert never reached 9202's mirror; the walk installed the OLD head's TO as FROM
|
|
src = open(w.__file__).read()
|
|
body = src[src.index("def security_walk("):]
|
|
body = body[:body.index("rec[\"drill_commit\"]")]
|
|
self.assertIn("refresh_box_mirror()", body, "security_walk installs FROM without loading the drill into the box")
|
|
self.assertLess(body.index("refresh_box_mirror()"), body.index("deploy(app, sub, values)"))
|
|
|
|
def test_mover_uses_move_images(self):
|
|
self.assertIn("move_images(s, froms, tos)", open(w.__file__).read(), "_drill_bump no longer calls move_images")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|