From 5592beaf31c9e9c23b0f49fd99596ca1df3fb227 Mon Sep 17 00:00:00 2001 From: Christian Kreibich Date: Mon, 13 Jun 2022 13:19:04 -0700 Subject: [PATCH] Management framework: handle no-instances corner case in set-config correctly When the controller receives a configuration with no instances (and thus no nodes), it needs to roundtrip to agents and can send the response right away. --- .../management/controller/main.zeek | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/scripts/policy/frameworks/management/controller/main.zeek b/scripts/policy/frameworks/management/controller/main.zeek index a0100355ab..e1e02c2c81 100644 --- a/scripts/policy/frameworks/management/controller/main.zeek +++ b/scripts/policy/frameworks/management/controller/main.zeek @@ -668,8 +668,26 @@ event Management::Controller::API::set_configuration_request(reqid: string, conf add_instance(insts_to_peer[inst_name]); } - # Updates to out instance tables are complete, now check if we're already - # able to send the config to the agents: + # Updates to instance tables are complete. As a corner case, if the + # config contained no instances (and thus no nodes), we're now done + # since there are no agent interactions to wait for: + if ( |insts_new| == 0 ) + { + g_config_current = req$set_configuration_state$config; + g_config_reqid_pending = ""; + + Management::Log::info(fmt("tx Management::Controller::API::set_configuration_response %s", + Management::Request::to_string(req))); + Broker::publish(Management::Controller::topic, + Management::Controller::API::set_configuration_response, req$id, req$results); + Management::Request::finish(req$id); + return; + } + + # Otherwise, check if we're able to send the config to all agents + # involved. If that's the case, this will trigger a + # Management::Controller::API::notify_agents_ready event that implements + # the distribution in the controller's own event handler, above. check_instances_ready(); }