summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcin Siodelski <marcin@isc.org>2023-12-18 13:49:30 +0100
committerMarcin Siodelski <marcin@isc.org>2024-01-05 19:04:19 +0100
commited064ccc772e0f5999f0672ab537b40fdb80b13a (patch)
treea4dce1bbb32d1c86ec553d7da22a4c8871bb0c6c
parent[#3178] Different CS callback names (diff)
downloadkea-ed064ccc772e0f5999f0672ab537b40fdb80b13a.tar.xz
kea-ed064ccc772e0f5999f0672ab537b40fdb80b13a.zip
[#3178] Added status-get test for H&S
-rw-r--r--src/hooks/dhcp/high_availability/tests/ha_impl_unittest.cc82
1 files changed, 82 insertions, 0 deletions
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 8885dae142..5a7576fcce 100644
--- a/src/hooks/dhcp/high_availability/tests/ha_impl_unittest.cc
+++ b/src/hooks/dhcp/high_availability/tests/ha_impl_unittest.cc
@@ -1721,6 +1721,88 @@ TEST_F(HAImplTest, statusGetPassiveBackup) {
EXPECT_TRUE(isEquivalent(got, Element::fromJSON(expected)));
}
+// Tests status-get command processed handler for standby server in the
+// hub-and-spoke mode.
+TEST_F(HAImplTest, statusGetHubAndSpoke) {
+ TestHAImpl ha_impl;
+ ASSERT_NO_THROW(ha_impl.configure(createValidHubJsonConfiguration()));
+
+ // Starting the service is required prior to running any callouts.
+ NetworkStatePtr network_state(new NetworkState(NetworkState::DHCPv4));
+ ASSERT_NO_THROW(ha_impl.startServices(io_service_, network_state,
+ HAServerType::DHCPv4));
+
+ std::string name = "status-get";
+ ConstElementPtr response =
+ Element::fromJSON("{ \"arguments\": { \"pid\": 1 }, \"result\": 0 }");
+
+ CalloutHandlePtr callout_handle = HooksManager::createCalloutHandle();
+
+ callout_handle->setArgument("name", name);
+ callout_handle->setArgument("response", response);
+
+ ASSERT_NO_THROW(ha_impl.commandProcessed(*callout_handle));
+
+ ConstElementPtr got;
+ callout_handle->getArgument("response", got);
+ ASSERT_TRUE(got);
+
+ std::string expected =
+ "{"
+ " \"arguments\": {"
+ " \"high-availability\": ["
+ " {"
+ " \"ha-mode\": \"hot-standby\","
+ " \"ha-servers\": {"
+ " \"local\": {"
+ " \"role\": \"standby\","
+ " \"scopes\": [ ],"
+ " \"state\": \"waiting\""
+ " },"
+ " \"remote\": {"
+ " \"age\": 0,"
+ " \"analyzed-packets\": 0,"
+ " \"communication-interrupted\": false,"
+ " \"connecting-clients\": 0,"
+ " \"in-touch\": false,"
+ " \"last-scopes\": [ ],"
+ " \"last-state\": \"\","
+ " \"role\": \"primary\","
+ " \"unacked-clients\": 0,"
+ " \"unacked-clients-left\": 0"
+ " }"
+ " }"
+ " },"
+ " {"
+ " \"ha-mode\": \"hot-standby\","
+ " \"ha-servers\": {"
+ " \"local\": {"
+ " \"role\": \"standby\","
+ " \"scopes\": [ ],"
+ " \"state\": \"waiting\""
+ " },"
+ " \"remote\": {"
+ " \"age\": 0,"
+ " \"analyzed-packets\": 0,"
+ " \"communication-interrupted\": false,"
+ " \"connecting-clients\": 0,"
+ " \"in-touch\": false,"
+ " \"last-scopes\": [ ],"
+ " \"last-state\": \"\","
+ " \"role\": \"primary\","
+ " \"unacked-clients\": 0,"
+ " \"unacked-clients-left\": 0"
+ " }"
+ " }"
+ " }"
+ " ],"
+ " \"pid\": 1"
+ " },"
+ " \"result\": 0"
+ "}";
+ EXPECT_TRUE(isEquivalent(got, Element::fromJSON(expected)));
+}
+
// Test ha-maintenance-notify command handler with server name.
TEST_F(HAImplTest, maintenanceNotify) {
HAImpl ha_impl;