diff options
author | 2020-09-22 08:04:23 +0200 | |
---|---|---|
committer | 2020-09-22 20:01:03 +0200 | |
commit | e0da464c1b8bfe7ceb1f16879a2c550e7348fe18 (patch) | |
tree | dbf127607c7e8708776514ab3fbfc67196e7add6 /tests/oom-platform-cert-service/postprocessor/libraries/TrustMergerManager.py | |
parent | 97c946e21835cbc213f9974ed0df05ef702f4b88 (diff) |
[OOM-CMPv2] Rename truststoremerger->postprocessor
Issue-ID: DCAEGEN2-2253
Signed-off-by: Jan Malkiewicz <jan.malkiewicz@nokia.com>
Change-Id: I6c7fa3378c86dee4e1fe23e4840046b979d942ea
Diffstat (limited to 'tests/oom-platform-cert-service/postprocessor/libraries/TrustMergerManager.py')
-rw-r--r-- | tests/oom-platform-cert-service/postprocessor/libraries/TrustMergerManager.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/oom-platform-cert-service/postprocessor/libraries/TrustMergerManager.py b/tests/oom-platform-cert-service/postprocessor/libraries/TrustMergerManager.py new file mode 100644 index 00000000..f7a493c4 --- /dev/null +++ b/tests/oom-platform-cert-service/postprocessor/libraries/TrustMergerManager.py @@ -0,0 +1,47 @@ +import docker +import os +import shutil +from EnvsReader import EnvsReader +from docker.types import Mount + +ARCHIVES_PATH = os.getenv("WORKSPACE") + "/archives/" + + +class TrustMergerManager: + + def __init__(self, mount_path, truststores_path): + self.mount_path = mount_path + self.truststores_path = truststores_path + + def run_merger_container(self, merger_image, merger_name, path_to_env): + self.remove_mount_dir() + shutil.copytree(self.truststores_path, self.mount_path) + client = docker.from_env() + environment = EnvsReader().read_env_list_from_file(path_to_env) + container = client.containers.run( + image=merger_image, + name=merger_name, + environment=environment, + user='root', # Run container as root to avoid permission issues with volume mount access + mounts=[Mount(target='/var/certs', source=self.mount_path, type='bind')], + detach=True + ) + exitcode = container.wait() + return exitcode + + def create_mount_dir(self): + if not os.path.exists(self.mount_path): + os.makedirs(self.mount_path) + + def remove_mount_dir(self): + if os.path.exists(self.mount_path): + shutil.rmtree(self.mount_path) + + def remove_merger_container_and_save_logs(self, container_name, log_file_name): + client = docker.from_env() + container = client.containers.get(container_name) + text_file = open(ARCHIVES_PATH + "merger_container_" + log_file_name + ".log", "w") + text_file.write(container.logs()) + text_file.close() + container.remove() + self.remove_mount_dir() |