2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-31 05:55:28 +00:00

[#3106] ha-maintenance-notify includes server name

This commit is contained in:
Marcin Siodelski
2023-10-18 11:36:31 +02:00
parent ccd4873dcf
commit c981b5b14d
5 changed files with 17 additions and 8 deletions

View File

@@ -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);

View File

@@ -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.
///

View File

@@ -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);
}

View File

@@ -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

View File

@@ -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));