From c48734c20e47355cc4b81d9316a582566eaa608b Mon Sep 17 00:00:00 2001 From: Marcin Siodelski Date: Fri, 5 Jan 2024 17:25:04 +0100 Subject: [PATCH] [#3178] Include server-name in status-get --- doc/sphinx/arm/hooks-ha.rst | 6 ++++-- src/hooks/dhcp/high_availability/ha_service.cc | 2 ++ .../dhcp/high_availability/tests/ha_impl_unittest.cc | 8 ++++++++ .../dhcp/high_availability/tests/ha_service_unittest.cc | 6 ++++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/doc/sphinx/arm/hooks-ha.rst b/doc/sphinx/arm/hooks-ha.rst index 155e0f64d0..983a39f370 100644 --- a/doc/sphinx/arm/hooks-ha.rst +++ b/doc/sphinx/arm/hooks-ha.rst @@ -2172,7 +2172,8 @@ the HA status of two ``load-balancing`` servers: "local": { "role": "primary", "scopes": [ "server1" ], - "state": "load-balancing" + "state": "load-balancing", + "server-name": "server1" }, "remote": { "age": 10, @@ -2184,7 +2185,8 @@ the HA status of two ``load-balancing`` servers: "connecting-clients": 2, "unacked-clients": 1, "unacked-clients-left": 2, - "analyzed-packets": 8 + "analyzed-packets": 8, + "server-name": "server2" } } } diff --git a/src/hooks/dhcp/high_availability/ha_service.cc b/src/hooks/dhcp/high_availability/ha_service.cc index 58f798b687..55c0bed647 100644 --- a/src/hooks/dhcp/high_availability/ha_service.cc +++ b/src/hooks/dhcp/high_availability/ha_service.cc @@ -1662,6 +1662,7 @@ HAService::processStatusGet() const { list->add(Element::create(scope)); } local->set("scopes", list); + local->set("server-name", Element::create(config_->getThisServerName())); ha_servers->set("local", local); // Do not include remote server information if this is a backup server or @@ -1682,6 +1683,7 @@ HAService::processStatusGet() const { } catch (...) { remote->set("role", Element::create(std::string())); } + remote->set("server-name", Element::create(config_->getFailoverPeerConfig()->getName())); ha_servers->set("remote", remote); return (ha_servers); 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 e61664ce1a..d3c5dbff14 100644 --- a/src/hooks/dhcp/high_availability/tests/ha_impl_unittest.cc +++ b/src/hooks/dhcp/high_availability/tests/ha_impl_unittest.cc @@ -1683,9 +1683,11 @@ TEST_F(HAImplTest, statusGet) { " \"local\": {" " \"role\": \"primary\"," " \"scopes\": [ ]," + " \"server-name\": \"server1\"," " \"state\": \"waiting\"" " }," " \"remote\": {" + " \"server-name\": \"server2\"," " \"age\": 0," " \"in-touch\": false," " \"last-scopes\": [ ]," @@ -1743,6 +1745,7 @@ TEST_F(HAImplTest, statusGetBackupServer) { " \"local\": {" " \"role\": \"backup\"," " \"scopes\": [ ]," + " \"server-name\": \"server3\"," " \"state\": \"backup\"" " }" " }" @@ -1791,6 +1794,7 @@ TEST_F(HAImplTest, statusGetPassiveBackup) { " \"local\": {" " \"role\": \"primary\"," " \"scopes\": [ \"server1\" ]," + " \"server-name\": \"server1\"," " \"state\": \"passive-backup\"" " }" " }" @@ -1839,6 +1843,7 @@ TEST_F(HAImplTest, statusGetHubAndSpoke) { " \"local\": {" " \"role\": \"standby\"," " \"scopes\": [ ]," + " \"server-name\": \"server2\"," " \"state\": \"waiting\"" " }," " \"remote\": {" @@ -1850,6 +1855,7 @@ TEST_F(HAImplTest, statusGetHubAndSpoke) { " \"last-scopes\": [ ]," " \"last-state\": \"\"," " \"role\": \"primary\"," + " \"server-name\": \"server1\"," " \"unacked-clients\": 0," " \"unacked-clients-left\": 0" " }" @@ -1861,6 +1867,7 @@ TEST_F(HAImplTest, statusGetHubAndSpoke) { " \"local\": {" " \"role\": \"standby\"," " \"scopes\": [ ]," + " \"server-name\": \"server4\"," " \"state\": \"waiting\"" " }," " \"remote\": {" @@ -1872,6 +1879,7 @@ TEST_F(HAImplTest, statusGetHubAndSpoke) { " \"last-scopes\": [ ]," " \"last-state\": \"\"," " \"role\": \"primary\"," + " \"server-name\": \"server3\"," " \"unacked-clients\": 0," " \"unacked-clients-left\": 0" " }" 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 921ca2de1d..4c4639d4fa 100644 --- a/src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc +++ b/src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc @@ -2391,9 +2391,11 @@ TEST_F(HAServiceTest, hotStandbyScopeSelectionThisPrimary) { " \"local\": {" " \"role\": \"primary\"," " \"scopes\": [ \"server1\" ]," + " \"server-name\": \"server1\"," " \"state\": \"hot-standby\"" " }, " " \"remote\": {" + " \"server-name\": \"server2\"," " \"age\": 0," " \"in-touch\": false," " \"role\": \"standby\"," @@ -2440,9 +2442,11 @@ TEST_F(HAServiceTest, hotStandbyScopeSelectionThisStandby) { " \"local\": {" " \"role\": \"standby\"," " \"scopes\": [ ]," + " \"server-name\": \"server2\"," " \"state\": \"waiting\"" " }, " " \"remote\": {" + " \"server-name\": \"server1\"," " \"age\": 0," " \"in-touch\": false," " \"role\": \"primary\"," @@ -6054,9 +6058,11 @@ TEST_F(HAServiceStateMachineTest, waitingParterDownLoadBalancingPartnerDown) { " \"local\": {" " \"role\": \"primary\"," " \"scopes\": [ \"server1\" ], " + " \"server-name\": \"server1\"," " \"state\": \"load-balancing\"" " }, " " \"remote\": {" + " \"server-name\": \"server2\"," " \"age\": " + s.str() + "," " \"in-touch\": true," " \"role\": \"secondary\","