Mercurial > hg > orthanc-tests
annotate NewTests/PostgresUpgrades/test_pg_upgrades.py @ 641:ac88ebf92e83
added CITATION.cff
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 06 Apr 2024 17:31:18 +0200 |
parents | e1bc43b5a7d2 |
children |
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") | |
628 | 54 subprocesss_env = os.environ.copy() |
55 subprocesss_env["ORTHANC_IMAGE_UNDER_TESTS"] = Helpers.orthanc_under_tests_docker_image | |
607 | 56 subprocess.run(["docker", "compose", "up", "orthanc-pg-15-under-tests", "-d"], |
628 | 57 env=subprocesss_env, check=True) |
58 | |
607 | 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() | |
630 | 66 self.assertEqual(0, int(o.get_json('statistics')['TotalDiskSize'])) |
607 | 67 instances = o.upload_folder(here / "../../Database/Knee") |
630 | 68 size_before_downgrade = int(o.get_json('statistics')['TotalDiskSize']) |
607 | 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") | |
628 | 99 subprocesss_env = os.environ.copy() |
100 subprocesss_env["ORTHANC_IMAGE_UNDER_TESTS"] = Helpers.orthanc_under_tests_docker_image | |
599
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
101 subprocess.run(["docker", "compose", "up", "orthanc-pg-15-under-tests", "-d"], |
628 | 102 env=subprocesss_env, check=True) |
596 | 103 |
104 o = OrthancApiClient("http://localhost:8050") | |
105 o.wait_started() | |
106 | |
107 # make sure we can 'play' with Orthanc | |
108 o.instances.get_tags(orthanc_id=instances[0]) | |
109 o.instances.delete_all() | |
630 | 110 self.assertEqual(0, int(o.get_json('statistics')['TotalDiskSize'])) |
596 | 111 instances = o.upload_folder(here / "../../Database/Knee") |
630 | 112 size_before_downgrade = int(o.get_json('statistics')['TotalDiskSize']) |
596 | 113 |
599
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
114 print("Stopping newest Orthanc ") |
596 | 115 subprocess.run(["docker", "compose", "stop", "orthanc-pg-15-under-tests"], check=True) |
116 time.sleep(2) | |
117 | |
623 | 118 print("Downgrading Orthanc DB to Rev1") |
599
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
119 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
|
120 time.sleep(2) |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
121 |
623 | 122 print("Launching previous Orthanc (DB Rev1)") |
599
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
123 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
|
124 |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
125 o = OrthancApiClient("http://localhost:8052") |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
126 o.wait_started() |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
127 |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
128 # make sure we can 'play' with Orthanc |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
129 o.instances.get_tags(orthanc_id=instances[0]) |
630 | 130 self.assertEqual(size_before_downgrade, int(o.get_json('statistics')['TotalDiskSize'])) |
599
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
131 o.instances.delete_all() |
630 | 132 self.assertEqual(0, int(o.get_json('statistics')['TotalDiskSize'])) |
599
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
133 instances = o.upload_folder(here / "../../Database/Knee") |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
134 o.instances.delete_all() |
630 | 135 self.assertEqual(0, int(o.get_json('statistics')['TotalDiskSize'])) |
599
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
136 |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
137 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
|
138 # 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
|
139 # 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
|
140 |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
141 # 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
|
142 |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
143 # 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
|
144 # o.wait_started() |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
145 |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
146 # time.sleep(10000) |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
147 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
|
148 |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
149 |
596 | 150 |
151 def test_latest_orthanc_with_pg_9(self): | |
607 | 152 |
153 # remove everything including the DB from previous tests | |
154 TestPgUpgrades.cleanup() | |
155 | |
596 | 156 print("Launching PG-9 server") |
157 subprocess.run(["docker", "compose", "up", "pg-9", "-d"], check=True) | |
158 wait_container_healthy("pg-9") | |
159 | |
160 print("Launching newest Orthanc") | |
628 | 161 subprocesss_env = os.environ.copy() |
162 subprocesss_env["ORTHANC_IMAGE_UNDER_TESTS"] = Helpers.orthanc_under_tests_docker_image | |
163 subprocess.run(["docker", "compose", "up", "orthanc-pg-9-under-tests", "-d"], | |
164 env=subprocesss_env, check=True) | |
596 | 165 |
166 o = OrthancApiClient("http://localhost:8051") | |
167 o.wait_started() | |
168 instances = o.upload_folder(here / "../../Database/Knee") | |
169 o.instances.delete(orthanc_ids=instances) | |
170 | |
171 subprocess.run(["docker", "compose", "down", "-v", "--remove-orphans"], check=True) |