Mercurial > hg > orthanc-tests
annotate NewTests/PostgresUpgrades/test_pg_upgrades.py @ 605:76e5f75249ca
fix
author | Alain Mazy <am@osimis.io> |
---|---|
date | Tue, 23 Jan 2024 10:21:30 +0100 |
parents | 3e15e950c462 |
children | d743c210cbc8 |
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 |
596 | 30 def test_upgrades_downgrades_with_pg_15(self): |
31 | |
600
58384ae69f41
added docker pull to avoid timeout
Alain Mazy <am@osimis.io>
parents:
599
diff
changeset
|
32 print("Pullling container") |
58384ae69f41
added docker pull to avoid timeout
Alain Mazy <am@osimis.io>
parents:
599
diff
changeset
|
33 subprocess.run(["docker", "compose", "pull"], check=True) |
58384ae69f41
added docker pull to avoid timeout
Alain Mazy <am@osimis.io>
parents:
599
diff
changeset
|
34 |
596 | 35 print("Launching PG-15 server") |
36 subprocess.run(["docker", "compose", "up", "pg-15", "-d"], check=True) | |
37 wait_container_healthy("pg-15") | |
38 | |
39 print("Launching old Orthanc (PG v2.0)") | |
40 subprocess.run(["docker", "compose", "up", "orthanc-pg-15-2", "-d"], check=True) | |
41 | |
42 o = OrthancApiClient("http://localhost:8049") | |
43 o.wait_started() | |
44 | |
45 instances = o.upload_folder(here / "../../Database/Knee") | |
46 | |
47 print("Stopping old Orthanc ") | |
48 subprocess.run(["docker", "compose", "stop", "orthanc-pg-15-2"], check=True) | |
49 time.sleep(2) | |
50 | |
51 print("Launching newest Orthanc") | |
599
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
52 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
|
53 env= { |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
54 "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
|
55 }, |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
56 check=True) |
596 | 57 |
58 o = OrthancApiClient("http://localhost:8050") | |
59 o.wait_started() | |
60 | |
61 # make sure we can 'play' with Orthanc | |
62 o.instances.get_tags(orthanc_id=instances[0]) | |
63 o.instances.delete_all() | |
599
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
64 self.assertEqual(0, int(o.get_json('/statistics')['TotalDiskSize'])) |
596 | 65 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
|
66 size_before_downgrade = int(o.get_json('/statistics')['TotalDiskSize']) |
596 | 67 |
599
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
68 print("Stopping newest Orthanc ") |
596 | 69 subprocess.run(["docker", "compose", "stop", "orthanc-pg-15-under-tests"], check=True) |
70 time.sleep(2) | |
71 | |
599
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
72 print("Downgrading Orthanc DB to v6.1") |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
73 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
|
74 time.sleep(2) |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
75 |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
76 print("Downgrading Orthanc DB to v6.1") |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
77 print("Launching previous Orthanc (DB v6.1)") |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
78 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
|
79 |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
80 o = OrthancApiClient("http://localhost:8052") |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
81 o.wait_started() |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
82 |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
83 # make sure we can 'play' with Orthanc |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
84 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
|
85 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
|
86 o.instances.delete_all() |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
87 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
|
88 instances = o.upload_folder(here / "../../Database/Knee") |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
89 o.instances.delete_all() |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
90 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
|
91 |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
92 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
|
93 # 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
|
94 # 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
|
95 |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
96 # 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
|
97 |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
98 # 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
|
99 # o.wait_started() |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
100 |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
101 # time.sleep(10000) |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
102 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
|
103 |
f3475c3e42e5
run integ tests after a PG downgrade
Alain Mazy <am@osimis.io>
parents:
596
diff
changeset
|
104 |
596 | 105 |
106 def test_latest_orthanc_with_pg_9(self): | |
107 print("Launching PG-9 server") | |
108 subprocess.run(["docker", "compose", "up", "pg-9", "-d"], check=True) | |
109 wait_container_healthy("pg-9") | |
110 | |
111 print("Launching newest Orthanc") | |
112 subprocess.run( | |
113 ["docker", "compose", "up", "orthanc-pg-9-under-tests", "-d"], | |
114 env= { | |
115 "ORTHANC_IMAGE_UNDER_TESTS": Helpers.orthanc_under_tests_docker_image | |
116 }, | |
117 check=True) | |
118 | |
119 o = OrthancApiClient("http://localhost:8051") | |
120 o.wait_started() | |
121 instances = o.upload_folder(here / "../../Database/Knee") | |
122 o.instances.delete(orthanc_ids=instances) | |
123 | |
124 subprocess.run(["docker", "compose", "down", "-v", "--remove-orphans"], check=True) |