summaryrefslogtreecommitdiffstats
path: root/tests/aaf/certservice/libraries/CertClientManager.py
blob: 30501c8b1dfab73792f1630b84b6d49a664ebb56 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import docker


class CertClientManager:

    def run_client_container(self, client_image, container_name, path_to_env, request_url, network):
        client = docker.from_env()
        environment = self.read_list_env_from_file(path_to_env)
        environment.append("REQUEST_URL=" + request_url)
        container = client.containers.run(image=client_image, name=container_name, detach=True, environment=environment,
                                          network=network)
        exitcode = container.wait()
        return exitcode

    def remove_client_container(self, container_name):
        client = docker.from_env()
        container = client.containers.get(container_name)
        container.remove()

    def read_list_env_from_file(self, path):
        f = open(path, "r")
        r_list = []
        for line in f:
            line = line.strip()
            if line[0] != "#":
                r_list.append(line)
        return r_list