def project_config()

in it_serverless/conftest.py [0:0]


def project_config(project, tmpdir_factory):
    credentials = serverless_api(
        "POST",
        f"/api/v1/serverless/projects/elasticsearch/{project['id']}{GET_CREDENTIALS_ENDPOINT}",
    )

    es_endpoint = project["endpoints"]["elasticsearch"]
    es_hostname = urllib.parse.urlparse(es_endpoint).hostname
    rally_target_host = f"{es_hostname}:443"

    print("Waiting for DNS propagation")
    for _ in range(6):
        time.sleep(30)
        with contextlib.suppress(subprocess.CalledProcessError):
            subprocess.run(["nslookup", es_hostname, "8.8.8.8"], check=True)
            break
    else:
        raise ValueError("Timed out waiting for DNS propagation")

    print("Waiting for Elasticsearch")
    for _ in range(18):
        try:
            es = Elasticsearch(
                f"https://{rally_target_host}",
                basic_auth=(
                    credentials["username"],
                    credentials["password"],
                ),
                request_timeout=10,
            )
            info = es.info()
            print("GET /")
            print(json.dumps(info.body, indent=2))

            authenticate = es.perform_request(method="GET", path="/_security/_authenticate")
            print("GET /_security/_authenticate")
            print(json.dumps(authenticate.body, indent=2))

            break
        except Exception as e:
            print(f"GET / Failed with {str(e)}")
            time.sleep(10)
    else:
        raise ValueError("Timed out waiting for Elasticsearch")

    # Create API key to test Rally with a public user privileges
    print("Waiting for API key")
    for _ in range(18):
        try:
            api_key = es.security.create_api_key(name="public-api-key")
            break
        except Exception as e:
            print(f"API create failed with {str(e)}")
            time.sleep(10)
    else:
        raise ValueError("Timed out waiting for API key")

    # Confirm API key is working fine
    print("Testing API key")
    for _ in range(18):
        try:
            es = Elasticsearch(
                f"https://{rally_target_host}",
                api_key=api_key.body["encoded"],
                request_timeout=10,
            )
            info = es.info()
            break
        except Exception as e:
            print(f"API verification failed with {str(e)}")
            time.sleep(10)
    else:
        raise ValueError("Timed out verifying API key")

    project_config = ServerlessProjectConfig(
        rally_target_host,
        credentials["username"],
        credentials["password"],
        api_key.body["encoded"],
    )
    project_config.prepare_client_options_files(tmpdir_factory)
    yield project_config