Simplify btests using cluster_started event.

This commit is contained in:
Jan Grashoefer 2023-04-26 20:00:44 +02:00
parent 4ddf7562b9
commit 342d88fbd4
30 changed files with 92 additions and 405 deletions

View file

@ -26,7 +26,7 @@ redef Cluster::nodes = {
};
@TEST-END-FILE
@load base/frameworks/cluster
@load policy/frameworks/cluster/experimental
@load base/frameworks/intel
module Intel;
@ -41,33 +41,12 @@ redef Intel::send_store_on_node_up = F;
global log_writes = 0;
global worker_data = 0;
global proxy_ready = F;
global sent_data = F;
event Cluster::node_up(name: string, id: string)
event Cluster::Experimental::cluster_started()
{
if ( Cluster::local_node_type() == Cluster::PROXY &&
Cluster::get_active_node_count(Cluster::WORKER) == 2 )
{
# Make the proxy tell the manager explicitly when both workers
# have checked in. The cluster framework normally generates this
# event with the Broker ID as second argument. We borrow the
# event to signal readiness, using recognizable arguments.
Broker::publish(Cluster::manager_topic, Cluster::node_up, Cluster::node, Cluster::node);
return;
}
if ( Cluster::local_node_type() == Cluster::MANAGER )
{
if ( name == "proxy-1" && id == "proxy-1" )
proxy_ready = T;
# Insert data once both workers and the proxy are connected, and
# the proxy has indicated that it too has both workers connected.
if ( Cluster::get_active_node_count(Cluster::WORKER) == 2 &&
Cluster::proxy_pool$alive_count == 1 && proxy_ready )
Intel::insert([$indicator="1.2.3.4", $indicator_type=Intel::ADDR, $meta=[$source="manager"]]);
}
Intel::insert([$indicator="1.2.3.4", $indicator_type=Intel::ADDR, $meta=[$source="manager"]]);
}
# Watch for new indicators sent to workers.

View file

@ -22,21 +22,18 @@ redef Cluster::nodes = {
};
@TEST-END-FILE
@load base/frameworks/cluster
@load policy/frameworks/cluster/experimental
@load base/frameworks/intel
module Intel;
redef Log::default_rotation_interval=0sec;
event Cluster::node_up(name: string, id: string)
event Cluster::Experimental::cluster_started()
{
# Insert the data once both workers are connected.
if ( Cluster::local_node_type() == Cluster::MANAGER &&
Cluster::get_active_node_count(Cluster::WORKER) == 2 )
{
if ( Cluster::local_node_type() == Cluster::MANAGER )
Intel::insert([$indicator="1.2.3.4", $indicator_type=Intel::ADDR, $meta=[$source="manager"]]);
}
}
global log_writes = 0;

View file

@ -28,6 +28,7 @@ e@mail.com Intel::EMAIL source1 Phishing email source http://some-data-distribut
@load base/frameworks/control
@load base/frameworks/intel
@load policy/frameworks/cluster/experimental
redef Log::default_rotation_interval=0sec;
module Intel;
@ -55,31 +56,16 @@ event do_it()
Broker::publish(Cluster::node_topic("manager-1"), do_it);
}
global hi_count = 0;
event start_it()
{
Broker::publish(Cluster::node_topic("worker-1"), do_it);
}
event hi()
event Cluster::Experimental::cluster_started()
{
if ( Cluster::node == "manager-1" )
{
++hi_count;
if ( hi_count == 2 )
# Give more time for intel distribution.
schedule 1sec { start_it() };
}
else
Broker::publish(Cluster::node_topic("manager-1"), hi);
}
event Cluster::node_up(name: string, id: string) &priority=-100
{
if ( Cluster::node == "manager-1" )
Broker::publish(Cluster::node_topic(name), hi);
# Give more time for intel distribution.
schedule 1sec { start_it() };
}
event do_terminate()

View file

@ -9,7 +9,7 @@
# @TEST-EXEC: btest-diff manager-1/intel.log
@load base/frameworks/intel
@load base/frameworks/cluster
@load policy/frameworks/cluster/experimental
# @TEST-START-FILE cluster-layout.zeek
redef Cluster::nodes = {
@ -41,8 +41,11 @@ event test_manager()
Broker::publish(Cluster::worker_topic, test_worker);
}
event ready()
event Cluster::Experimental::cluster_started()
{
if ( Cluster::node != "manager-1" )
return;
# Insert the data once all workers are connected.
Intel::insert([$indicator="192.168.0.1", $indicator_type=Intel::ADDR, $meta=[$source="source1"]]);
Intel::insert([$indicator="192.168.0.2", $indicator_type=Intel::ADDR, $meta=[$source="source1"]]);
@ -54,12 +57,6 @@ event ready()
event test_manager();
}
event Cluster::node_up(name: string, id: string)
{
if ( Cluster::node == "worker-1" )
Broker::publish(Cluster::manager_topic, ready);
}
event Intel::remove_item(item: Item, purge_indicator: bool)
{
print fmt("Removing %s (source: %s).", item$indicator, item$meta$source);