comparison 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
comparison
equal deleted inserted replaced
619:79812e0df162 620:8ba9b20ae95f
162 return path 162 return path
163 163
164 @classmethod 164 @classmethod
165 def clear_storage(cls, storage_name: str): 165 def clear_storage(cls, storage_name: str):
166 storage_path = cls.get_storage_path(storage_name=storage_name) 166 storage_path = cls.get_storage_path(storage_name=storage_name)
167 print("clearing storage")
168
167 if Helpers.is_exe(): 169 if Helpers.is_exe():
168 170
169 # clear the directory but keep it ! 171 # clear the directory but keep it !
170 for root, dirs, files in os.walk(storage_path): 172 for root, dirs, files in os.walk(storage_path):
171 for f in files: 173 for f in files:
172 os.unlink(os.path.join(root, f)) 174 os.unlink(os.path.join(root, f))
173 for d in dirs: 175 for d in dirs:
174 shutil.rmtree(os.path.join(root, d)) 176 shutil.rmtree(os.path.join(root, d))
175 shutil.rmtree(storage_path, ignore_errors=True) 177 shutil.rmtree(storage_path, ignore_errors=True)
176 else: 178 else:
179 # subprocess.run(["sudo", "rm", "-rf", storage_path], check=True)
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/*
177 cmd = [ 181 cmd = [
178 "docker", "run", "--rm", 182 "docker", "run", "--rm",
179 "-v", f"{storage_path}:/var/lib/orthanc/db/", 183 "-v", f"{storage_path}:/var/lib/orthanc/db/",
180 "--name", "storage-cleanup", 184 "--name", "storage-cleanup",
181 "debian:12-slim", 185 "debian:12-slim",
182 "rm", "-rf", "/var/lib/orthanc/db/*" 186 "rm", "-rf", "/var/lib/orthanc/db/*"
183 ] 187 ]
184 188
185 subprocess.run(cmd, check=True) 189 subprocess.run(cmd, check=True)
190
191 if not cls.is_storage_empty(storage_name):
192 print("Could not clear storage")
193 exit(-12)
194 print("cleared storage")
195
186 196
187 @classmethod 197 @classmethod
188 def is_storage_empty(cls, storage_name: str): 198 def is_storage_empty(cls, storage_name: str):
199 print("checking storage empty")
189 storage_path = cls.get_storage_path(storage_name=storage_name) 200 storage_path = cls.get_storage_path(storage_name=storage_name)
190 return len(glob.glob(os.path.join(storage_path, '*'))) == 0 201 res = len(glob.glob(os.path.join(storage_path, '*'))) == 0
202 print("checked storage empty")
203
204 return res
191 205
192 @classmethod 206 @classmethod
193 def create_docker_network(cls, network: str): 207 def create_docker_network(cls, network: str):
194 if Helpers.is_docker(): 208 if Helpers.is_docker():
195 subprocess.run(["docker", "network", "rm", network]) # ignore error 209 subprocess.run(["docker", "network", "rm", network]) # ignore error
282 def launch_orthanc_docker(cls, docker_image: str, storage_name: str, config_path: str, config_name: str, network: str = None, enable_verbose: bool = False): 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):
283 storage_path = cls.get_storage_path(storage_name=storage_name) 297 storage_path = cls.get_storage_path(storage_name=storage_name)
284 298
285 cmd = [ 299 cmd = [
286 "docker", "run", "--rm", 300 "docker", "run", "--rm",
287 "-e", "VERBOSE_ENABLED=true" if enable_verbose else "VERBOSE_ENABLED=false", 301 "-e", "VERBOSE_ENABLED=true", # if enable_verbose else "VERBOSE_ENABLED=false",
288 "-e", "VERBOSE_STARTUP=true" if enable_verbose else "VERBOSE_STARTUP=false", 302 "-e", "VERBOSE_STARTUP=true", # always set it !!!! if enable_verbose else "VERBOSE_STARTUP=false",
289 "-v", f"{config_path}:/etc/orthanc/orthanc.json", 303 "-v", f"{config_path}:/etc/orthanc/orthanc.json",
290 "-v", f"{storage_path}:/var/lib/orthanc/db/", 304 "-v", f"{storage_path}:/var/lib/orthanc/db/",
291 "--name", config_name, 305 "--name", config_name,
292 "-p", f"{Helpers.orthanc_under_tests_http_port}:{Helpers.orthanc_under_tests_http_port}", 306 "-p", f"{Helpers.orthanc_under_tests_http_port}:{Helpers.orthanc_under_tests_http_port}",
293 "-p", f"{Helpers.orthanc_under_tests_dicom_port}:{Helpers.orthanc_under_tests_dicom_port}" 307 "-p", f"{Helpers.orthanc_under_tests_dicom_port}:{Helpers.orthanc_under_tests_dicom_port}"