From: Marcin Siodelski Date: Tue, 19 May 2020 13:58:03 +0000 (+0200) Subject: [#1087] HA status enclosed in a list X-Git-Tag: Kea-1.7.8~35 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9aba538d28f9490feb181d5e85ca580639536ff0;p=thirdparty%2Fkea.git [#1087] HA status enclosed in a list The HA specific status information is returned in a list rather than map. This is a preparation for extending HA to support more than one relationship per server. --- diff --git a/src/hooks/dhcp/high_availability/ha_impl.cc b/src/hooks/dhcp/high_availability/ha_impl.cc index d996690f8e..d7b7c45a8e 100644 --- a/src/hooks/dhcp/high_availability/ha_impl.cc +++ b/src/hooks/dhcp/high_availability/ha_impl.cc @@ -281,9 +281,17 @@ HAImpl::commandProcessed(hooks::CalloutHandle& callout_handle) { // Add the ha servers info to arguments. ElementPtr mutable_resp_args = boost::const_pointer_cast(resp_args); + + /// @todo Today we support only one HA relationship per Kea server. + /// In the future there will be more of them. Therefore we enclose + /// our sole relationship in a list. + auto ha_relationships = Element::createList(); + auto ha_relationship = Element::createMap(); ConstElementPtr ha_servers = service_->processStatusGet(); - mutable_resp_args->set("ha-servers", ha_servers); - mutable_resp_args->set("ha-mode", Element::create(HAConfig::HAModeToString(config_->getHAMode()))); + ha_relationship->set("ha-servers", ha_servers); + ha_relationship->set("ha-mode", Element::create(HAConfig::HAModeToString(config_->getHAMode()))); + ha_relationships->add(ha_relationship); + mutable_resp_args->set("high-availability", ha_relationships); } } 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 b2581f4585..38d634af97 100644 --- a/src/hooks/dhcp/high_availability/tests/ha_impl_unittest.cc +++ b/src/hooks/dhcp/high_availability/tests/ha_impl_unittest.cc @@ -573,26 +573,30 @@ TEST_F(HAImplTest, statusGet) { std::string expected = "{" " \"arguments\": {" - " \"ha-mode\": \"load-balancing\"," - " \"ha-servers\": {" - " \"local\": {" - " \"role\": \"primary\"," - " \"scopes\": [ ]," - " \"state\": \"waiting\"" - " }," - " \"remote\": {" - " \"age\": 0," - " \"in-touch\": false," - " \"last-scopes\": [ ]," - " \"last-state\": \"\"," - " \"role\": \"secondary\"," - " \"communication-interrupted\": false," - " \"connecting-clients\": 0," - " \"unacked-clients\": 0," - " \"unacked-clients-left\": 0," - " \"analyzed-packets\": 0" + " \"high-availability\": [" + " {" + " \"ha-mode\": \"load-balancing\"," + " \"ha-servers\": {" + " \"local\": {" + " \"role\": \"primary\"," + " \"scopes\": [ ]," + " \"state\": \"waiting\"" + " }," + " \"remote\": {" + " \"age\": 0," + " \"in-touch\": false," + " \"last-scopes\": [ ]," + " \"last-state\": \"\"," + " \"role\": \"secondary\"," + " \"communication-interrupted\": false," + " \"connecting-clients\": 0," + " \"unacked-clients\": 0," + " \"unacked-clients-left\": 0," + " \"analyzed-packets\": 0" + " }" + " }" " }" - " }," + " ]," " \"pid\": 1" " }," " \"result\": 0" @@ -629,14 +633,18 @@ TEST_F(HAImplTest, statusGetBackupServer) { std::string expected = "{" " \"arguments\": {" - " \"ha-mode\": \"load-balancing\"," - " \"ha-servers\": {" - " \"local\": {" - " \"role\": \"backup\"," - " \"scopes\": [ ]," - " \"state\": \"backup\"" + " \"high-availability\": [" + " {" + " \"ha-mode\": \"load-balancing\"," + " \"ha-servers\": {" + " \"local\": {" + " \"role\": \"backup\"," + " \"scopes\": [ ]," + " \"state\": \"backup\"" + " }" + " }" " }" - " }," + " ]," " \"pid\": 1" " }," " \"result\": 0" @@ -673,14 +681,18 @@ TEST_F(HAImplTest, statusGetPassiveBackup) { std::string expected = "{" " \"arguments\": {" - " \"ha-mode\": \"passive-backup\"," - " \"ha-servers\": {" - " \"local\": {" - " \"role\": \"primary\"," - " \"scopes\": [ \"server1\" ]," - " \"state\": \"passive-backup\"" + " \"high-availability\": [" + " {" + " \"ha-mode\": \"passive-backup\"," + " \"ha-servers\": {" + " \"local\": {" + " \"role\": \"primary\"," + " \"scopes\": [ \"server1\" ]," + " \"state\": \"passive-backup\"" + " }" + " }" " }" - " }," + " ]," " \"pid\": 1" " }," " \"result\": 0"