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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
596
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
1 import subprocess
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
2 import time
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
3 import unittest
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
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
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
6
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
7 import pathlib
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
8 import os
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
9 here = pathlib.Path(__file__).parent.resolve()
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
10
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
11
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
12 class TestPgUpgrades(unittest.TestCase):
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
13
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
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
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
16 os.chdir(here)
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
17 print("Cleaning old compose")
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
18 subprocess.run(["docker", "compose", "down", "-v", "--remove-orphans"], check=True)
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
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
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
30 def test_upgrades_downgrades_with_pg_15(self):
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
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
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
35 print("Launching PG-15 server")
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
36 subprocess.run(["docker", "compose", "up", "pg-15", "-d"], check=True)
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
37 wait_container_healthy("pg-15")
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
38
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
39 print("Launching old Orthanc (PG v2.0)")
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
40 subprocess.run(["docker", "compose", "up", "orthanc-pg-15-2", "-d"], check=True)
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
41
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
42 o = OrthancApiClient("http://localhost:8049")
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
43 o.wait_started()
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
44
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
45 instances = o.upload_folder(here / "../../Database/Knee")
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
46
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
47 print("Stopping old Orthanc ")
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
48 subprocess.run(["docker", "compose", "stop", "orthanc-pg-15-2"], check=True)
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
49 time.sleep(2)
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
50
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
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
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
57
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
58 o = OrthancApiClient("http://localhost:8050")
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
59 o.wait_started()
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
60
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
61 # make sure we can 'play' with Orthanc
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
62 o.instances.get_tags(orthanc_id=instances[0])
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
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
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
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
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
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
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
69 subprocess.run(["docker", "compose", "stop", "orthanc-pg-15-under-tests"], check=True)
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
70 time.sleep(2)
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
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
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
105
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
106 def test_latest_orthanc_with_pg_9(self):
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
107 print("Launching PG-9 server")
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
108 subprocess.run(["docker", "compose", "up", "pg-9", "-d"], check=True)
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
109 wait_container_healthy("pg-9")
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
110
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
111 print("Launching newest Orthanc")
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
112 subprocess.run(
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
113 ["docker", "compose", "up", "orthanc-pg-9-under-tests", "-d"],
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
114 env= {
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
115 "ORTHANC_IMAGE_UNDER_TESTS": Helpers.orthanc_under_tests_docker_image
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
116 },
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
117 check=True)
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
118
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
119 o = OrthancApiClient("http://localhost:8051")
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
120 o.wait_started()
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
121 instances = o.upload_folder(here / "../../Database/Knee")
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
122 o.instances.delete(orthanc_ids=instances)
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
123
b1e1c7149a37 new PG upgrades tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
124 subprocess.run(["docker", "compose", "down", "-v", "--remove-orphans"], check=True)