Mercurial > hg > orthanc-tests
annotate NewTests/PostgresUpgrades/test_pg_upgrades.py @ 617:6ba2ff41ea52
fxi
author | Alain Mazy <am@osimis.io> |
---|---|
date | Mon, 05 Feb 2024 14:24:36 +0100 |
parents | d743c210cbc8 |
children | 3bb4b2589030 |
rev | line source |
---|---|
596 | 1 import subprocess |
2 import time | |
3 import unittest | |
4 from orthanc_api_client import OrthancApiClient | |
601
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
600
diff
changeset
|
5 from helpers import Helpers, wait_container_healthy |
596 | 6 |
7 import pathlib | |
8 import os | |
9 here = pathlib.Path(__file__).parent.resolve() | |
10 | |
11 | |
12 class TestPgUpgrades(unittest.TestCase): | |
13 | |
14 @classmethod | |
599
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
15 def cleanup(cls): |
596 | 16 os.chdir(here) |
17 print("Cleaning old compose") | |
18 subprocess.run(["docker", "compose", "down", "-v", "--remove-orphans"], check=True) | |
19 | |
599
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
20 |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
21 @classmethod |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
22 def setUpClass(cls): |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
23 cls.cleanup() |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
24 |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
25 @classmethod |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
26 def tearDownClass(cls): |
601
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
600
diff
changeset
|
27 cls.cleanup() |
599
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
28 |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
29 |
607 | 30 def test_upgrade_61_to_62(self): |
31 # remove everything including the DB from previous tests | |
32 TestPgUpgrades.cleanup() | |
33 | |
34 print("Pullling container") | |
35 subprocess.run(["docker", "compose", "pull"], check=True) | |
36 | |
37 print("Launching PG-15 server") | |
38 subprocess.run(["docker", "compose", "up", "pg-15", "-d"], check=True) | |
39 wait_container_healthy("pg-15") | |
40 | |
41 print("Launching Orthanc with 6.1 DB") | |
42 subprocess.run(["docker", "compose", "up", "orthanc-pg-15-61", "-d"], check=True) | |
43 | |
44 o = OrthancApiClient("http://localhost:8052") | |
45 o.wait_started() | |
46 | |
47 instances = o.upload_folder(here / "../../Database/Knee") | |
48 | |
49 print("Stopping Orthanc with 6.1 DB") | |
50 subprocess.run(["docker", "compose", "stop", "orthanc-pg-15-61"], check=True) | |
51 time.sleep(2) | |
52 | |
53 print("Launching newest Orthanc") | |
54 subprocess.run(["docker", "compose", "up", "orthanc-pg-15-under-tests", "-d"], | |
55 env= { | |
56 "ORTHANC_IMAGE_UNDER_TESTS": Helpers.orthanc_under_tests_docker_image | |
57 }, | |
58 check=True) | |
59 | |
60 o = OrthancApiClient("http://localhost:8050") | |
61 o.wait_started() | |
62 | |
63 # make sure we can 'play' with this Orthanc | |
64 o.instances.get_tags(orthanc_id=instances[0]) | |
65 o.instances.delete_all() | |
66 self.assertEqual(0, int(o.get_json('/statistics')['TotalDiskSize'])) | |
67 instances = o.upload_folder(here / "../../Database/Knee") | |
68 size_before_downgrade = int(o.get_json('/statistics')['TotalDiskSize']) | |
69 | |
70 print("Stopping newest Orthanc ") | |
71 subprocess.run(["docker", "compose", "stop", "orthanc-pg-15-under-tests"], check=True) | |
72 time.sleep(2) | |
73 | |
596 | 74 def test_upgrades_downgrades_with_pg_15(self): |
75 | |
607 | 76 # remove everything including the DB from previous tests |
77 TestPgUpgrades.cleanup() | |
78 | |
600
58384ae69f41
added docker pull to avoid timeout
Alain Mazy <am@osimis.io>
parents:
599
diff
changeset
|
79 print("Pullling container") |
58384ae69f41
added docker pull to avoid timeout
Alain Mazy <am@osimis.io>
parents:
599
diff
changeset
|
80 subprocess.run(["docker", "compose", "pull"], check=True) |
58384ae69f41
added docker pull to avoid timeout
Alain Mazy <am@osimis.io>
parents:
599
diff
changeset
|
81 |
596 | 82 print("Launching PG-15 server") |
83 subprocess.run(["docker", "compose", "up", "pg-15", "-d"], check=True) | |
84 wait_container_healthy("pg-15") | |
85 | |
86 print("Launching old Orthanc (PG v2.0)") | |
87 subprocess.run(["docker", "compose", "up", "orthanc-pg-15-2", "-d"], check=True) | |
88 | |
89 o = OrthancApiClient("http://localhost:8049") | |
90 o.wait_started() | |
91 | |
92 instances = o.upload_folder(here / "../../Database/Knee") | |
93 | |
94 print("Stopping old Orthanc ") | |
95 subprocess.run(["docker", "compose", "stop", "orthanc-pg-15-2"], check=True) | |
96 time.sleep(2) | |
97 | |
98 print("Launching newest Orthanc") | |
599
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
99 subprocess.run(["docker", "compose", "up", "orthanc-pg-15-under-tests", "-d"], |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
100 env= { |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
101 "ORTHANC_IMAGE_UNDER_TESTS": Helpers.orthanc_under_tests_docker_image |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
102 }, |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
103 check=True) |
596 | 104 |
105 o = OrthancApiClient("http://localhost:8050") | |
106 o.wait_started() | |
107 | |
108 # make sure we can 'play' with Orthanc | |
109 o.instances.get_tags(orthanc_id=instances[0]) | |
110 o.instances.delete_all() | |
599
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
111 self.assertEqual(0, int(o.get_json('/statistics')['TotalDiskSize'])) |
596 | 112 instances = o.upload_folder(here / "../../Database/Knee") |
599
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
113 size_before_downgrade = int(o.get_json('/statistics')['TotalDiskSize']) |
596 | 114 |
599
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
115 print("Stopping newest Orthanc ") |
596 | 116 subprocess.run(["docker", "compose", "stop", "orthanc-pg-15-under-tests"], check=True) |
117 time.sleep(2) | |
118 | |
599
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
119 print("Downgrading Orthanc DB to v6.1") |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
120 subprocess.run(["docker", "exec", "pg-15", "./scripts/downgrade.sh"], check=True) |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
121 time.sleep(2) |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
122 |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
123 print("Downgrading Orthanc DB to v6.1") |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
124 print("Launching previous Orthanc (DB v6.1)") |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
125 subprocess.run(["docker", "compose", "up", "orthanc-pg-15-61", "-d"], check=True) |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
126 |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
127 o = OrthancApiClient("http://localhost:8052") |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
128 o.wait_started() |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
129 |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
130 # make sure we can 'play' with Orthanc |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
131 o.instances.get_tags(orthanc_id=instances[0]) |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
132 self.assertEqual(size_before_downgrade, int(o.get_json('/statistics')['TotalDiskSize'])) |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
133 o.instances.delete_all() |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
134 self.assertEqual(0, int(o.get_json('/statistics')['TotalDiskSize'])) |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
135 instances = o.upload_folder(here / "../../Database/Knee") |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
136 o.instances.delete_all() |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
137 self.assertEqual(0, int(o.get_json('/statistics')['TotalDiskSize'])) |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
138 |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
139 print("run the integration tests after a downgrade") |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
140 # first create the containers (orthanc-tests + orthanc-pg-15-61-for-integ-tests) so they know each other |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
141 # subprocess.run(["docker", "compose", "create", "orthanc-tests"], check=True) |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
142 |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
143 # subprocess.run(["docker", "compose", "up", "orthanc-pg-15-61-for-integ-tests", "-d"], check=True) |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
144 |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
145 # o = OrthancApiClient("http://localhost:8053", user="alice", pwd="orthanctest") |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
146 # o.wait_started() |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
147 |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
148 # time.sleep(10000) |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
149 subprocess.run(["docker", "compose", "up", "orthanc-tests"], check=True) |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
150 |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
151 |
596 | 152 |
153 def test_latest_orthanc_with_pg_9(self): | |
607 | 154 |
155 # remove everything including the DB from previous tests | |
156 TestPgUpgrades.cleanup() | |
157 | |
596 | 158 print("Launching PG-9 server") |
159 subprocess.run(["docker", "compose", "up", "pg-9", "-d"], check=True) | |
160 wait_container_healthy("pg-9") | |
161 | |
162 print("Launching newest Orthanc") | |
163 subprocess.run( | |
164 ["docker", "compose", "up", "orthanc-pg-9-under-tests", "-d"], | |
165 env= { | |
166 "ORTHANC_IMAGE_UNDER_TESTS": Helpers.orthanc_under_tests_docker_image | |
167 }, | |
168 check=True) | |
169 | |
170 o = OrthancApiClient("http://localhost:8051") | |
171 o.wait_started() | |
172 instances = o.upload_folder(here / "../../Database/Knee") | |
173 o.instances.delete(orthanc_ids=instances) | |
174 | |
175 subprocess.run(["docker", "compose", "down", "-v", "--remove-orphans"], check=True) |