annotate NewTests/helpers.py @ 620:8ba9b20ae95f debug-pg-transactions

debug pg transactions tests
author Alain Mazy <am@osimis.io>
date Mon, 05 Feb 2024 22:32:39 +0100
parents 79812e0df162
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
1 import unittest
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
2 from orthanc_api_client import OrthancApiClient
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
3 import subprocess
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
4 import json
490
10a47656e34f new tests for MaximumStorageMode
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
5 import os
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
6 import typing
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
7 import shutil
592
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
8 import glob
601
3e15e950c462 new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents: 593
diff changeset
9 import time
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
10 from threading import Thread
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
11
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
12
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
13 import pathlib
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
14 here = pathlib.Path(__file__).parent.resolve()
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
15
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
16
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
17 default_base_config = {
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
18 "AuthenticationEnabled": False,
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
19 "RemoteAccessAllowed": True
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
20 }
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
21
490
10a47656e34f new tests for MaximumStorageMode
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
22
601
3e15e950c462 new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents: 593
diff changeset
23 def get_container_health(container_name):
3e15e950c462 new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents: 593
diff changeset
24 try:
3e15e950c462 new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents: 593
diff changeset
25 # Run the docker inspect command
3e15e950c462 new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents: 593
diff changeset
26 result = subprocess.run(
3e15e950c462 new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents: 593
diff changeset
27 ["docker", "inspect", "--format", "{{.State.Health.Status}}", container_name],
3e15e950c462 new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents: 593
diff changeset
28 capture_output=True,
3e15e950c462 new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents: 593
diff changeset
29 text=True,
3e15e950c462 new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents: 593
diff changeset
30 check=True,
3e15e950c462 new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents: 593
diff changeset
31 )
3e15e950c462 new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents: 593
diff changeset
32
3e15e950c462 new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents: 593
diff changeset
33 # Extract the health status from the command output
3e15e950c462 new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents: 593
diff changeset
34 return result.stdout.strip()
3e15e950c462 new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents: 593
diff changeset
35
3e15e950c462 new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents: 593
diff changeset
36 except subprocess.CalledProcessError as e:
3e15e950c462 new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents: 593
diff changeset
37 print(f"Error checking container health: {e}")
3e15e950c462 new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents: 593
diff changeset
38 return None
3e15e950c462 new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents: 593
diff changeset
39
3e15e950c462 new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents: 593
diff changeset
40 def wait_container_healthy(container_name):
3e15e950c462 new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents: 593
diff changeset
41 retry = 0
3e15e950c462 new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents: 593
diff changeset
42
3e15e950c462 new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents: 593
diff changeset
43 while (get_container_health(container_name) != "healthy" and retry < 200):
3e15e950c462 new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents: 593
diff changeset
44 print(f"Waiting for {container_name} to be healty")
3e15e950c462 new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents: 593
diff changeset
45 time.sleep(1)
3e15e950c462 new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents: 593
diff changeset
46
3e15e950c462 new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents: 593
diff changeset
47
3e15e950c462 new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents: 593
diff changeset
48
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
49 class Helpers:
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
50
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
51 orthanc_under_tests_hostname: str = 'localhost'
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
52 orthanc_under_tests_http_port: int = 8052
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
53 orthanc_under_tests_dicom_port: int = 4252
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
54 orthanc_under_tests_exe: str = None
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
55 orthanc_previous_version_exe: str = None
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
56 orthanc_under_tests_docker_image: str = None
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
57 skip_preparation: bool = False
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
58 break_after_preparation: bool = False
483
45c3fe035fed added tests for delayed_deletion
Alain Mazy <am@osimis.io>
parents: 475
diff changeset
59 break_before_preparation: bool = False
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
60 plugins: typing.List[str] = []
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
61
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
62 @classmethod
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
63 def get_orthanc_url(cls):
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
64 return f"http://{cls.orthanc_under_tests_hostname}:{cls.orthanc_under_tests_http_port}"
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
65
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
66 @classmethod
490
10a47656e34f new tests for MaximumStorageMode
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
67 def get_orthanc_ip(cls):
10a47656e34f new tests for MaximumStorageMode
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
68 return cls.orthanc_under_tests_hostname
10a47656e34f new tests for MaximumStorageMode
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
69
10a47656e34f new tests for MaximumStorageMode
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
70 @classmethod
10a47656e34f new tests for MaximumStorageMode
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
71 def get_orthanc_dicom_port(cls):
10a47656e34f new tests for MaximumStorageMode
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
72 return cls.orthanc_under_tests_dicom_port
10a47656e34f new tests for MaximumStorageMode
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
73
10a47656e34f new tests for MaximumStorageMode
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
74 @classmethod
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
75 def is_docker(cls):
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
76 return cls.orthanc_under_tests_exe is None and cls.orthanc_under_tests_docker_image is not None
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
77
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
78 @classmethod
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
79 def is_exe(cls):
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
80 return cls.orthanc_under_tests_exe is not None and cls.orthanc_under_tests_docker_image is None
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
81
490
10a47656e34f new tests for MaximumStorageMode
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
82 @classmethod
10a47656e34f new tests for MaximumStorageMode
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
83 def find_executable(cls, name):
10a47656e34f new tests for MaximumStorageMode
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
84 p = os.path.join('/usr/local/bin', name)
10a47656e34f new tests for MaximumStorageMode
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
85 if os.path.isfile(p):
10a47656e34f new tests for MaximumStorageMode
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
86 return p
10a47656e34f new tests for MaximumStorageMode
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
87
10a47656e34f new tests for MaximumStorageMode
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
88 p = os.path.join('/usr/local/sbin', name)
10a47656e34f new tests for MaximumStorageMode
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
89 if os.path.isfile(p):
10a47656e34f new tests for MaximumStorageMode
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
90 return p
10a47656e34f new tests for MaximumStorageMode
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
91
10a47656e34f new tests for MaximumStorageMode
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
92 return name
10a47656e34f new tests for MaximumStorageMode
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
93
10a47656e34f new tests for MaximumStorageMode
Alain Mazy <am@osimis.io>
parents: 484
diff changeset
94
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
95 class OrthancTestCase(unittest.TestCase):
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
96
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
97 o: OrthancApiClient = None # the orthanc under tests api client
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
98 _orthanc_process = None
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
99 _orthanc_container_name = None
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
100 _orthanc_is_running = False
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
101 _orthanc_logger_thread = None
592
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
102 _show_orthanc_output = False
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
103
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
104 @classmethod
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
105 def setUpClass(cls):
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
106
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
107 cls.o = OrthancApiClient(Helpers.get_orthanc_url())
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
108 cls._prepare()
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
109
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
110 @classmethod
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
111 def tearDownClass(cls):
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
112 if not Helpers.break_after_preparation:
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
113 cls.kill_orthanc()
577
0649a19df194 new tests for auth-service
Alain Mazy <am@osimis.io>
parents: 576
diff changeset
114 cls.terminate()
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
115
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
116 @classmethod
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
117 def prepare(cls):
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
118 pass # to override
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
119
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
120 @classmethod
576
80ba6f1d521c new tests for authorization plugin (native only)
Alain Mazy <am@osimis.io>
parents: 490
diff changeset
121 def terminate(cls):
80ba6f1d521c new tests for authorization plugin (native only)
Alain Mazy <am@osimis.io>
parents: 490
diff changeset
122 pass # to override
80ba6f1d521c new tests for authorization plugin (native only)
Alain Mazy <am@osimis.io>
parents: 490
diff changeset
123
80ba6f1d521c new tests for authorization plugin (native only)
Alain Mazy <am@osimis.io>
parents: 490
diff changeset
124 @classmethod
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
125 def _prepare(cls):
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
126 if not Helpers.skip_preparation:
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
127 cls.prepare()
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
128
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
129 @classmethod
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
130 def get_storage_path(cls, storage_name: str):
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
131 return str(here / "storages" / f"{storage_name}")
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
132
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
133 @classmethod
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
134 def generate_configuration(cls, config_name: str, config: object, storage_name: str, plugins = []):
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
135
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
136 # add plugins and default storge directory
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
137 if plugins and len(plugins) > 0:
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
138 config["Plugins"] = plugins
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
139
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
140 if Helpers.is_exe() and not "StorageDirectory" in config:
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
141 config["StorageDirectory"] = cls.get_storage_path(storage_name=storage_name)
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
142
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
143 if not "Name" in config:
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
144 config["Name"] = config_name
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
145
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
146 if not "HttpPort" in config:
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
147 config["HttpPort"] = Helpers.orthanc_under_tests_http_port
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
148
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
149 if not "DicomPort" in config:
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
150 config["DicomPort"] = Helpers.orthanc_under_tests_dicom_port
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
151
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
152 # copy the values from the base config
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
153 for k, v in default_base_config.items():
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
154 if not k in config:
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
155 config[k] = v
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
156
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
157 # save to disk
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
158 path = str(here / "configurations" / f"{config_name}.json")
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
159 with open(path, "w") as f:
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
160 json.dump(config, f, indent=4)
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
161
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
162 return path
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
163
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
164 @classmethod
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
165 def clear_storage(cls, storage_name: str):
592
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
166 storage_path = cls.get_storage_path(storage_name=storage_name)
620
8ba9b20ae95f debug pg transactions tests
Alain Mazy <am@osimis.io>
parents: 619
diff changeset
167 print("clearing storage")
8ba9b20ae95f debug pg transactions tests
Alain Mazy <am@osimis.io>
parents: 619
diff changeset
168
619
79812e0df162 new way to clean storage for docker containers
Alain Mazy <am@osimis.io>
parents: 618
diff changeset
169 if Helpers.is_exe():
593
f4f0e2d24a51 more pg-transactions tests
Alain Mazy <am@osimis.io>
parents: 592
diff changeset
170
619
79812e0df162 new way to clean storage for docker containers
Alain Mazy <am@osimis.io>
parents: 618
diff changeset
171 # clear the directory but keep it !
79812e0df162 new way to clean storage for docker containers
Alain Mazy <am@osimis.io>
parents: 618
diff changeset
172 for root, dirs, files in os.walk(storage_path):
79812e0df162 new way to clean storage for docker containers
Alain Mazy <am@osimis.io>
parents: 618
diff changeset
173 for f in files:
79812e0df162 new way to clean storage for docker containers
Alain Mazy <am@osimis.io>
parents: 618
diff changeset
174 os.unlink(os.path.join(root, f))
79812e0df162 new way to clean storage for docker containers
Alain Mazy <am@osimis.io>
parents: 618
diff changeset
175 for d in dirs:
79812e0df162 new way to clean storage for docker containers
Alain Mazy <am@osimis.io>
parents: 618
diff changeset
176 shutil.rmtree(os.path.join(root, d))
79812e0df162 new way to clean storage for docker containers
Alain Mazy <am@osimis.io>
parents: 618
diff changeset
177 shutil.rmtree(storage_path, ignore_errors=True)
79812e0df162 new way to clean storage for docker containers
Alain Mazy <am@osimis.io>
parents: 618
diff changeset
178 else:
620
8ba9b20ae95f debug pg transactions tests
Alain Mazy <am@osimis.io>
parents: 619
diff changeset
179 # subprocess.run(["sudo", "rm", "-rf", storage_path], check=True)
8ba9b20ae95f debug pg transactions tests
Alain Mazy <am@osimis.io>
parents: 619
diff changeset
180 # docker run --rm -v /home/alain/o/orthanc-tests/NewTests/storages/concurrency/:/var/lib/orthanc/db/ debian:12-slim rm -rf /var/lib/orthanc/db/*
619
79812e0df162 new way to clean storage for docker containers
Alain Mazy <am@osimis.io>
parents: 618
diff changeset
181 cmd = [
79812e0df162 new way to clean storage for docker containers
Alain Mazy <am@osimis.io>
parents: 618
diff changeset
182 "docker", "run", "--rm",
79812e0df162 new way to clean storage for docker containers
Alain Mazy <am@osimis.io>
parents: 618
diff changeset
183 "-v", f"{storage_path}:/var/lib/orthanc/db/",
79812e0df162 new way to clean storage for docker containers
Alain Mazy <am@osimis.io>
parents: 618
diff changeset
184 "--name", "storage-cleanup",
79812e0df162 new way to clean storage for docker containers
Alain Mazy <am@osimis.io>
parents: 618
diff changeset
185 "debian:12-slim",
79812e0df162 new way to clean storage for docker containers
Alain Mazy <am@osimis.io>
parents: 618
diff changeset
186 "rm", "-rf", "/var/lib/orthanc/db/*"
79812e0df162 new way to clean storage for docker containers
Alain Mazy <am@osimis.io>
parents: 618
diff changeset
187 ]
79812e0df162 new way to clean storage for docker containers
Alain Mazy <am@osimis.io>
parents: 618
diff changeset
188
79812e0df162 new way to clean storage for docker containers
Alain Mazy <am@osimis.io>
parents: 618
diff changeset
189 subprocess.run(cmd, check=True)
620
8ba9b20ae95f debug pg transactions tests
Alain Mazy <am@osimis.io>
parents: 619
diff changeset
190
8ba9b20ae95f debug pg transactions tests
Alain Mazy <am@osimis.io>
parents: 619
diff changeset
191 if not cls.is_storage_empty(storage_name):
8ba9b20ae95f debug pg transactions tests
Alain Mazy <am@osimis.io>
parents: 619
diff changeset
192 print("Could not clear storage")
8ba9b20ae95f debug pg transactions tests
Alain Mazy <am@osimis.io>
parents: 619
diff changeset
193 exit(-12)
8ba9b20ae95f debug pg transactions tests
Alain Mazy <am@osimis.io>
parents: 619
diff changeset
194 print("cleared storage")
8ba9b20ae95f debug pg transactions tests
Alain Mazy <am@osimis.io>
parents: 619
diff changeset
195
592
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
196
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
197 @classmethod
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
198 def is_storage_empty(cls, storage_name: str):
620
8ba9b20ae95f debug pg transactions tests
Alain Mazy <am@osimis.io>
parents: 619
diff changeset
199 print("checking storage empty")
592
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
200 storage_path = cls.get_storage_path(storage_name=storage_name)
620
8ba9b20ae95f debug pg transactions tests
Alain Mazy <am@osimis.io>
parents: 619
diff changeset
201 res = len(glob.glob(os.path.join(storage_path, '*'))) == 0
8ba9b20ae95f debug pg transactions tests
Alain Mazy <am@osimis.io>
parents: 619
diff changeset
202 print("checked storage empty")
8ba9b20ae95f debug pg transactions tests
Alain Mazy <am@osimis.io>
parents: 619
diff changeset
203
8ba9b20ae95f debug pg transactions tests
Alain Mazy <am@osimis.io>
parents: 619
diff changeset
204 return res
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
205
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
206 @classmethod
577
0649a19df194 new tests for auth-service
Alain Mazy <am@osimis.io>
parents: 576
diff changeset
207 def create_docker_network(cls, network: str):
0649a19df194 new tests for auth-service
Alain Mazy <am@osimis.io>
parents: 576
diff changeset
208 if Helpers.is_docker():
0649a19df194 new tests for auth-service
Alain Mazy <am@osimis.io>
parents: 576
diff changeset
209 subprocess.run(["docker", "network", "rm", network]) # ignore error
0649a19df194 new tests for auth-service
Alain Mazy <am@osimis.io>
parents: 576
diff changeset
210 subprocess.run(["docker", "network", "create", network])
0649a19df194 new tests for auth-service
Alain Mazy <am@osimis.io>
parents: 576
diff changeset
211
0649a19df194 new tests for auth-service
Alain Mazy <am@osimis.io>
parents: 576
diff changeset
212 @classmethod
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
213 def launch_orthanc_to_prepare_db(cls, config_name: str = None, config: object = None, config_path: str = None, storage_name: str = None, plugins = []):
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
214 if config_name and storage_name and config:
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
215 # generate the configuration file
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
216 config_path = cls.generate_configuration(
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
217 config_name=config_name,
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
218 storage_name=storage_name,
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
219 config=config,
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
220 plugins=plugins
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
221 )
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
222 elif not config_path or not storage_name or not config_name:
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
223 raise RuntimeError("Invalid configuration")
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
224
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
225 # run orthanc
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
226 if Helpers.orthanc_previous_version_exe:
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
227 cls.launch_orthanc_exe(
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
228 exe_path=Helpers.orthanc_previous_version_exe,
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
229 config_path=config_path
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
230 )
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
231 elif Helpers.orthanc_previous_version_docker_image:
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
232 cls.launch_orthanc_docker(
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
233 docker_image=Helpers.orthanc_previous_version_docker_image,
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
234 storage_name=storage_name,
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
235 config_name=config_name,
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
236 config_path=config_path
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
237 )
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
238 else:
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
239 raise RuntimeError("Invalid configuration, can not launch Orthanc")
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
240
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
241 @classmethod
592
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
242 def launch_orthanc_under_tests(cls, config_name: str = None, config: object = None, config_path: str = None, storage_name: str = None, plugins = [], docker_network: str = None, enable_verbose: bool = False, show_orthanc_output: bool = False):
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
243 cls._show_orthanc_output = show_orthanc_output
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
244
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
245 if config_name and storage_name and config:
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
246 # generate the configuration file
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
247 config_path = cls.generate_configuration(
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
248 config_name=config_name,
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
249 storage_name=storage_name,
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
250 config=config,
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
251 plugins=plugins
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
252 )
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
253 elif not config_path or not storage_name or not config_name:
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
254 raise RuntimeError("Invalid configuration")
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
255
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
256 # run orthanc
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
257 if Helpers.orthanc_under_tests_exe:
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
258 cls.launch_orthanc_exe(
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
259 exe_path=Helpers.orthanc_under_tests_exe,
592
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
260 config_path=config_path,
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
261 enable_verbose=enable_verbose
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
262 )
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
263 elif Helpers.orthanc_under_tests_docker_image:
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
264 cls.launch_orthanc_docker(
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
265 docker_image=Helpers.orthanc_under_tests_docker_image,
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
266 storage_name=storage_name,
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
267 config_name=config_name,
577
0649a19df194 new tests for auth-service
Alain Mazy <am@osimis.io>
parents: 576
diff changeset
268 config_path=config_path,
592
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
269 network=docker_network,
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
270 enable_verbose=enable_verbose
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
271 )
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
272 else:
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
273 raise RuntimeError("Invalid configuration, can not launch Orthanc")
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
274
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
275 @classmethod
592
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
276 def launch_orthanc_exe(cls, exe_path: str, config_path: str, enable_verbose: bool = False, show_orthanc_output: bool = False):
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
277 if enable_verbose:
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
278 cmd = [exe_path, "--verbose", config_path]
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
279 else:
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
280 cmd = [exe_path, config_path]
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
281
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
282 cls._orthanc_process = subprocess.Popen(
592
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
283 cmd,
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
284 stdout=subprocess.PIPE,
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
285 stderr=subprocess.PIPE
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
286 )
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
287
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
288 cls.o.wait_started(10)
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
289 if not cls.o.is_alive():
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
290 output = cls.get_orthanc_process_output()
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
291 print("Orthanc output\n" + output)
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
292
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
293 raise RuntimeError(f"Orthanc failed to start '{exe_path}', conf = '{config_path}'. Check output above")
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
294
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
295 @classmethod
592
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
296 def launch_orthanc_docker(cls, docker_image: str, storage_name: str, config_path: str, config_name: str, network: str = None, enable_verbose: bool = False):
484
ddfabe1fbee1 new tests for DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents: 483
diff changeset
297 storage_path = cls.get_storage_path(storage_name=storage_name)
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
298
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
299 cmd = [
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
300 "docker", "run", "--rm",
620
8ba9b20ae95f debug pg transactions tests
Alain Mazy <am@osimis.io>
parents: 619
diff changeset
301 "-e", "VERBOSE_ENABLED=true", # if enable_verbose else "VERBOSE_ENABLED=false",
8ba9b20ae95f debug pg transactions tests
Alain Mazy <am@osimis.io>
parents: 619
diff changeset
302 "-e", "VERBOSE_STARTUP=true", # always set it !!!! if enable_verbose else "VERBOSE_STARTUP=false",
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
303 "-v", f"{config_path}:/etc/orthanc/orthanc.json",
484
ddfabe1fbee1 new tests for DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents: 483
diff changeset
304 "-v", f"{storage_path}:/var/lib/orthanc/db/",
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
305 "--name", config_name,
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
306 "-p", f"{Helpers.orthanc_under_tests_http_port}:{Helpers.orthanc_under_tests_http_port}",
619
79812e0df162 new way to clean storage for docker containers
Alain Mazy <am@osimis.io>
parents: 618
diff changeset
307 "-p", f"{Helpers.orthanc_under_tests_dicom_port}:{Helpers.orthanc_under_tests_dicom_port}"
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
308 ]
577
0649a19df194 new tests for auth-service
Alain Mazy <am@osimis.io>
parents: 576
diff changeset
309 if network:
0649a19df194 new tests for auth-service
Alain Mazy <am@osimis.io>
parents: 576
diff changeset
310 cmd.extend(["--network", network])
0649a19df194 new tests for auth-service
Alain Mazy <am@osimis.io>
parents: 576
diff changeset
311 cmd.append(docker_image)
0649a19df194 new tests for auth-service
Alain Mazy <am@osimis.io>
parents: 576
diff changeset
312
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
313 cls._orthanc_container_name = config_name
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
314 print("docker cmd line: " + " ".join(cmd))
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
315
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
316 cls._orthanc_process = subprocess.Popen(
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
317 cmd,
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
318 stdout=subprocess.PIPE,
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
319 stderr=subprocess.PIPE
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
320 )
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
321
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
322 cls.o.wait_started(10)
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
323 if not cls.o.is_alive():
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
324 output = cls.get_orthanc_process_output()
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
325 print("Orthanc output\n" + output)
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
326
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
327 raise RuntimeError(f"Orthanc failed to start Orthanc through Docker '{docker_image}', conf = '{config_path}'. Check output above")
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
328
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
329
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
330 @classmethod
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
331 def kill_orthanc(cls):
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
332 if Helpers.is_exe():
576
80ba6f1d521c new tests for authorization plugin (native only)
Alain Mazy <am@osimis.io>
parents: 490
diff changeset
333 if cls._orthanc_process:
80ba6f1d521c new tests for authorization plugin (native only)
Alain Mazy <am@osimis.io>
parents: 490
diff changeset
334 cls._orthanc_process.kill()
80ba6f1d521c new tests for authorization plugin (native only)
Alain Mazy <am@osimis.io>
parents: 490
diff changeset
335 else:
80ba6f1d521c new tests for authorization plugin (native only)
Alain Mazy <am@osimis.io>
parents: 490
diff changeset
336 return
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
337 else:
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
338 subprocess.run(["docker", "stop", cls._orthanc_container_name])
592
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
339
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
340 if cls._show_orthanc_output:
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
341 output = cls.get_orthanc_process_output()
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
342 print("Orthanc output\n" + output)
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents: 577
diff changeset
343
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
344 cls._orthanc_process = None
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
345
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
346 @classmethod
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
347 def get_orthanc_process_output(cls):
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
348 outputs = cls._orthanc_process.communicate()
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
349 output = ""
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
350 for o in outputs:
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
351 output += o.decode('utf-8')
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
352 return output