def cleanup(): agent = service.get_container_by_hostname('midolman1') # We wait just to make sure that it's been unregistered agent.stop(wait=True) # Wipe out the container sandbox.remove_container(agent) # Restart sandbox, the --no-recreate flag will spawn only missing containers sandbox.restart_sandbox('default_neutron+kilo+compat', conf.sandbox_name(), 'sandbox/override_compat') # Reset cached containers and reload them (await for the new agent to be up) service.loaded_containers = None agent = service.get_container_by_hostname('midolman1') agent.wait_for_status('up')
def get_all_containers(container_type=None, include_failed=False): global loaded_containers # Load and cache containers associated with the sandbox if not loaded_containers: sandbox_containers = _containers_for_sandbox(conf.sandbox_name(), include_failed) loaded_containers = {} for container in sandbox_containers: if 'type' in container['Labels']: current_type = container['Labels']['type'] container_instance = load_from_id(container['Id']) loaded_containers.setdefault(current_type, []).append(container_instance) for type, container_list in loaded_containers.items(): sorted(container_list, key=lambda container: container.get_hostname()) if container_type: if container_type in loaded_containers: return loaded_containers[container_type] else: return [] return loaded_containers
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(): if timeout == 0: