]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3106] ha-maintenance-notify includes server name
authorMarcin Siodelski <marcin@isc.org>
Wed, 18 Oct 2023 09:36:31 +0000 (11:36 +0200)
committerMarcin Siodelski <marcin@isc.org>
Wed, 29 Nov 2023 19:58:55 +0000 (20:58 +0100)
src/hooks/dhcp/high_availability/command_creator.cc
src/hooks/dhcp/high_availability/command_creator.h
src/hooks/dhcp/high_availability/ha_impl.cc
src/hooks/dhcp/high_availability/ha_service.cc
src/hooks/dhcp/high_availability/tests/command_creator_unittest.cc

index a43447f17059c9bfe347ef23e5be6c5df8c636c1..725f9f185a480dfbcdb3298db7183f77459ffdbd 100644 (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);
index dc65cffcc987ba4db0436b95da1c12a2ba4005bc..c137579dda6b1a30cef498f4fa2800d8cab88dbb 100644 (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.
     ///
index 042ff901fe0020de6a6c52b38e356b8c7c0ee1d7..88fca58749f1fb978ae337a73ad244a7f09d2f03 100644 (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);
 }
 
index 837aa3f095163d04cd8fbb0a86512ddfb43d2d61..c89afdea12eef99772e0486e697326512a5ab688 100644 (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
index 5ad5f8973cdc1d45c804379ca17b14028e8f83df..46d76cce4451678670656166449fbd29ab7015ce 100644 (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));