def s3_client(docker_ip, docker_services): """wait for minio to be up""" # Build URL to service listening on random port. url = 'http://%s:%d/' % ( docker_ip, docker_services.port_for('minio', 9000), ) # Wait until service is responsive. docker_services.wait_until_responsive( check=lambda: is_responsive(url, 403), timeout=30.0, pause=0.1, ) # Contact the service. response = requests.get(url) assert response.status_code == 403 endpoint = '{ip}:{port}'.format(ip=docker_ip, port=docker_services.port_for( 'minio', 9000)) access_key = "12345678" secret_key = "12345678" secure = False s3_client = S3Client(endpoint, access_key, secret_key, secure) return s3_client
def docker_registry(docker_ip, docker_services): host = docker_ip port = docker_services.port_for('registry', 5000) url = "{host}:{port}".format(host=host, port=port) # Wait until we can connect docker_services.wait_until_responsive( check=lambda: is_responsive(url), timeout=30.0, pause=1.0, ) # test the registry try: docker_client = docker.from_env() # get the hello world example from docker hub hello_world_image = docker_client.images.pull("hello-world", "latest") # login to private registry docker_client.login(registry=url, username="******") # tag the image repo = url + "/hello-world:dev" assert hello_world_image.tag(repo) == True # push the image to the private registry docker_client.images.push(repo) # wipe the images docker_client.images.remove(image="hello-world:latest") docker_client.images.remove(image=hello_world_image.id) # pull the image from the private registry private_image = docker_client.images.pull(repo) docker_client.images.remove(image=private_image.id) except docker.errors.APIError: log.exception("Unexpected docker API error") raise yield url print("teardown docker registry")
def postgres_service(docker_services, docker_ip): url = 'postgresql://{user}:{password}@{host}:{port}/{database}'.format( user=USER, password=PASS, database=DATABASE, host=docker_ip, port=docker_services.port_for('postgres', 5432), ) # Wait until service is responsive. docker_services.wait_until_responsive( check=lambda: is_postgres_responsive(url), timeout=30.0, pause=0.1, ) postgres_service = { 'user': USER, 'password': PASS, 'database': DATABASE, 'host': docker_ip, 'port': docker_services.port_for('postgres', 5432) } return postgres_service
def engine(docker_ip, docker_services): dbname = 'test' user = '******' password = '******' host = docker_ip port = docker_services.port_for('postgres', 5432) url = 'postgresql://{user}:{password}@{host}:{port}/{database}'.format( user=user, password=password, database=dbname, host=docker_ip, port=docker_services.port_for('postgres', 5432), ) # Wait until we can connect docker_services.wait_until_responsive( check=lambda: is_responsive(url), timeout=30.0, pause=1.0, ) # Configures db and initializes tables # Uses syncrounous engine for that engine = create_engine(url, client_encoding='utf8') _metadata.create_all(bind=engine, tables=[ _tokens, ], checkfirst=True) os.environ["POSTGRES_ENDPOINT"] = "{host}:{port}".format(host=host, port=port) os.environ["POSTGRES_USER"] = "******" os.environ["POSTGRES_PASSWORD"] = "******" os.environ["POSTGRES_DB"] = "test" yield engine # cleanup engine.dispose()
def test_minio(docker_ip, docker_services): """wait for minio to be up""" # Build URL to service listening on random port. url = 'http://%s:%d/' % ( docker_ip, docker_services.port_for('minio', 9000), ) # Wait until service is responsive. docker_services.wait_until_responsive( check=lambda: is_responsive(url, 403), timeout=30.0, pause=0.1, ) # Contact the service. response = requests.get(url) assert response.status_code == 403
def test_integration(docker_ip, docker_services): """Showcase the power of our Docker fixtures!""" # Build URL to service listening on random port. url = 'http://%s:%d/' % ( docker_ip, docker_services.port_for('hello', 80), ) # Wait until service is responsive. docker_services.wait_until_responsive( check=lambda: is_responsive(url), timeout=30.0, pause=0.1, ) # Contact the service. response = requests.get(url) response.raise_for_status() log.debug(response.text)
def postgres_service(docker_ip, docker_services): """ starts postgress service with sample data """ config = init_db.TEST_CONFIG['postgres'] engine = init_db.test_engine docker_services.wait_until_responsive( check=lambda: is_responsive(**config), timeout=30.0, pause=1.0, ) init_db.setup_db(config) init_db.create_tables(engine) init_db.sample_data(engine) yield config init_db.drop_tables() init_db.teardown_db(config)
def rabbit_service(docker_services, docker_ip): os.environ['RABBITMQ_HOST'] = "{host}".format(host=docker_ip) os.environ['RABBITMQ_PORT'] = "{port}".format(port=docker_services.port_for('rabbit', 5672)) # Build URL to service listening on random port. url = 'amqp://{user}:{pw}@{url}:{port}'.format(user=RABBITMQ_USER, pw=RABBITMQ_PASSWORD, url=docker_ip, port=docker_services.port_for('rabbit', 5672)) # ping_url = "{url}:{port}".format(url=docker_ip, port=docker_services.port_for('rabbit', 5672)) rabbit = { 'user': RABBITMQ_USER, 'password': RABBITMQ_PASSWORD, 'host': docker_ip, 'port': docker_services.port_for('rabbit', 5672), 'url': url } # Wait until service is responsive. docker_services.wait_until_responsive( check=lambda: is_responsive_rabbit(rabbit), timeout=30.0, pause=0.1, ) return rabbit
def minio_service(docker_services, docker_ip): # Build URL to service listening on random port. url = 'http://%s:%d/' % ( docker_ip, docker_services.port_for('minio', 9000), ) # Wait until service is responsive. docker_services.wait_until_responsive( check=lambda: is_responsive(url, 403), timeout=30.0, pause=0.1, ) utils.setup_config(docker_ip, docker_services.port_for('minio', 9000), ACCESS_KEY, SECRET_KEY) return { 'endpoint': '{ip}:{port}'.format(ip=docker_ip, port=docker_services.port_for('minio', 9000)), 'access_key': ACCESS_KEY, 'secret_key': SECRET_KEY, 'bucket_name': BUCKET_NAME }