From b3f53dc4550f97f93836402478c634c5c64640d8 Mon Sep 17 00:00:00 2001 From: Arne Welzel Date: Wed, 14 May 2025 11:16:11 +0200 Subject: [PATCH] testing/btest/Files: Add generic broker/cluster-layout.zeek This is a cluster-layout.zeek template that can be copied into a testing directory if needed. The idea is that a developer sets environment variables within their btest and the Cluster::nodes variable is implicitly extended by appropriate nodes. For example, using @TEST-PORT BROKER_LOGGER1_PORT will add an appropriate logger-1 node to Cluster::nodes, based on the existence of the BROKER_LOGGER1_PORT environment variable. --- .../btest/Files/broker/cluster-layout.zeek | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 testing/btest/Files/broker/cluster-layout.zeek diff --git a/testing/btest/Files/broker/cluster-layout.zeek b/testing/btest/Files/broker/cluster-layout.zeek new file mode 100644 index 0000000000..f495e8da29 --- /dev/null +++ b/testing/btest/Files/broker/cluster-layout.zeek @@ -0,0 +1,85 @@ +# +# Use this file in a test by copying it into the tests directory: +# +# @TEST-EXEC: cp $FILES/broker/cluster-layout.zeek . +# +# Then specify @TEST-PORT using the following: +# +# BROKER_MANAGER_PORT +# BROKER_LOGGER1_PORT +# BROKER_LOGGER2_PORT +# BROKER_PROXY1_PORT +# BROKER_PROXY2_PORT +# BROKER_WORKER1_PORT +# BROKER_WORKER2_PORT +# BROKER_WORKER3_PORT +# BROKER_WORKER4_PORT +# +# The existence of the environment variable will add a corresponding node +# to Cluster::nodes. + + +# Redef'ed to F if logger-1 or logger-2 are active. +redef Cluster::manager_is_logger = T; + +# Minimal cluster-layout for two nodes. +redef Cluster::nodes = { + ["manager"] = [$node_type=Cluster::MANAGER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_MANAGER_PORT"))], +}; + +# Depending on what environment variables are set, extend the Cluster::nodes table +# with more nodes. This allows tests to control the contents of Cluster::nodes +# just by using TEST-PORT accordingly to the used environment variables. + +### Loggers +@if ( getenv("BROKER_LOGGER1_PORT") != "" ) +redef Cluster::manager_is_logger = F; +redef Cluster::nodes += { + ["logger-1"] = [$node_type=Cluster::LOGGER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_LOGGER1_PORT")), $manager="manager"], +}; +@endif + +@if ( getenv("BROKER_LOGGER2_PORT") != "" ) +redef Cluster::manager_is_logger = F; +redef Cluster::nodes += { + ["logger-2"] = [$node_type=Cluster::LOGGER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_LOGGER2_PORT")), $manager="manager"], +}; +@endif + +### Proxies +@if ( getenv("BROKER_PROXY1_PORT") != "" ) +redef Cluster::nodes += { + ["proxy-1"] = [$node_type=Cluster::PROXY, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PROXY1_PORT")), $manager="manager"], +}; +@endif + +@if ( getenv("BROKER_PROXY2_PORT") != "" ) +redef Cluster::nodes += { + ["proxy-2"] = [$node_type=Cluster::PROXY, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PROXY2_PORT")), $manager="manager"], +}; +@endif + +### Workers +@if ( getenv("BROKER_WORKER1_PORT") != "" ) +redef Cluster::nodes += { + ["worker-1"] = [$node_type=Cluster::WORKER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_WORKER1_PORT")), $manager="manager"], +}; +@endif + +@if ( getenv("BROKER_WORKER2_PORT") != "" ) +redef Cluster::nodes += { + ["worker-2"] = [$node_type=Cluster::WORKER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_WORKER2_PORT")), $manager="manager"], +}; +@endif + +@if ( getenv("BROKER_WORKER3_PORT") != "" ) +redef Cluster::nodes += { + ["worker-3"] = [$node_type=Cluster::WORKER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_WORKER3_PORT")), $manager="manager"], +}; +@endif + +@if ( getenv("BROKER_WORKER4_PORT") != "" ) +redef Cluster::nodes += { + ["worker-4"] = [$node_type=Cluster::WORKER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_WORKER4_PORT")), $manager="manager"], +}; +@endif