def pytest_configure() -> None: """ Set up the Sentry SDK to avoid errors hidden by configuration. Ensure the snuba_test database exists """ assert ( settings.TESTING ), "settings.TESTING is False, try `SNUBA_SETTINGS=test` or `make test`" setup_sentry() for cluster in settings.CLUSTERS: clickhouse_cluster = ClickhouseCluster( host=cluster["host"], port=cluster["port"], user="******", password="", database="default", http_port=cluster["http_port"], storage_sets=cluster["storage_sets"], single_node=cluster["single_node"], cluster_name=cluster["cluster_name"] if "cluster_name" in cluster else None, distributed_cluster_name=cluster["distributed_cluster_name"] if "distributed_cluster_name" in cluster else None, ) database_name = cluster["database"] nodes = [ *clickhouse_cluster.get_local_nodes(), *clickhouse_cluster.get_distributed_nodes(), ] for node in nodes: connection = clickhouse_cluster.get_node_connection( ClickhouseClientSettings.MIGRATE, node) connection.execute(f"DROP DATABASE IF EXISTS {database_name};") connection.execute(f"CREATE DATABASE {database_name};")
def is_valid_node(host: str, port: int, cluster: ClickhouseCluster) -> bool: nodes = [*cluster.get_local_nodes(), cluster.get_query_node()] return any(node.host_name == host and node.port == port for node in nodes)