def percona_xtradb_cluster_one_node(container_network): client = docker_client() api = client.api # The ports that need to be exposed from the PXC container to host container_ports = [PXC_MYSQL_PORT] container_info = [{ 'id': None, 'name': 'pxc-one-node-node01', 'ip': '172.25.3.10', 'mysql_port': PXC_MYSQL_PORT, 'root_password': PXC_ROOT_PASSWORD }] cluster_name = 'test_cluster_1_node' # Create the cluster container_info = create_percona_xtradb_cluster( PXC_IMAGE, [CONTAINERS_FOR_TESTING_LABEL], container_info, container_ports, container_network, cluster_name) yield container_info # Cleanup the containers now for container in container_info: api.remove_container(container=container['id'], force=True)
def container_network(): client = docker_client() api = client.api network_name = 'test_network' ipam_pool = IPAMPool(subnet="172.25.0.0/16") ipam_config = IPAMConfig(pool_configs=[ipam_pool]) network = api.create_network(name=network_name, driver="bridge", ipam=ipam_config) yield network_name api.remove_network(net_id=network['Id'])
def debian_container(): client = docker_client() api = client.api # Pull the image locally docker_pull_image(DEBIAN_IMAGE) container = api.create_container(image=DEBIAN_IMAGE, labels=[CONTAINERS_FOR_TESTING_LABEL], command='/bin/sleep 36000') api.start(container['Id']) container_info = client.containers.get(container['Id']) yield container_info api.remove_container(container=container['Id'], force=True)
def pytest_runtest_logreport(report): """Process a test setup/call/teardown report relating to the respective phase of executing a test.""" if report.failed: client = docker_client() api = client.api test_containers = api.containers( all=True, filters={"label": CONTAINERS_FOR_TESTING_LABEL}) for container in test_containers: log_lines = [ ("docker inspect {!r}:".format(container['Id'])), (pprint.pformat(api.inspect_container(container['Id']))), ("docker logs {!r}:".format(container['Id'])), (api.logs(container['Id'])), ] report.longrepr.addsection('docker logs', os.linesep.join(log_lines))
def proxysql_container(proxysql_config_contents, tmpdir, container_network): client = docker_client() api = client.api # Pull the container image locally first docker_pull_image(PROXYSQL_IMAGE) # Setup the ProxySQL config config = tmpdir.join('proxysql.cnf') config.write(proxysql_config_contents) LOG.debug('ProxySQL Config:\n %s', proxysql_config_contents) # The ports that the ProxySQL container will be listening on inside the # container container_ports = [PROXYSQL_ADMIN_PORT, PROXYSQL_CLIENT_PORT] container_info = { 'name': 'proxysql01', 'ip': '172.25.3.100', } host_config = api.create_host_config( binds=["{}:/etc/proxysql.cnf".format(str(config))], port_bindings={}) networking_config = api.create_networking_config({ container_network: api.create_endpoint_config(ipv4_address=container_info['ip']) }) container = api.create_container(image=PROXYSQL_IMAGE, name='proxysql01', labels=[CONTAINERS_FOR_TESTING_LABEL], ports=container_ports, host_config=host_config, networking_config=networking_config) LOG.debug('Starting container %s', container['Id']) api.start(container['Id']) # 1/0 yield container_info api.remove_container(container=container['Id'], force=True)