mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Add btests for supervisor stem/leaf process revival
This commit is contained in:
parent
bbdf5f8938
commit
5fb01caee6
7 changed files with 165 additions and 0 deletions
|
@ -98,3 +98,15 @@ function Supervisor::__is_supervisor%(%): bool
|
||||||
%{
|
%{
|
||||||
return val_mgr->GetBool(zeek::supervisor_mgr != nullptr);
|
return val_mgr->GetBool(zeek::supervisor_mgr != nullptr);
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
function Supervisor::__stem_pid%(%): int
|
||||||
|
%{
|
||||||
|
if ( zeek::supervisor_mgr )
|
||||||
|
return val_mgr->GetInt(zeek::supervisor_mgr->StemPID());
|
||||||
|
|
||||||
|
if ( zeek::Supervisor::ThisNode() )
|
||||||
|
return val_mgr->GetInt(zeek::Supervisor::ThisNode()->parent_pid);
|
||||||
|
|
||||||
|
builtin_error("supervisor mode not enabled and not a supervised node");
|
||||||
|
return val_mgr->GetInt(-1);
|
||||||
|
%}
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
supervised node zeek_init()
|
||||||
|
supervised node zeek_done()
|
|
@ -0,0 +1,7 @@
|
||||||
|
supervisor zeek_init()
|
||||||
|
supervisor connected to peer
|
||||||
|
supervisor lost peer
|
||||||
|
supervisor connected to peer
|
||||||
|
supervisor lost peer
|
||||||
|
supervisor connected to peer
|
||||||
|
supervisor zeek_done()
|
|
@ -0,0 +1,2 @@
|
||||||
|
supervised node zeek_init()
|
||||||
|
supervised node zeek_done()
|
|
@ -0,0 +1,7 @@
|
||||||
|
supervisor zeek_init()
|
||||||
|
supervisor connected to peer
|
||||||
|
supervisor lost peer
|
||||||
|
supervisor connected to peer
|
||||||
|
supervisor lost peer
|
||||||
|
supervisor connected to peer
|
||||||
|
supervisor zeek_done()
|
70
testing/btest/supervisor/revive-leaf.zeek
Normal file
70
testing/btest/supervisor/revive-leaf.zeek
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
# @TEST-PORT: BROKER_PORT
|
||||||
|
# @TEST-EXEC: btest-bg-run zeek zeek -j -b %INPUT
|
||||||
|
# @TEST-EXEC: btest-bg-wait 20
|
||||||
|
# @TEST-EXEC: btest-diff zeek/supervisor.out
|
||||||
|
# @TEST-EXEC: btest-diff zeek/node.out
|
||||||
|
|
||||||
|
# So the supervised node doesn't terminate right away.
|
||||||
|
redef exit_only_after_terminate=T;
|
||||||
|
|
||||||
|
global supervisor_output_file: file;
|
||||||
|
global node_output_file: file;
|
||||||
|
global topic = "test-topic";
|
||||||
|
global peers_added = 0;
|
||||||
|
|
||||||
|
event kill_self()
|
||||||
|
{
|
||||||
|
system(fmt("kill %s", getpid()));
|
||||||
|
}
|
||||||
|
|
||||||
|
event zeek_init()
|
||||||
|
{
|
||||||
|
if ( Supervisor::is_supervisor() )
|
||||||
|
{
|
||||||
|
Broker::subscribe(topic);
|
||||||
|
Broker::listen("127.0.0.1", to_port(getenv("BROKER_PORT")));
|
||||||
|
supervisor_output_file = open("supervisor.out");
|
||||||
|
print supervisor_output_file, "supervisor zeek_init()";
|
||||||
|
local sn = Supervisor::NodeConfig($name="grault");
|
||||||
|
local res = Supervisor::create(sn);
|
||||||
|
|
||||||
|
if ( res != "" )
|
||||||
|
print supervisor_output_file, res;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Broker::subscribe(topic);
|
||||||
|
Broker::peer("127.0.0.1", to_port(getenv("BROKER_PORT")));
|
||||||
|
node_output_file = open("node.out");
|
||||||
|
print node_output_file, "supervised node zeek_init()";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
event Broker::peer_added(endpoint: Broker::EndpointInfo, msg: string)
|
||||||
|
{
|
||||||
|
++peers_added;
|
||||||
|
|
||||||
|
if ( Supervisor::is_supervisor() )
|
||||||
|
{
|
||||||
|
print supervisor_output_file, "supervisor connected to peer";
|
||||||
|
|
||||||
|
if ( peers_added == 3 )
|
||||||
|
terminate();
|
||||||
|
else
|
||||||
|
Broker::publish(topic, kill_self);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
event Broker::peer_lost(endpoint: Broker::EndpointInfo, msg: string)
|
||||||
|
{
|
||||||
|
if ( Supervisor::is_supervisor() )
|
||||||
|
print supervisor_output_file, "supervisor lost peer";
|
||||||
|
}
|
||||||
|
|
||||||
|
event zeek_done()
|
||||||
|
{
|
||||||
|
if ( Supervisor::is_supervisor() )
|
||||||
|
print supervisor_output_file, "supervisor zeek_done()";
|
||||||
|
else
|
||||||
|
print node_output_file, "supervised node zeek_done()";
|
||||||
|
}
|
65
testing/btest/supervisor/revive-stem.zeek
Normal file
65
testing/btest/supervisor/revive-stem.zeek
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
# @TEST-PORT: BROKER_PORT
|
||||||
|
# @TEST-EXEC: btest-bg-run zeek zeek -j -b %INPUT
|
||||||
|
# @TEST-EXEC: btest-bg-wait 20
|
||||||
|
# @TEST-EXEC: btest-diff zeek/supervisor.out
|
||||||
|
# @TEST-EXEC: btest-diff zeek/node.out
|
||||||
|
|
||||||
|
# So the supervised node doesn't terminate right away.
|
||||||
|
redef exit_only_after_terminate=T;
|
||||||
|
|
||||||
|
global supervisor_output_file: file;
|
||||||
|
global node_output_file: file;
|
||||||
|
global topic = "test-topic";
|
||||||
|
global peers_added = 0;
|
||||||
|
|
||||||
|
event zeek_init()
|
||||||
|
{
|
||||||
|
if ( Supervisor::is_supervisor() )
|
||||||
|
{
|
||||||
|
Broker::subscribe(topic);
|
||||||
|
Broker::listen("127.0.0.1", to_port(getenv("BROKER_PORT")));
|
||||||
|
supervisor_output_file = open("supervisor.out");
|
||||||
|
print supervisor_output_file, "supervisor zeek_init()";
|
||||||
|
local sn = Supervisor::NodeConfig($name="grault");
|
||||||
|
local res = Supervisor::create(sn);
|
||||||
|
|
||||||
|
if ( res != "" )
|
||||||
|
print supervisor_output_file, res;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Broker::subscribe(topic);
|
||||||
|
Broker::peer("127.0.0.1", to_port(getenv("BROKER_PORT")));
|
||||||
|
node_output_file = open("node.out");
|
||||||
|
print node_output_file, "supervised node zeek_init()";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
event Broker::peer_added(endpoint: Broker::EndpointInfo, msg: string)
|
||||||
|
{
|
||||||
|
++peers_added;
|
||||||
|
|
||||||
|
if ( Supervisor::is_supervisor() )
|
||||||
|
{
|
||||||
|
print supervisor_output_file, "supervisor connected to peer";
|
||||||
|
|
||||||
|
if ( peers_added == 3 )
|
||||||
|
terminate();
|
||||||
|
else
|
||||||
|
system(fmt("kill %s", Supervisor::__stem_pid()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
event Broker::peer_lost(endpoint: Broker::EndpointInfo, msg: string)
|
||||||
|
{
|
||||||
|
if ( Supervisor::is_supervisor() )
|
||||||
|
print supervisor_output_file, "supervisor lost peer";
|
||||||
|
}
|
||||||
|
|
||||||
|
event zeek_done()
|
||||||
|
{
|
||||||
|
if ( Supervisor::is_supervisor() )
|
||||||
|
print supervisor_output_file, "supervisor zeek_done()";
|
||||||
|
else
|
||||||
|
print node_output_file, "supervised node zeek_done()";
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue