]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5675] Added ha-continue command handler.
authorMarcin Siodelski <marcin@isc.org>
Wed, 11 Jul 2018 16:31:27 +0000 (18:31 +0200)
committerMarcin Siodelski <marcin@isc.org>
Wed, 18 Jul 2018 18:03:35 +0000 (20:03 +0200)
src/hooks/dhcp/high_availability/ha_callouts.cc
src/hooks/dhcp/high_availability/ha_impl.cc
src/hooks/dhcp/high_availability/ha_impl.h
src/hooks/dhcp/high_availability/ha_messages.mes
src/hooks/dhcp/high_availability/tests/ha_impl_unittest.cc

index 30756a2cfbae711ba7eb086bb0ca1a941098dfb2..6dcdeac3ebce251275bdcf149b0a6413dabb8a7e 100644 (file)
@@ -190,6 +190,19 @@ int scopes_command(CalloutHandle& handle) {
     return (0);
 }
 
+/// @brief ha-continue command handler implementation.
+int continue_command(CalloutHandle& handle) {
+    try {
+        impl->continueHandler(handle);
+
+    } catch (const std::exception& ex) {
+        LOG_ERROR(ha_logger, HA_CONTINUE_HANDLER_FAILED)
+            .arg(ex.what());
+    }
+
+    return (0);
+}
+
 /// @brief This function is called when the library is loaded.
 ///
 /// @param handle library handle
@@ -208,6 +221,7 @@ int load(LibraryHandle& handle) {
         handle.registerCommandCallout("ha-heartbeat", heartbeat_command);
         handle.registerCommandCallout("ha-sync", sync_command);
         handle.registerCommandCallout("ha-scopes", scopes_command);
+        handle.registerCommandCallout("ha-continue", continue_command);
 
     } catch (const std::exception& ex) {
         LOG_ERROR(ha_logger, HA_CONFIGURATION_FAILED)
index 3d9a057d4b1b252cc0aad7da31397ca0fb1fbd26..46fadf68b6f3d3f97c5d3d746ec9d28a1e7e2a2c 100644 (file)
@@ -390,5 +390,12 @@ HAImpl::scopesHandler(hooks::CalloutHandle& callout_handle) {
     callout_handle.setArgument("response", response);
 }
 
+void
+HAImpl::continueHandler(hooks::CalloutHandle& callout_handle) {
+    ConstElementPtr response = service_->processContinue();
+    callout_handle.setArgument("response", response);
+}
+
+
 } // end of namespace isc::ha
 } // end of namespace isc
index 85486200e55f765baaa4f9ffee91301237750ee6..a27892ba57e908904180aecd23a3f71ca5d408f6 100644 (file)
@@ -137,6 +137,11 @@ public:
     /// @param callout_handle Callout handle provided to the callout.
     void scopesHandler(hooks::CalloutHandle& callout_handle);
 
+    /// @brief Implements handler for the ha-continue command.
+    ///
+    /// @param callout_handle Callout handle provided to the callout.
+    void continueHandler(hooks::CalloutHandle& callout_handle);
+
 protected:
 
     /// @brief Holds parsed configuration.
index d0aea18523a03ec27f33554294cad358c20764e0..1f752bcaf845cff7d5130dc62633bb0106bcd7f0 100644 (file)
@@ -107,6 +107,11 @@ are administratively disabled and will not be issued in the HA state to
 which the server has transitioned. The sole argument specifies the state
 into which the server has transitioned.
 
+% HA_CONTINUE_HANDLER_FAILED ha-continue command failed: %1
+This error message is issued to indicate that the ha-continue command handler
+failed while processing the command. The argument provides the reason for
+failure.
+
 % HA_DEINIT_OK unloading High Availability hooks library successful
 This informational message indicates that the High Availability hooks library
 has been unloaded successfully.
index 19abf085921997ff84fb9bc9525c8c1272bfa98e..f1be7c121ad3a38f0a21e80e1908d6e0a2ddd113 100644 (file)
@@ -509,5 +509,29 @@ TEST_F(HAImplTest, synchronizeHandler) {
 
 }
 
+// Tests ha-continue command handler.
+TEST_F(HAImplTest, continueHandler) {
+    HAImpl ha_impl;
+    ASSERT_NO_THROW(ha_impl.configure(createValidJsonConfiguration()));
+
+    // Starting the service is required prior to running any callouts.
+    NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv4));
+    ASSERT_NO_THROW(ha_impl.startService(io_service_, network_state,
+                                         HAServerType::DHCPv4));
+
+    ConstElementPtr command = Element::fromJSON("{ \"command\": \"ha-continue\" }");
+
+    CalloutHandlePtr callout_handle = HooksManager::createCalloutHandle();
+    callout_handle->setArgument("command", command);
+
+    ASSERT_NO_THROW(ha_impl.continueHandler(*callout_handle));
+
+    ConstElementPtr response;
+    callout_handle->getArgument("response", response);
+    ASSERT_TRUE(response);
+
+    checkAnswer(response, CONTROL_RESULT_SUCCESS, "HA state machine is not paused.");
+}
+
 
 }