diff options
author | Marcin Siodelski <marcin@isc.org> | 2023-10-18 11:36:31 +0200 |
---|---|---|
committer | Marcin Siodelski <marcin@isc.org> | 2023-11-29 20:58:55 +0100 |
commit | c981b5b14d2d76a280316c10b99462222839b51e (patch) | |
tree | 3f9e8c806ca72f14dd01f2decb203675393a402c /src | |
parent | [#3106] Include origin in ha-sync-complete-notify (diff) | |
download | kea-c981b5b14d2d76a280316c10b99462222839b51e.tar.xz kea-c981b5b14d2d76a280316c10b99462222839b51e.zip |
[#3106] ha-maintenance-notify includes server name
Diffstat (limited to 'src')
5 files changed, 17 insertions, 8 deletions
diff --git a/src/hooks/dhcp/high_availability/command_creator.cc b/src/hooks/dhcp/high_availability/command_creator.cc index a43447f170..725f9f185a 100644 --- a/src/hooks/dhcp/high_availability/command_creator.cc +++ b/src/hooks/dhcp/high_availability/command_creator.cc @@ -247,8 +247,11 @@ CommandCreator::createLease6GetPage(const Lease6Ptr& last_lease6, } ConstElementPtr -CommandCreator::createMaintenanceNotify(const bool cancel, const HAServerType& server_type) { +CommandCreator::createMaintenanceNotify(const std::string& server_name, + const bool cancel, + const HAServerType& server_type) { auto args = Element::createMap(); + args->set("server-name", Element::create(server_name)); args->set("cancel", Element::create(cancel)); auto command = config::createCommand("ha-maintenance-notify", args); insertService(command, server_type); diff --git a/src/hooks/dhcp/high_availability/command_creator.h b/src/hooks/dhcp/high_availability/command_creator.h index dc65cffcc9..c137579dda 100644 --- a/src/hooks/dhcp/high_availability/command_creator.h +++ b/src/hooks/dhcp/high_availability/command_creator.h @@ -171,12 +171,16 @@ public: /// @brief Creates ha-maintenance-notify command. /// + /// @param server_name name of the server sending the command allowing + /// for associating the command with the relationship. /// @param cancel boolean value indicating if the maintenance /// is being cancelled (true) or requested (false). /// @param server_type type of the DHCP server, i.e. v4 or v6. /// @return Pointer to the JSON representation of the command. static data::ConstElementPtr - createMaintenanceNotify(const bool cancel, const HAServerType& server_type); + createMaintenanceNotify(const std::string& server_name, + const bool cancel, + const HAServerType& server_type); /// @brief Creates ha-sync-complete-notify command. /// diff --git a/src/hooks/dhcp/high_availability/ha_impl.cc b/src/hooks/dhcp/high_availability/ha_impl.cc index 042ff901fe..88fca58749 100644 --- a/src/hooks/dhcp/high_availability/ha_impl.cc +++ b/src/hooks/dhcp/high_availability/ha_impl.cc @@ -468,7 +468,7 @@ HAImpl::scopesHandler(hooks::CalloutHandle& callout_handle) { scopes_vector.push_back(scope->stringValue()); } - service = getHAServiceByServerName("ha-sync", args); + service = getHAServiceByServerName("ha-scopes", args); } catch (const std::exception& ex) { // There was an error while parsing command arguments. Return an error status @@ -588,7 +588,7 @@ HAImpl::haResetHandler(hooks::CalloutHandle& callout_handle) { return; } - ConstElementPtr response = services_->get()->processHAReset(); + ConstElementPtr response = service->processHAReset(); callout_handle.setArgument("response", response); } diff --git a/src/hooks/dhcp/high_availability/ha_service.cc b/src/hooks/dhcp/high_availability/ha_service.cc index 837aa3f095..c89afdea12 100644 --- a/src/hooks/dhcp/high_availability/ha_service.cc +++ b/src/hooks/dhcp/high_availability/ha_service.cc @@ -2696,7 +2696,8 @@ HAService::processMaintenanceStart() { (HttpRequest::Method::HTTP_POST, "/", HttpVersion::HTTP_11(), HostHttpHeader(remote_config->getUrl().getStrippedHostname())); remote_config->addBasicAuthHttpHeader(request); - request->setBodyAsJson(CommandCreator::createMaintenanceNotify(false, server_type_)); + request->setBodyAsJson(CommandCreator::createMaintenanceNotify(config_->getThisServerName(), + false, server_type_)); request->finalize(); // Response object should also be created because the HTTP client needs @@ -2822,7 +2823,8 @@ HAService::processMaintenanceCancel() { (HttpRequest::Method::HTTP_POST, "/", HttpVersion::HTTP_11(), HostHttpHeader(remote_config->getUrl().getStrippedHostname())); remote_config->addBasicAuthHttpHeader(request); - request->setBodyAsJson(CommandCreator::createMaintenanceNotify(true, server_type_)); + request->setBodyAsJson(CommandCreator::createMaintenanceNotify(config_->getThisServerName(), + true, server_type_)); request->finalize(); // Response object should also be created because the HTTP client needs diff --git a/src/hooks/dhcp/high_availability/tests/command_creator_unittest.cc b/src/hooks/dhcp/high_availability/tests/command_creator_unittest.cc index 5ad5f8973c..46d76cce44 100644 --- a/src/hooks/dhcp/high_availability/tests/command_creator_unittest.cc +++ b/src/hooks/dhcp/high_availability/tests/command_creator_unittest.cc @@ -507,7 +507,7 @@ TEST(CommandCreatorTest, createLease6GetPageZeroLimit) { // This test verifies that the ha-maintenance-notify command is correct // while being sent to the DHCPv4 server. TEST(CommandCreatorTest, createMaintenanceNotify4) { - ConstElementPtr command = CommandCreator::createMaintenanceNotify(true, HAServerType::DHCPv4); + ConstElementPtr command = CommandCreator::createMaintenanceNotify("server1", true, HAServerType::DHCPv4); ConstElementPtr arguments; ASSERT_NO_FATAL_FAILURE(testCommandBasics(command, "ha-maintenance-notify", "dhcp4", arguments)); @@ -521,7 +521,7 @@ TEST(CommandCreatorTest, createMaintenanceNotify4) { // This test verifies that the ha-maintenance-notify command is correct // while being sent to the DHCPv6 server. TEST(CommandCreatorTest, createMaintenanceNotify6) { - ConstElementPtr command = CommandCreator::createMaintenanceNotify(false, HAServerType::DHCPv6); + ConstElementPtr command = CommandCreator::createMaintenanceNotify("server1", false, HAServerType::DHCPv6); ConstElementPtr arguments; ASSERT_NO_FATAL_FAILURE(testCommandBasics(command, "ha-maintenance-notify", "dhcp6", arguments)); |