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

index 62132a2a0f71384919151d39f685f31ebf0dea26..0f7a608819eaba7d9c70899776c210aad181375f 100644 (file)
@@ -1384,6 +1384,14 @@ HAService::processScopes(const std::vector<std::string>& 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.
index 56779044200ed745bed7f14c722d7f043362b7e5..40e842f6021d6825d9496ef1e37af99aa571da53 100644 (file)
@@ -610,6 +610,11 @@ public:
     /// @return Pointer to the response to the ha-scopes command.
     data::ConstElementPtr processScopes(const std::vector<std::string>& 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.
index b5eb35708c7ee71423f3af3c747a9f1e34e9c4c4..81ca3a39533578b44d8479560629a8382de34fb8 100644 (file)
@@ -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