]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2707] config-set in d2 now returns hash
authorTomek Mrugalski <tomek@isc.org>
Wed, 21 Jun 2023 11:54:06 +0000 (13:54 +0200)
committerTomek Mrugalski <tomek@isc.org>
Thu, 22 Jun 2023 14:23:38 +0000 (16:23 +0200)
src/bin/d2/tests/d2_command_unittest.cc
src/lib/d2srv/d2_cfg_mgr.cc

index 5b6c479bd322d8d9d7019217bb32050153394011..8b133b174ae3d3f0702e2a299077c9c4930aa527 100644 (file)
@@ -794,8 +794,13 @@ TEST_F(CtrlChannelD2Test, configTest) {
     ASSERT_TRUE(proc);
     ConstElementPtr answer = proc->configure(config, false);
     ASSERT_TRUE(answer);
-    EXPECT_EQ("{ \"result\": 0, \"text\": \"Configuration applied successfully.\" }",
-              answer->str());
+    // 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(answer->str().find("\"result\": 0"), std::string::npos);
+    EXPECT_NE(answer->str().find("\"text\": \"Configuration applied successfully.\""), std::string::npos);
     ASSERT_NO_THROW(d2Controller()->registerCommands());
 
     // Check that the config was indeed applied.
@@ -927,8 +932,14 @@ TEST_F(CtrlChannelD2Test, configSet) {
     ASSERT_TRUE(proc);
     ConstElementPtr answer = proc->configure(config, false);
     ASSERT_TRUE(answer);
-    EXPECT_EQ("{ \"result\": 0, \"text\": \"Configuration applied successfully.\" }",
-              answer->str());
+    // 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(answer->str().find("\"result\": 0"), std::string::npos);
+    EXPECT_NE(answer->str().find("\"text\": \"Configuration applied successfully.\""),
+              std::string::npos);
     ASSERT_NO_THROW(d2Controller()->registerCommands());
 
     // Check that the config was indeed applied.
@@ -993,7 +1004,8 @@ TEST_F(CtrlChannelD2Test, configSet) {
     EXPECT_FALSE(test::fileExists(socket_path_));
 
     // Verify the configuration was successful.
-    EXPECT_EQ("{ \"result\": 0, \"text\": \"Configuration applied successfully.\" }",
+    EXPECT_EQ("{ \"arguments\": { \"hash\": \"5206A1BEC7E3C6ADD5E97C5983861F97739EA05CFEAD823CBBC4"
+              "524095AAA10A\" }, \"result\": 0, \"text\": \"Configuration applied successfully.\" }",
               response);
 
     // Check that the config was applied.
@@ -1111,8 +1123,9 @@ TEST_F(CtrlChannelD2Test, configReloadFileValid) {
     sendUnixCommand("{ \"command\": \"config-reload\" }", response);
 
     // Verify the reload was successful.
-    string expected = "{ \"result\": 0, \"text\": "
-        "\"Configuration applied successfully.\" }";
+    string expected = "{ \"arguments\": { \"hash\": \"DC1235F1948D68E06F1425FC28BE326EF01DC4856C3"
+                      "833673B9CC8732409B04D\" }, \"result\": 0, \"text\": "
+                      "\"Configuration applied successfully.\" }";
     EXPECT_EQ(expected, response);
 
     // Check that the config was indeed applied.
index 351b9caa67accdf7e4b02da903ae0d5ed3a85b51..5f93a977515f0df2ac1846da0555eaf609b10ec6 100644 (file)
@@ -10,6 +10,7 @@
 #include <d2srv/d2_cfg_mgr.h>
 #include <d2srv/d2_simple_parser.h>
 #include <cc/command_interpreter.h>
+#include <config/base_command_mgr.h>
 #include <util/encode/hex.h>
 
 #include <boost/foreach.hpp>
@@ -306,8 +307,15 @@ D2CfgMgr::parse(isc::data::ConstElementPtr config_set, bool check_only) {
         answer = createAnswer(CONTROL_RESULT_SUCCESS,
                               "Configuration check successful");
     } else {
+
+        // Calculate hash of the configuration that was just set.
+        ElementPtr config = getContext()->toElement();
+        std::string hash = BaseCommandMgr::getHash(config);
+        ElementPtr params = Element::createMap();
+        params->set("hash", Element::create(hash));
+
         answer = createAnswer(CONTROL_RESULT_SUCCESS,
-                              "Configuration applied successfully.");
+                              "Configuration applied successfully.", params);
     }
 
     return (answer);