From: Marcin Siodelski Date: Wed, 18 Jul 2018 11:31:10 +0000 (+0200) Subject: [5674] State machine pausing dealt with in transition. X-Git-Tag: ha_phase2~54^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=327915bc69036c1f30e9322758e3926ccb039bb9;p=thirdparty%2Fkea.git [5674] State machine pausing dealt with in transition. --- diff --git a/src/hooks/dhcp/high_availability/ha_service.cc b/src/hooks/dhcp/high_availability/ha_service.cc index 8546dab1c4..e1257c8bc0 100644 --- a/src/hooks/dhcp/high_availability/ha_service.cc +++ b/src/hooks/dhcp/high_availability/ha_service.cc @@ -55,6 +55,7 @@ HAService::HAService(const IOServicePtr& io_service, const NetworkStatePtr& netw } startModel(HA_WAITING_ST); + state_machine_control_.notify(HA_WAITING_ST); LOG_INFO(ha_logger, HA_SERVICE_STARTED) .arg(HAConfig::HAModeToString(config->getHAMode())) @@ -115,7 +116,6 @@ HAService::backupStateHandler() { if (doOnEntry()) { query_filter_.serveNoScopes(); adjustNetworkState(); - state_machine_control_.notify(getCurrState()); } // There is nothing to do in that state. This server simply receives @@ -131,7 +131,6 @@ HAService::normalStateHandler() { if (doOnEntry()) { query_filter_.serveDefaultScopes(); adjustNetworkState(); - state_machine_control_.notify(getCurrState()); } scheduleHeartbeat(); @@ -187,8 +186,6 @@ HAService::partnerDownStateHandler() { query_filter_.serveDefaultScopes(); } adjustNetworkState(); - - state_machine_control_.notify(getCurrState()); } scheduleHeartbeat(); @@ -234,7 +231,6 @@ HAService::readyStateHandler() { if (doOnEntry()) { query_filter_.serveNoScopes(); adjustNetworkState(); - state_machine_control_.notify(getCurrState()); } scheduleHeartbeat(); @@ -297,7 +293,6 @@ HAService::syncingStateHandler() { if (doOnEntry()) { query_filter_.serveNoScopes(); adjustNetworkState(); - state_machine_control_.notify(getCurrState()); } if (state_machine_control_.amPaused()) { @@ -369,7 +364,6 @@ HAService::terminatedStateHandler() { if (doOnEntry()) { query_filter_.serveDefaultScopes(); adjustNetworkState(); - state_machine_control_.notify(getCurrState()); // In the terminated state we don't send heartbeat. communication_state_->stopHeartbeat(); @@ -388,7 +382,6 @@ HAService::waitingStateHandler() { if (doOnEntry()) { query_filter_.serveNoScopes(); adjustNetworkState(); - state_machine_control_.notify(getCurrState()); } // Only schedule the heartbeat for non-backup servers. @@ -489,6 +482,7 @@ HAService::verboseTransition(const unsigned state) { // Do the actual transition. transition(state, getNextEvent()); + state_machine_control_.notify(state); // Inform the administrator whether or not lease updates are generated. // Updates are never generated by a backup server so it doesn't make diff --git a/src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc b/src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc index 12b7bbd525..829cb746c0 100644 --- a/src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc +++ b/src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc @@ -3559,6 +3559,8 @@ TEST_F(HAServiceStateMachineTest, stateTransitionsLoadBalancingPause) { state_machine->getStateConfig(HA_LOAD_BALANCING_ST)->setPausing("always"); state_machine->getStateConfig(HA_PARTNER_DOWN_ST)->setPausing("always"); state_machine->getStateConfig(HA_READY_ST)->setPausing("always"); + state_machine->getStateConfig(HA_SYNCING_ST)->setPausing("always"); + state_machine->getStateConfig(HA_TERMINATED_ST)->setPausing("always"); state_machine->getStateConfig(HA_WAITING_ST)->setPausing("always"); startService(valid_config); @@ -3619,9 +3621,15 @@ TEST_F(HAServiceStateMachineTest, stateTransitionsLoadBalancingPause) { TEST_F(HAServiceStateMachineTest, syncingTransitionsLoadBalancingPause) { HAConfigPtr valid_config = createValidConfiguration(); - // Pause state machine in syncing state. - auto state_config = valid_config->getStateMachineConfig()->getStateConfig(HA_SYNCING_ST); - state_config->setPausing("always"); + auto state_machine = valid_config->getStateMachineConfig(); + + // Pause state machine in various states. + state_machine->getStateConfig(HA_LOAD_BALANCING_ST)->setPausing("always"); + state_machine->getStateConfig(HA_PARTNER_DOWN_ST)->setPausing("always"); + state_machine->getStateConfig(HA_READY_ST)->setPausing("always"); + state_machine->getStateConfig(HA_SYNCING_ST)->setPausing("always"); + state_machine->getStateConfig(HA_TERMINATED_ST)->setPausing("always"); + state_machine->getStateConfig(HA_WAITING_ST)->setPausing("always"); startService(valid_config); waitForEvent(HAService::HA_HEARTBEAT_COMPLETE_EVT);