]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1087] HA status enclosed in a list
authorMarcin Siodelski <marcin@isc.org>
Tue, 19 May 2020 13:58:03 +0000 (15:58 +0200)
committerMarcin Siodelski <marcin@isc.org>
Wed, 20 May 2020 15:49:11 +0000 (17:49 +0200)
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.

src/hooks/dhcp/high_availability/ha_impl.cc
src/hooks/dhcp/high_availability/tests/ha_impl_unittest.cc

index d996690f8e41a04ade7d1255496e8095d507faad..d7b7c45a8e8c241bc4bd6cac11b577376a1a8b99 100644 (file)
@@ -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<Element>(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);
     }
 }
 
index b2581f4585fecef1656fb5271e7ba8c4267c6cbd..38d634af97e7658c53de035bdba6c440bc0d5b57 100644 (file)
@@ -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"