2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-29 13:07:50 +00:00

[#2707] config-set in v4 now returns hash

This commit is contained in:
Tomek Mrugalski 2023-06-21 12:46:56 +02:00
parent db6ec11cc1
commit abe38a4e5c
No known key found for this signature in database
GPG Key ID: 5F418202F1F80482
3 changed files with 38 additions and 14 deletions

View 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);
}

View 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 =

View 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) {