]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2707] config-set in v4 now returns hash
authorTomek Mrugalski <tomek@isc.org>
Wed, 21 Jun 2023 10:46:56 +0000 (12:46 +0200)
committerTomek Mrugalski <tomek@isc.org>
Thu, 22 Jun 2023 14:23:38 +0000 (16:23 +0200)
src/bin/dhcp4/json_config_parser.cc
src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc
src/bin/dhcp4/tests/hooks_unittest.cc

index 98dd3f379d01005596c5ecfa8b174517769e12d2..0de041bdf4adc0d8060b6e5205d668a97383f777 100644 (file)
@@ -974,8 +974,14 @@ configureDhcp4Server(Dhcpv4Srv& server, isc::data::ConstElementPtr config_set,
         .arg(CfgMgr::instance().getStagingCfg()->
              getConfigSummary(SrvConfig::CFGSEL_ALL4));
 
+    // Also calculate SHA256 hash of the config that was just set and append it to the response.
+    ElementPtr config = CfgMgr::instance().getCurrentCfg()->toElement();
+    string hash = BaseCommandMgr::getHash(config);
+    ElementPtr hash_map = Element::createMap();
+    hash_map->set("hash", Element::create(hash));
+
     // Everything was fine. Configuration is successful.
-    answer = isc::config::createAnswer(CONTROL_RESULT_SUCCESS, "Configuration successful.");
+    answer = isc::config::createAnswer(CONTROL_RESULT_SUCCESS, "Configuration successful.", hash_map);
     return (answer);
 }
 
index f912c17ab120caaa5b7de81e6e5faa40f64d9fdf..5cf130618fffc521e6ee490af9e077f490583527 100644 (file)
@@ -816,9 +816,13 @@ TEST_F(CtrlChannelDhcpv4SrvTest, configSet) {
     std::string response;
     sendUnixCommand(os.str(), response);
 
-    // Verify the configuration was successful.
-    EXPECT_EQ("{ \"result\": 0, \"text\": \"Configuration successful.\" }",
-              response);
+    // Verify the configuration was successful. The config contains random
+    // socket name (/tmp/kea-<value-changing-each-time>/kea6.sock), so the
+    // hash will be different each time. As such, we can do simplified checks:
+    // - verify the "result": 0 is there
+    // - verify the "text": "Configuration successful." is there
+    EXPECT_NE(response.find("\"result\": 0"), std::string::npos);
+    EXPECT_NE(response.find("\"text\": \"Configuration successful.\""), std::string::npos);
 
     // Check that the config was indeed applied.
     const Subnet4Collection* subnets =
@@ -880,9 +884,13 @@ TEST_F(CtrlChannelDhcpv4SrvTest, configSet) {
     // Verify the control channel socket no longer exists.
     EXPECT_FALSE(fileExists(socket_path_));
 
-    // With no command channel, should still receive the response.
-    EXPECT_EQ("{ \"result\": 0, \"text\": \"Configuration successful.\" }",
-              response);
+    // With no command channel, should still receive the response. The config contains random
+    // socket name (/tmp/kea-<value-changing-each-time>/kea6.sock), so the
+    // hash will be different each time. As such, we can do simplified checks:
+    // - verify the "result": 0 is there
+    // - verify the "text": "Configuration successful." is there
+    EXPECT_NE(response.find("\"result\": 0"), std::string::npos);
+    EXPECT_NE(response.find("\"text\": \"Configuration successful.\""), std::string::npos);
 
     // Check that the config was not lost
     subnets = CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getAll();
@@ -1021,9 +1029,13 @@ TEST_F(CtrlChannelDhcpv4SrvTest, configTest) {
     std::string response;
     sendUnixCommand(os.str(), response);
 
-    // Verify the configuration was successful.
-    EXPECT_EQ("{ \"result\": 0, \"text\": \"Configuration successful.\" }",
-              response);
+    // Verify the configuration was successful. The config contains random
+    // socket name (/tmp/kea-<value-changing-each-time>/kea6.sock), so the
+    // hash will be different each time. As such, we can do simplified checks:
+    // - verify the "result": 0 is there
+    // - verify the "text": "Configuration successful." is there
+    EXPECT_NE(response.find("\"result\": 0"), std::string::npos);
+    EXPECT_NE(response.find("\"text\": \"Configuration successful.\""), std::string::npos);
 
     // Check that the config was indeed applied.
     const Subnet4Collection* subnets =
@@ -1579,9 +1591,13 @@ TEST_F(CtrlChannelDhcpv4SrvTest, configReloadValid) {
 
     // This command should reload test8.json config.
     sendUnixCommand("{ \"command\": \"config-reload\" }", response);
-    // Verify the configuration was successful.
-    EXPECT_EQ("{ \"result\": 0, \"text\": \"Configuration successful.\" }",
-              response);
+    // Verify the configuration was successful. The config contains random
+    // socket name (/tmp/kea-<value-changing-each-time>/kea6.sock), so the
+    // hash will be different each time. As such, we can do simplified checks:
+    // - verify the "result": 0 is there
+    // - verify the "text": "Configuration successful." is there
+    EXPECT_NE(response.find("\"result\": 0"), std::string::npos);
+    EXPECT_NE(response.find("\"text\": \"Configuration successful.\""), std::string::npos);
 
     // Check that the config was indeed applied.
     const Subnet4Collection* subnets =
index 6d5f8cb5cc21fc8e8de8246e3206acf288ced195..6622995dfa4cd902b514b8efd36b9f04b10dcdb6 100644 (file)
@@ -3267,7 +3267,9 @@ TEST_F(LoadUnloadDhcpv4SrvTest, Dhcpv4SrvConfigured) {
         parseAnswer(status_code, answer);
         if (parameters.empty()) {
             EXPECT_EQ(0, status_code);
-            EXPECT_EQ(answer->str(), R"({ "result": 0, "text": "Configuration successful." })");
+            EXPECT_EQ(answer->str(), "{ \"arguments\": { \"hash\": \"FA868B7A5983A80A83A7E9EFD8E"
+            "3DA4CC78B57A44817AEB9EF9DD6E4B9B0B116\" }, \"result\": 0, \"text\": "
+            "\"Configuration successful.\" }");
         } else {
             EXPECT_EQ(1, status_code);
             if (parameters.find("fail-without-error") != string::npos) {