Esempio n. 1
0
def started_cluster():
    try:
        cluster = ClickHouseCluster(__file__)
        instance = cluster.add_instance("dummy")
        cluster.start()

        cluster.communication_port = 10000
        instance.copy_file_to_container(os.path.join(os.path.dirname(__file__), "server.py"), "test_server.py")
        cluster.bucket = "abc"
        instance.exec_in_container(["python", "test_server.py", str(cluster.communication_port), cluster.bucket], detach=True)
        cluster.mock_host = instance.ip_address

        for i in range(10):
            try:
                data = get_communication_data(cluster)
                cluster.redirecting_to_http_port = data["redirecting_to_http_port"]
                cluster.preserving_data_port = data["preserving_data_port"]
                cluster.multipart_preserving_data_port = data["multipart_preserving_data_port"]
                cluster.redirecting_preserving_data_port = data["redirecting_preserving_data_port"]
            except:
                logging.error(traceback.format_exc())
                time.sleep(0.5)
            else:
                break
        else:
            assert False, "Could not initialize mock server"

        yield cluster

    finally:
        cluster.shutdown()