]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1402] Do not reset HA in waiting state
authorMarcin Siodelski <marcin@isc.org>
Thu, 14 Jan 2021 19:22:14 +0000 (20:22 +0100)
committerMarcin Siodelski <marcin@isc.org>
Thu, 14 Jan 2021 19:24:03 +0000 (20:24 +0100)
doc/sphinx/arm/hooks-ha.rst
src/hooks/dhcp/high_availability/ha_service.cc
src/hooks/dhcp/high_availability/tests/ha_impl_unittest.cc
src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc

index e0d3dbeb5b1ab8e1a0c3bb712b5005496872c5bb..691d51846af88a01208e4aa41feb7b3046d6d4ca 100644 (file)
@@ -1946,3 +1946,6 @@ The response:
        "result": 0,
        "text": "HA state machine reset."
    }
+
+If the server receiving this command is already in the waiting state,
+the command has no effect.
index dca4280316d410e19086ffe2faeeee43cf241c6f..5ecdd33ac4594c9c11fcacd8c61c6f7f4c5a6f29 100644 (file)
@@ -1527,6 +1527,9 @@ HAService::processHeartbeat() {
 
 ConstElementPtr
 HAService::processHAReset() {
+    if (getCurrState() == HA_WAITING_ST) {
+        return (createAnswer(CONTROL_RESULT_SUCCESS, "HA state machine already in WAITING state."));
+    }
     verboseTransition(HA_WAITING_ST);
     runModel(NOP_EVT);
     return (createAnswer(CONTROL_RESULT_SUCCESS, "HA state machine reset."));
index 900c39df373ad4bc457d6599d9854c9650e96f23..f7e75a870a89c3431ce52df9087b06ee19d141f3 100644 (file)
@@ -756,7 +756,7 @@ TEST_F(HAImplTest, haReset) {
     callout_handle->getArgument("response", response);
     ASSERT_TRUE(response);
 
-    checkAnswer(response, CONTROL_RESULT_SUCCESS, "HA state machine reset.");
+    checkAnswer(response, CONTROL_RESULT_SUCCESS, "HA state machine already in WAITING state.");
 }
 
 }
index 7fc8fef68fc0773a38471094ff63fe6e43e4771f..5c64ab6410ca9f0a86ac9c728bf0e47219c4f0f0 100644 (file)
@@ -4585,6 +4585,32 @@ TEST_F(HAServiceTest, processHAReset) {
     EXPECT_EQ(HA_WAITING_ST, service.getCurrState());
 }
 
+// This test verifies that the ha-reset command is processed successfully when
+// the server is already in the waiting state.
+TEST_F(HAServiceTest, processHAResetWaiting) {
+    HAConfigPtr config_storage = createValidConfiguration();
+    TestHAService service(io_service_, network_state_, config_storage);
+
+    // Transion the server to the load-balancing state.
+    EXPECT_NO_THROW(service.transition(HA_WAITING_ST, HAService::NOP_EVT));
+
+    // Process ha-reset command that should not change the state of the
+    // server because the server is already in the waiting state. It
+    // should not fail though.
+    ConstElementPtr rsp;
+    ASSERT_NO_THROW(rsp = service.processHAReset());
+
+    // The server should have responded.
+    ASSERT_TRUE(rsp);
+    checkAnswer(rsp, CONTROL_RESULT_SUCCESS, "HA state machine already in WAITING state.");
+
+    // Response should include no arguments.
+    EXPECT_FALSE(rsp->get("arguments"));
+
+    // The server should be in the waiting state.
+    EXPECT_EQ(HA_WAITING_ST, service.getCurrState());
+}
+
 /// @brief HA partner to the server under test.
 ///
 /// This is a wrapper class around @c HttpListener which simulates a