from mdts.lib.mdtsdocker import DockerClient from mdts.lib.ssh import SshClient from mdts.services.interface import Interface from mdts.tests.utils import conf LOG = logging.getLogger(__name__) cli = None if conf.containers_file() is None: print("containers_file not configured -> using Docker API") cli = DockerClient(base_url='unix://var/run/docker.sock', timeout=conf.docker_http_timeout(), sandbox_prefix=conf.sandbox_prefix(), sandbox_name=conf.sandbox_name()) else: print("containers_file configured as '%s' -> using SSH" % conf.containers_file()) cli = SshClient(conf.containers_file(), conf.extra_ssh_config_file()) class Service(object): def __init__(self, container_id): self.container_id = container_id self.info = cli.inspect_container(container_id) timeout = conf.service_status_timeout() wait_time = 1 # Check first that the container is running while not self.is_container_running():
def _is_sandbox_container(sandbox_name, container): container_to_sandbox_name = lambda name: name.replace('/', '')[len(conf.sandbox_prefix()):].split('_')[0] container_sandbox_names = map(container_to_sandbox_name, container['Names']) return sandbox_name in container_sandbox_names