From: Marcin Siodelski Date: Wed, 11 Jul 2018 16:13:31 +0000 (+0200) Subject: [5675] Implemented ha-continue command handler. X-Git-Tag: ha_phase2~41^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=598e73f9fd445c5752f957708d454ebdf73869c9;p=thirdparty%2Fkea.git [5675] Implemented ha-continue command handler. --- diff --git a/src/hooks/dhcp/high_availability/ha_service.cc b/src/hooks/dhcp/high_availability/ha_service.cc index 62132a2a0f..0f7a608819 100644 --- a/src/hooks/dhcp/high_availability/ha_service.cc +++ b/src/hooks/dhcp/high_availability/ha_service.cc @@ -1384,6 +1384,14 @@ HAService::processScopes(const std::vector& scopes) { return (createAnswer(CONTROL_RESULT_SUCCESS, "New HA scopes configured.")); } +data::ConstElementPtr +HAService::processContinue() { + if (unpause()) { + return (createAnswer(CONTROL_RESULT_SUCCESS, "HA state machine continues.")); + } + return (createAnswer(CONTROL_RESULT_SUCCESS, "HA state machine is not paused.")); +} + ConstElementPtr HAService::verifyAsyncResponse(const HttpResponsePtr& response) { // The response must cast to JSON type. diff --git a/src/hooks/dhcp/high_availability/ha_service.h b/src/hooks/dhcp/high_availability/ha_service.h index 5677904420..40e842f602 100644 --- a/src/hooks/dhcp/high_availability/ha_service.h +++ b/src/hooks/dhcp/high_availability/ha_service.h @@ -610,6 +610,11 @@ public: /// @return Pointer to the response to the ha-scopes command. data::ConstElementPtr processScopes(const std::vector& scopes); + /// @brief Processes ha-continue command and returns a response. + /// + /// @return Pointer to the response to the ha-continue command. + data::ConstElementPtr processContinue(); + protected: /// @brief Checks if the response is valid or contains an error. 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 b5eb35708c..81ca3a3953 100644 --- a/src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc +++ b/src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc @@ -192,6 +192,7 @@ public: using HAService::config_; using HAService::communication_state_; using HAService::query_filter_; + using HAService::state_machine_control_; using HAService::pending_requests_; }; @@ -2320,6 +2321,49 @@ TEST_F(HAServiceTest, processScopes) { EXPECT_FALSE(service.query_filter_.amServingScope("server3")); } +// This test verifies that the ha-continue command is processed successfully. +TEST_F(HAServiceTest, processContinue) { + HAConfigPtr config_storage = createValidConfiguration(); + + // State machine is to be paused in the waiting state. + ASSERT_NO_THROW(config_storage->getStateConfig(HA_WAITING_ST)->setPausing("always")); + + TestHAService service(io_service_, network_state_, config_storage); + + // Pause the state machine. + EXPECT_NO_THROW(service.state_machine_control_.notify(HA_WAITING_ST)); + EXPECT_TRUE(service.state_machine_control_.amPaused()); + + // Process ha-continue command that should unpause the state machine. + ConstElementPtr rsp; + ASSERT_NO_THROW(rsp = service.processContinue()); + + // The server should have responded. + ASSERT_TRUE(rsp); + checkAnswer(rsp, CONTROL_RESULT_SUCCESS, "HA state machine continues."); + + // State machine should have been unpaused as a result of processing the + // command. + EXPECT_FALSE(service.state_machine_control_.amPaused()); + + // Response should include no arguments. + EXPECT_FALSE(rsp->get("arguments")); + + // Sending ha-continue command again which should return success but + // slightly different textual status. + ASSERT_NO_THROW(rsp = service.processContinue()); + + // The server should have responded. + ASSERT_TRUE(rsp); + checkAnswer(rsp, CONTROL_RESULT_SUCCESS, "HA state machine is not paused."); + + // The state machine should not be paused. + EXPECT_FALSE(service.state_machine_control_.amPaused()); + + // Response should include no arguments. + EXPECT_FALSE(rsp->get("arguments")); +} + /// @brief HA partner to the server under test. /// /// This is a wrapper class around @c HttpListener which simulates a