comparison NewTests/PostgresUpgrades/test_pg_upgrades.py @ 596:b1e1c7149a37

new PG upgrades tests
author Alain Mazy <am@osimis.io>
date Thu, 21 Dec 2023 18:02:49 +0100
parents
children f3475c3e42e5
comparison
equal deleted inserted replaced
595:b6c1f0c9ca15 596:b1e1c7149a37
1 import subprocess
2 import time
3 import unittest
4 from orthanc_api_client import OrthancApiClient
5 from helpers import Helpers
6
7 import pathlib
8 import os
9 here = pathlib.Path(__file__).parent.resolve()
10
11
12 def get_container_health(container_name):
13 try:
14 # Run the docker inspect command
15 result = subprocess.run(
16 ["docker", "inspect", "--format", "{{.State.Health.Status}}", container_name],
17 capture_output=True,
18 text=True,
19 check=True,
20 )
21
22 # Extract the health status from the command output
23 return result.stdout.strip()
24
25 except subprocess.CalledProcessError as e:
26 print(f"Error checking container health: {e}")
27 return None
28
29 def wait_container_healthy(container_name):
30 retry = 0
31
32 while (get_container_health(container_name) != "healthy" and retry < 200):
33 print(f"Waiting for {container_name} to be healty")
34 time.sleep(1)
35
36 class TestPgUpgrades(unittest.TestCase):
37
38 @classmethod
39 def setUpClass(cls):
40 os.chdir(here)
41 print("Cleaning old compose")
42 subprocess.run(["docker", "compose", "down", "-v", "--remove-orphans"], check=True)
43
44 def test_upgrades_downgrades_with_pg_15(self):
45
46 print("Launching PG-15 server")
47 subprocess.run(["docker", "compose", "up", "pg-15", "-d"], check=True)
48 wait_container_healthy("pg-15")
49
50 print("Launching old Orthanc (PG v2.0)")
51 subprocess.run(["docker", "compose", "up", "orthanc-pg-15-2", "-d"], check=True)
52
53 o = OrthancApiClient("http://localhost:8049")
54 o.wait_started()
55
56 instances = o.upload_folder(here / "../../Database/Knee")
57
58 print("Stopping old Orthanc ")
59 subprocess.run(["docker", "compose", "stop", "orthanc-pg-15-2"], check=True)
60 time.sleep(2)
61
62 print("Launching newest Orthanc")
63 subprocess.run(["docker", "compose", "up", "orthanc-pg-15-under-tests", "-d"], check=True)
64
65 o = OrthancApiClient("http://localhost:8050")
66 o.wait_started()
67
68 # make sure we can 'play' with Orthanc
69 o.instances.get_tags(orthanc_id=instances[0])
70 o.instances.delete_all()
71 instances = o.upload_folder(here / "../../Database/Knee")
72
73 print("Stopping new Orthanc ")
74 subprocess.run(["docker", "compose", "stop", "orthanc-pg-15-under-tests"], check=True)
75 time.sleep(2)
76
77 print("TODO Downgrading Orthanc DB and restart an Orthanc 23.12.1")
78 # ...
79
80 def test_latest_orthanc_with_pg_9(self):
81 print("Launching PG-9 server")
82 subprocess.run(["docker", "compose", "up", "pg-9", "-d"], check=True)
83 wait_container_healthy("pg-9")
84
85 print("Launching newest Orthanc")
86 subprocess.run(
87 ["docker", "compose", "up", "orthanc-pg-9-under-tests", "-d"],
88 env= {
89 "ORTHANC_IMAGE_UNDER_TESTS": Helpers.orthanc_under_tests_docker_image
90 },
91 check=True)
92
93 o = OrthancApiClient("http://localhost:8051")
94 o.wait_started()
95 instances = o.upload_folder(here / "../../Database/Knee")
96 o.instances.delete(orthanc_ids=instances)
97
98 subprocess.run(["docker", "compose", "down", "-v", "--remove-orphans"], check=True)