Mercurial > hg > orthanc-tests
annotate NewTests/helpers.py @ 533:c5291d97ed54
fix
author | Alain Mazy <am@osimis.io> |
---|---|
date | Tue, 25 Apr 2023 08:27:40 +0200 |
parents | 10a47656e34f |
children | 80ba6f1d521c |
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 | 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 |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
8 from threading import Thread |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
9 |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
10 |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
11 import pathlib |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
12 here = pathlib.Path(__file__).parent.resolve() |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
13 |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
14 |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
15 default_base_config = { |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
16 "AuthenticationEnabled": False, |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
17 "RemoteAccessAllowed": True |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
18 } |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
19 |
490 | 20 |
473
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
21 class Helpers: |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
22 |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
23 orthanc_under_tests_hostname: str = 'localhost' |
474 | 24 orthanc_under_tests_http_port: int = 8052 |
25 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
|
26 orthanc_under_tests_exe: str = None |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
27 orthanc_previous_version_exe: str = None |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
28 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
|
29 skip_preparation: bool = False |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
30 break_after_preparation: bool = False |
483 | 31 break_before_preparation: bool = False |
473
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
32 plugins: typing.List[str] = [] |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
33 |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
34 @classmethod |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
35 def get_orthanc_url(cls): |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
36 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
|
37 |
474 | 38 @classmethod |
490 | 39 def get_orthanc_ip(cls): |
40 return cls.orthanc_under_tests_hostname | |
41 | |
42 @classmethod | |
43 def get_orthanc_dicom_port(cls): | |
44 return cls.orthanc_under_tests_dicom_port | |
45 | |
46 @classmethod | |
474 | 47 def is_docker(cls): |
48 return cls.orthanc_under_tests_exe is None and cls.orthanc_under_tests_docker_image is not None | |
49 | |
50 @classmethod | |
51 def is_exe(cls): | |
52 return cls.orthanc_under_tests_exe is not None and cls.orthanc_under_tests_docker_image is None | |
53 | |
490 | 54 @classmethod |
55 def find_executable(cls, name): | |
56 p = os.path.join('/usr/local/bin', name) | |
57 if os.path.isfile(p): | |
58 return p | |
59 | |
60 p = os.path.join('/usr/local/sbin', name) | |
61 if os.path.isfile(p): | |
62 return p | |
63 | |
64 return name | |
65 | |
66 | |
473
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
67 class OrthancTestCase(unittest.TestCase): |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
68 |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
69 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
|
70 _orthanc_process = None |
474 | 71 _orthanc_container_name = None |
473
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
72 _orthanc_is_running = False |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
73 _orthanc_logger_thread = None |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
74 |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
75 @classmethod |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
76 def setUpClass(cls): |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
77 |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
78 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
|
79 cls._prepare() |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
80 |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
81 @classmethod |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
82 def tearDownClass(cls): |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
83 if not Helpers.break_after_preparation: |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
84 cls.kill_orthanc() |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
85 |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
86 @classmethod |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
87 def prepare(cls): |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
88 pass # to override |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
89 |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
90 @classmethod |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
91 def _prepare(cls): |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
92 if not Helpers.skip_preparation: |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
93 cls.prepare() |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
94 |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
95 @classmethod |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
96 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
|
97 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
|
98 |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
99 @classmethod |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
100 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
|
101 |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
102 # add plugins and default storge directory |
474 | 103 if plugins and len(plugins) > 0: |
104 config["Plugins"] = plugins | |
473
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
105 |
474 | 106 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
|
107 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
|
108 |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
109 if not "Name" in config: |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
110 config["Name"] = config_name |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
111 |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
112 if not "HttpPort" in config: |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
113 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
|
114 |
474 | 115 if not "DicomPort" in config: |
116 config["DicomPort"] = Helpers.orthanc_under_tests_dicom_port | |
117 | |
473
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
118 # 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
|
119 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
|
120 if not k in config: |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
121 config[k] = v |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
122 |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
123 # save to disk |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
124 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
|
125 with open(path, "w") as f: |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
126 json.dump(config, f, indent=4) |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
127 |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
128 return path |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
129 |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
130 @classmethod |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
131 def clear_storage(cls, storage_name: str): |
474 | 132 if Helpers.is_exe(): |
133 storage_path = cls.get_storage_path(storage_name=storage_name) | |
134 shutil.rmtree(storage_path, ignore_errors=True) | |
135 elif Helpers.is_docker(): | |
475 | 136 subprocess.run(["docker", "volume", "rm", "-f", storage_name]) |
473
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
137 |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
138 @classmethod |
474 | 139 def launch_orthanc_to_prepare_db(cls, config_name: str = None, config: object = None, config_path: str = None, storage_name: str = None, plugins = []): |
140 if config_name and storage_name and config: | |
141 # generate the configuration file | |
142 config_path = cls.generate_configuration( | |
143 config_name=config_name, | |
144 storage_name=storage_name, | |
145 config=config, | |
146 plugins=plugins | |
147 ) | |
148 elif not config_path or not storage_name or not config_name: | |
149 raise RuntimeError("Invalid configuration") | |
473
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
150 |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
151 # run orthanc |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
152 if Helpers.orthanc_previous_version_exe: |
474 | 153 cls.launch_orthanc_exe( |
473
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
154 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
|
155 config_path=config_path |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
156 ) |
474 | 157 elif Helpers.orthanc_previous_version_docker_image: |
158 cls.launch_orthanc_docker( | |
159 docker_image=Helpers.orthanc_previous_version_docker_image, | |
160 storage_name=storage_name, | |
161 config_name=config_name, | |
162 config_path=config_path | |
163 ) | |
473
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
164 else: |
474 | 165 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
|
166 |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
167 @classmethod |
474 | 168 def launch_orthanc_under_tests(cls, config_name: str = None, config: object = None, config_path: str = None, storage_name: str = None, plugins = []): |
169 if config_name and storage_name and config: | |
170 # generate the configuration file | |
171 config_path = cls.generate_configuration( | |
172 config_name=config_name, | |
173 storage_name=storage_name, | |
174 config=config, | |
175 plugins=plugins | |
176 ) | |
177 elif not config_path or not storage_name or not config_name: | |
178 raise RuntimeError("Invalid configuration") | |
179 | |
180 # run orthanc | |
181 if Helpers.orthanc_under_tests_exe: | |
182 cls.launch_orthanc_exe( | |
183 exe_path=Helpers.orthanc_under_tests_exe, | |
184 config_path=config_path | |
185 ) | |
186 elif Helpers.orthanc_under_tests_docker_image: | |
187 cls.launch_orthanc_docker( | |
188 docker_image=Helpers.orthanc_under_tests_docker_image, | |
189 storage_name=storage_name, | |
190 config_name=config_name, | |
191 config_path=config_path | |
192 ) | |
193 else: | |
194 raise RuntimeError("Invalid configuration, can not launch Orthanc") | |
195 | |
196 @classmethod | |
197 def launch_orthanc_exe(cls, exe_path: str, config_path: str): | |
473
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
198 cls._orthanc_process = subprocess.Popen( |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
199 [exe_path, "--verbose", config_path], |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
200 stdout=subprocess.PIPE, |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
201 stderr=subprocess.PIPE |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
202 ) |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
203 |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
204 cls.o.wait_started(10) |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
205 if not cls.o.is_alive(): |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
206 output = cls.get_orthanc_process_output() |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
207 print("Orthanc output\n" + output) |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
208 |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
209 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
|
210 |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
211 @classmethod |
474 | 212 def launch_orthanc_docker(cls, docker_image: str, storage_name: str, config_path: str, config_name: str): |
484
ddfabe1fbee1
new tests for DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
483
diff
changeset
|
213 storage_path = cls.get_storage_path(storage_name=storage_name) |
474 | 214 |
215 cmd = [ | |
216 "docker", "run", "--rm", | |
217 "-e", "VERBOSE_ENABLED=true", | |
218 "-e", "VERBOSE_STARTUP=true", | |
219 "-v", f"{config_path}:/etc/orthanc/orthanc.json", | |
484
ddfabe1fbee1
new tests for DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
483
diff
changeset
|
220 "-v", f"{storage_path}:/var/lib/orthanc/db/", |
474 | 221 "--name", config_name, |
222 "-p", f"{Helpers.orthanc_under_tests_http_port}:{Helpers.orthanc_under_tests_http_port}", | |
223 "-p", f"{Helpers.orthanc_under_tests_dicom_port}:{Helpers.orthanc_under_tests_dicom_port}", | |
224 docker_image | |
225 ] | |
226 cls._orthanc_container_name = config_name | |
227 print("docker cmd line: " + " ".join(cmd)) | |
228 | |
229 cls._orthanc_process = subprocess.Popen( | |
230 cmd, | |
231 stdout=subprocess.PIPE, | |
232 stderr=subprocess.PIPE | |
233 ) | |
234 | |
235 cls.o.wait_started(10) | |
236 if not cls.o.is_alive(): | |
237 output = cls.get_orthanc_process_output() | |
238 print("Orthanc output\n" + output) | |
239 | |
240 raise RuntimeError(f"Orthanc failed to start Orthanc through Docker '{docker_image}', conf = '{config_path}'. Check output above") | |
241 | |
242 | |
243 @classmethod | |
473
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
244 def kill_orthanc(cls): |
474 | 245 if Helpers.is_exe(): |
246 cls._orthanc_process.kill() | |
247 else: | |
248 subprocess.run(["docker", "stop", cls._orthanc_container_name]) | |
473
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
249 output = cls.get_orthanc_process_output() |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
250 print("Orthanc output\n" + output) |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
251 cls._orthanc_process = None |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
252 |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
253 @classmethod |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
254 def get_orthanc_process_output(cls): |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
255 outputs = cls._orthanc_process.communicate() |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
256 output = "" |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
257 for o in outputs: |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
258 output += o.decode('utf-8') |
4ee85b016a40
added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
259 return output |