From: Marcin Siodelski Date: Wed, 11 Jul 2018 16:31:27 +0000 (+0200) Subject: [5675] Added ha-continue command handler. X-Git-Tag: ha_phase2~41^2~6 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=b28ab59286a6bb2b6eaa748de5c17a3522f65791;p=thirdparty%2Fkea.git [5675] Added ha-continue command handler. --- diff --git a/src/hooks/dhcp/high_availability/ha_callouts.cc b/src/hooks/dhcp/high_availability/ha_callouts.cc index 30756a2cfb..6dcdeac3eb 100644 --- a/src/hooks/dhcp/high_availability/ha_callouts.cc +++ b/src/hooks/dhcp/high_availability/ha_callouts.cc @@ -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) diff --git a/src/hooks/dhcp/high_availability/ha_impl.cc b/src/hooks/dhcp/high_availability/ha_impl.cc index 3d9a057d4b..46fadf68b6 100644 --- a/src/hooks/dhcp/high_availability/ha_impl.cc +++ b/src/hooks/dhcp/high_availability/ha_impl.cc @@ -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 diff --git a/src/hooks/dhcp/high_availability/ha_impl.h b/src/hooks/dhcp/high_availability/ha_impl.h index 85486200e5..a27892ba57 100644 --- a/src/hooks/dhcp/high_availability/ha_impl.h +++ b/src/hooks/dhcp/high_availability/ha_impl.h @@ -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. diff --git a/src/hooks/dhcp/high_availability/ha_messages.mes b/src/hooks/dhcp/high_availability/ha_messages.mes index d0aea18523..1f752bcaf8 100644 --- a/src/hooks/dhcp/high_availability/ha_messages.mes +++ b/src/hooks/dhcp/high_availability/ha_messages.mes @@ -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. diff --git a/src/hooks/dhcp/high_availability/tests/ha_impl_unittest.cc b/src/hooks/dhcp/high_availability/tests/ha_impl_unittest.cc index 19abf08592..f1be7c121a 100644 --- a/src/hooks/dhcp/high_availability/tests/ha_impl_unittest.cc +++ b/src/hooks/dhcp/high_availability/tests/ha_impl_unittest.cc @@ -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."); +} + }