From: Tomek Mrugalski Date: Wed, 21 Jun 2023 11:54:06 +0000 (+0200) Subject: [#2707] config-set in d2 now returns hash X-Git-Tag: Kea-2.4.0~128 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=be438b98ee3209260aa39e51163c1c4364dcfcc3;p=thirdparty%2Fkea.git [#2707] config-set in d2 now returns hash --- diff --git a/src/bin/d2/tests/d2_command_unittest.cc b/src/bin/d2/tests/d2_command_unittest.cc index 5b6c479bd3..8b133b174a 100644 --- a/src/bin/d2/tests/d2_command_unittest.cc +++ b/src/bin/d2/tests/d2_command_unittest.cc @@ -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-/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-/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. diff --git a/src/lib/d2srv/d2_cfg_mgr.cc b/src/lib/d2srv/d2_cfg_mgr.cc index 351b9caa67..5f93a97751 100644 --- a/src/lib/d2srv/d2_cfg_mgr.cc +++ b/src/lib/d2srv/d2_cfg_mgr.cc @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -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);