Mercurial > hg > orthanc-tests
changeset 619:79812e0df162
new way to clean storage for docker containers
author | Alain Mazy <am@osimis.io> |
---|---|
date | Mon, 05 Feb 2024 17:12:07 +0100 |
parents | 4b3d13e498a5 |
children | 8ba9b20ae95f 9f867dc595e2 |
files | NewTests/helpers.py |
diffstat | 1 files changed, 19 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/NewTests/helpers.py Mon Feb 05 16:42:37 2024 +0100 +++ b/NewTests/helpers.py Mon Feb 05 17:12:07 2024 +0100 @@ -164,14 +164,25 @@ @classmethod def clear_storage(cls, storage_name: str): storage_path = cls.get_storage_path(storage_name=storage_name) + if Helpers.is_exe(): - # clear the directory but keep it ! - for root, dirs, files in os.walk(storage_path): - for f in files: - os.unlink(os.path.join(root, f)) - for d in dirs: - shutil.rmtree(os.path.join(root, d)) - shutil.rmtree(storage_path, ignore_errors=True) + # clear the directory but keep it ! + for root, dirs, files in os.walk(storage_path): + for f in files: + os.unlink(os.path.join(root, f)) + for d in dirs: + shutil.rmtree(os.path.join(root, d)) + shutil.rmtree(storage_path, ignore_errors=True) + else: + cmd = [ + "docker", "run", "--rm", + "-v", f"{storage_path}:/var/lib/orthanc/db/", + "--name", "storage-cleanup", + "debian:12-slim", + "rm", "-rf", "/var/lib/orthanc/db/*" + ] + + subprocess.run(cmd, check=True) @classmethod def is_storage_empty(cls, storage_name: str): @@ -279,8 +290,7 @@ "-v", f"{storage_path}:/var/lib/orthanc/db/", "--name", config_name, "-p", f"{Helpers.orthanc_under_tests_http_port}:{Helpers.orthanc_under_tests_http_port}", - "-p", f"{Helpers.orthanc_under_tests_dicom_port}:{Helpers.orthanc_under_tests_dicom_port}", - "-u", f"999:999" + "-p", f"{Helpers.orthanc_under_tests_dicom_port}:{Helpers.orthanc_under_tests_dicom_port}" ] if network: cmd.extend(["--network", network])