diff --git a/testing/btest/Baseline/scripts.policy.frameworks.cluster.cluster_started_restart_manager/zeek.manager.stdout b/testing/btest/Baseline/scripts.policy.frameworks.cluster.cluster_started_restart_manager/zeek.manager.stdout new file mode 100644 index 0000000000..71012a64ca --- /dev/null +++ b/testing/btest/Baseline/scripts.policy.frameworks.cluster.cluster_started_restart_manager/zeek.manager.stdout @@ -0,0 +1,7 @@ +### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. +supervised node zeek_init(), manager +node fully connected (resending: F) +node fully connected (resending: T) +node fully connected (resending: T) +node fully connected (resending: T) +supervised node zeek_done(), manager diff --git a/testing/btest/Baseline/scripts.policy.frameworks.cluster.cluster_started_restart_manager/zeek.proxy-1.stdout b/testing/btest/Baseline/scripts.policy.frameworks.cluster.cluster_started_restart_manager/zeek.proxy-1.stdout new file mode 100644 index 0000000000..7e3218b69c --- /dev/null +++ b/testing/btest/Baseline/scripts.policy.frameworks.cluster.cluster_started_restart_manager/zeek.proxy-1.stdout @@ -0,0 +1,7 @@ +### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. +supervised node zeek_init(), proxy-1 +node fully connected (resending: F) +cluster_started +node fully connected (resending: T) +node fully connected (resending: T) +supervised node zeek_done(), proxy-1 diff --git a/testing/btest/Baseline/scripts.policy.frameworks.cluster.cluster_started_restart_manager/zeek.supervisor.out b/testing/btest/Baseline/scripts.policy.frameworks.cluster.cluster_started_restart_manager/zeek.supervisor.out new file mode 100644 index 0000000000..8591a66f10 --- /dev/null +++ b/testing/btest/Baseline/scripts.policy.frameworks.cluster.cluster_started_restart_manager/zeek.supervisor.out @@ -0,0 +1,5 @@ +### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. +supervisor zeek_init() +restarting manager +restarting manager +supervisor zeek_done() diff --git a/testing/btest/Baseline/scripts.policy.frameworks.cluster.cluster_started_restart_manager/zeek.worker-1.stdout b/testing/btest/Baseline/scripts.policy.frameworks.cluster.cluster_started_restart_manager/zeek.worker-1.stdout new file mode 100644 index 0000000000..1e7ad8e88b --- /dev/null +++ b/testing/btest/Baseline/scripts.policy.frameworks.cluster.cluster_started_restart_manager/zeek.worker-1.stdout @@ -0,0 +1,7 @@ +### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. +supervised node zeek_init(), worker-1 +node fully connected (resending: F) +cluster_started +node fully connected (resending: T) +node fully connected (resending: T) +supervised node zeek_done(), worker-1 diff --git a/testing/btest/Baseline/scripts.policy.frameworks.cluster.cluster_started_restart_worker/zeek.manager.stdout b/testing/btest/Baseline/scripts.policy.frameworks.cluster.cluster_started_restart_worker/zeek.manager.stdout new file mode 100644 index 0000000000..ab63e783cb --- /dev/null +++ b/testing/btest/Baseline/scripts.policy.frameworks.cluster.cluster_started_restart_worker/zeek.manager.stdout @@ -0,0 +1,10 @@ +### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. +supervised node zeek_init(), manager +node fully connected +node fully connected +node fully connected +node fully connected +cluster_started +node fully connected +node fully connected +supervised node zeek_done(), manager diff --git a/testing/btest/Baseline/scripts.policy.frameworks.cluster.cluster_started_restart_worker/zeek.proxy-1.stdout b/testing/btest/Baseline/scripts.policy.frameworks.cluster.cluster_started_restart_worker/zeek.proxy-1.stdout new file mode 100644 index 0000000000..db35a7c798 --- /dev/null +++ b/testing/btest/Baseline/scripts.policy.frameworks.cluster.cluster_started_restart_worker/zeek.proxy-1.stdout @@ -0,0 +1,5 @@ +### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. +supervised node zeek_init(), proxy-1 +node fully connected +cluster_started +supervised node zeek_done(), proxy-1 diff --git a/testing/btest/Baseline/scripts.policy.frameworks.cluster.cluster_started_restart_worker/zeek.supervisor.out b/testing/btest/Baseline/scripts.policy.frameworks.cluster.cluster_started_restart_worker/zeek.supervisor.out new file mode 100644 index 0000000000..3dc8ca353d --- /dev/null +++ b/testing/btest/Baseline/scripts.policy.frameworks.cluster.cluster_started_restart_worker/zeek.supervisor.out @@ -0,0 +1,5 @@ +### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. +supervisor zeek_init() +restarting worker-1 +restarting worker-1 +supervisor zeek_done() diff --git a/testing/btest/Baseline/scripts.policy.frameworks.cluster.cluster_started_restart_worker/zeek.worker-1.stdout b/testing/btest/Baseline/scripts.policy.frameworks.cluster.cluster_started_restart_worker/zeek.worker-1.stdout new file mode 100644 index 0000000000..564605c60d --- /dev/null +++ b/testing/btest/Baseline/scripts.policy.frameworks.cluster.cluster_started_restart_worker/zeek.worker-1.stdout @@ -0,0 +1,4 @@ +### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. +supervised node zeek_init(), worker-1 +node fully connected +supervised node zeek_done(), worker-1 diff --git a/testing/btest/Baseline/scripts.policy.frameworks.cluster.cluster_started_restart_worker/zeek.worker-2.stdout b/testing/btest/Baseline/scripts.policy.frameworks.cluster.cluster_started_restart_worker/zeek.worker-2.stdout new file mode 100644 index 0000000000..b4ebe94708 --- /dev/null +++ b/testing/btest/Baseline/scripts.policy.frameworks.cluster.cluster_started_restart_worker/zeek.worker-2.stdout @@ -0,0 +1,5 @@ +### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. +supervised node zeek_init(), worker-2 +node fully connected +cluster_started +supervised node zeek_done(), worker-2 diff --git a/testing/btest/scripts/policy/frameworks/cluster/cluster_started_restart_manager.zeek b/testing/btest/scripts/policy/frameworks/cluster/cluster_started_restart_manager.zeek new file mode 100644 index 0000000000..8e5f8a2f33 --- /dev/null +++ b/testing/btest/scripts/policy/frameworks/cluster/cluster_started_restart_manager.zeek @@ -0,0 +1,123 @@ +# @TEST-DOC: Verify cluster_started() is not rebroadcasted if the manager restarts. +# @TEST-PORT: SUPERVISOR_PORT +# @TEST-PORT: MANAGER_PORT +# @TEST-PORT: PROXY_PORT +# @TEST-PORT: WORKER1_PORT +# @TEST-PORT: WORKER2_PORT +# @TEST-EXEC: btest-bg-run zeek zeek -j -b %INPUT +# @TEST-EXEC: btest-bg-wait 25 +# @TEST-EXEC: btest-diff zeek/supervisor.out +# @TEST-EXEC: btest-diff zeek/manager/stdout +# @TEST-EXEC: btest-diff zeek/worker-1/stdout +# @TEST-EXEC: btest-diff zeek/proxy-1/stdout + +@load base/frameworks/cluster +@load policy/frameworks/cluster/experimental + +# So the supervised node doesn't terminate right away. +redef exit_only_after_terminate=T; + +redef Log::default_rotation_interval = 0secs; + +global topic = "test-topic"; + +@if ( Supervisor::is_supervisor() ) + +global supervisor_output_file: file; +global manager_starts = 0; + +event Cluster::Experimental::cluster_started() + { + # Restart the manager a first time + ++manager_starts; + print supervisor_output_file, "restarting manager"; + Supervisor::restart("manager"); + } + +global redispatched_signals = 0; + +event Cluster::Experimental::node_fully_connected(name: string, id: string, resending: bool) + { + if ( resending ) + ++redispatched_signals; + + if ( redispatched_signals == 3 ) + { + # Restart the manager a second time + if ( ++manager_starts >= 3 ) + { + terminate(); + return; + } + + print supervisor_output_file, "restarting manager"; + Supervisor::restart("manager"); + redispatched_signals = 0; + } + } + +event zeek_init() + { + Broker::subscribe(topic); + Broker::listen("127.0.0.1", to_port(getenv("SUPERVISOR_PORT"))); + supervisor_output_file = open("supervisor.out"); + print supervisor_output_file, "supervisor zeek_init()"; + + local cluster: table[string] of Supervisor::ClusterEndpoint; + cluster["manager"] = [$role=Supervisor::MANAGER, $host=127.0.0.1, + $p=to_port(getenv("MANAGER_PORT"))]; + cluster["proxy-1"] = [$role=Supervisor::PROXY, $host=127.0.0.1, + $p=to_port(getenv("PROXY_PORT"))]; + cluster["worker-1"] = [$role=Supervisor::WORKER, $host=127.0.0.1, + $p=to_port(getenv("WORKER1_PORT"))]; + cluster["worker-2"] = [$role=Supervisor::WORKER, $host=127.0.0.1, + $p=to_port(getenv("WORKER2_PORT"))]; + + for ( n, ep in cluster ) + { + local sn = Supervisor::NodeConfig($name = n); + sn$cluster = cluster; + sn$directory = n; + sn$stdout_file = "stdout"; + sn$stderr_file = "stderr"; + local res = Supervisor::create(sn); + + if ( res != "" ) + print fmt("failed to create node %s: %s", n, res); + } + } + +event zeek_done() + { + print supervisor_output_file, "supervisor zeek_done()"; + } + +@else + +event zeek_init() + { + print "supervised node zeek_init()", Cluster::node; + + Broker::peer("127.0.0.1", to_port(getenv("SUPERVISOR_PORT"))); + } + +event Cluster::Experimental::node_fully_connected(name: string, id: string, resending: bool) + { + print fmt("node fully connected (resending: %s)", resending); + if ( Cluster::node == "manager" ) + Broker::publish(topic, Cluster::Experimental::node_fully_connected, name, id, resending); + } + +event Cluster::Experimental::cluster_started() + { + print "cluster_started"; + if ( Cluster::node == "manager" ) + Broker::publish(topic, Cluster::Experimental::cluster_started); + } + +event zeek_done() + { + print "supervised node zeek_done()", Cluster::node; + } + +@endif diff --git a/testing/btest/scripts/policy/frameworks/cluster/cluster_started_restart_worker.zeek b/testing/btest/scripts/policy/frameworks/cluster/cluster_started_restart_worker.zeek new file mode 100644 index 0000000000..c36e136234 --- /dev/null +++ b/testing/btest/scripts/policy/frameworks/cluster/cluster_started_restart_worker.zeek @@ -0,0 +1,109 @@ +# @TEST-DOC: Verify cluster_started() is not rebroadcasted if a worker restarts. +# @TEST-PORT: SUPERVISOR_PORT +# @TEST-PORT: MANAGER_PORT +# @TEST-PORT: PROXY_PORT +# @TEST-PORT: WORKER1_PORT +# @TEST-PORT: WORKER2_PORT +# @TEST-EXEC: btest-bg-run zeek zeek -j -b %INPUT +# @TEST-EXEC: btest-bg-wait 25 +# @TEST-EXEC: btest-diff zeek/supervisor.out +# @TEST-EXEC: btest-diff zeek/manager/stdout +# @TEST-EXEC: btest-diff zeek/worker-1/stdout +# @TEST-EXEC: btest-diff zeek/worker-2/stdout +# @TEST-EXEC: btest-diff zeek/proxy-1/stdout + +@load base/frameworks/cluster +@load policy/frameworks/cluster/experimental + +# So the supervised node doesn't terminate right away. +redef exit_only_after_terminate=T; + +redef Log::default_rotation_interval = 0secs; + +global topic = "test-topic"; + +@if ( Supervisor::is_supervisor() ) + +global supervisor_output_file: file; +global worker1_starts = 0; + +event Cluster::Experimental::node_fully_connected(name: string, id: string, resending: bool) + { + if ( name != "worker-1" ) + return; + + # Restart worker-1 twice + if ( ++worker1_starts >= 3 ) + { + terminate(); + return; + } + + print supervisor_output_file, fmt("restarting %s", name); + Supervisor::restart("worker-1"); + } + +event zeek_init() + { + Broker::subscribe(topic); + Broker::listen("127.0.0.1", to_port(getenv("SUPERVISOR_PORT"))); + supervisor_output_file = open("supervisor.out"); + print supervisor_output_file, "supervisor zeek_init()"; + + local cluster: table[string] of Supervisor::ClusterEndpoint; + cluster["manager"] = [$role=Supervisor::MANAGER, $host=127.0.0.1, + $p=to_port(getenv("MANAGER_PORT"))]; + cluster["proxy-1"] = [$role=Supervisor::PROXY, $host=127.0.0.1, + $p=to_port(getenv("PROXY_PORT"))]; + cluster["worker-1"] = [$role=Supervisor::WORKER, $host=127.0.0.1, + $p=to_port(getenv("WORKER1_PORT"))]; + cluster["worker-2"] = [$role=Supervisor::WORKER, $host=127.0.0.1, + $p=to_port(getenv("WORKER2_PORT"))]; + + for ( n, ep in cluster ) + { + local sn = Supervisor::NodeConfig($name = n); + sn$cluster = cluster; + sn$directory = n; + sn$stdout_file = "stdout"; + sn$stderr_file = "stderr"; + local res = Supervisor::create(sn); + + if ( res != "" ) + print fmt("failed to create node %s: %s", n, res); + } + } + +event zeek_done() + { + print supervisor_output_file, "supervisor zeek_done()"; + } + +@else + +event zeek_init() + { + print "supervised node zeek_init()", Cluster::node; + + Broker::peer("127.0.0.1", to_port(getenv("SUPERVISOR_PORT"))); + } + +event Cluster::Experimental::node_fully_connected(name: string, id: string, resending: bool) + { + print "node fully connected"; + + if ( Cluster::node == "manager" ) + Broker::publish(topic, Cluster::Experimental::node_fully_connected, name, id, resending); + } + +event Cluster::Experimental::cluster_started() + { + print "cluster_started"; + } + +event zeek_done() + { + print "supervised node zeek_done()", Cluster::node; + } + +@endif