summaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorRazvan Becheriu <razvan@isc.org>2023-02-26 16:23:40 +0100
committerRazvan Becheriu <razvan@isc.org>2023-03-16 20:26:11 +0100
commitdb352cc04cf99e5b877d02f87eaa8dbe2bc82f10 (patch)
treef711d6316cebe9b2e0c37bd46ecf7efea0488c6f /src/lib
parent[#2722] always perform config check before config set (diff)
downloadkea-db352cc04cf99e5b877d02f87eaa8dbe2bc82f10.tar.xz
kea-db352cc04cf99e5b877d02f87eaa8dbe2bc82f10.zip
[#2722] config set follows the same path as config test and can rollback
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/cc/command_interpreter.cc2
-rw-r--r--src/lib/cc/tests/command_interpreter_unittests.cc8
-rw-r--r--src/lib/config/hooked_command_mgr.cc2
-rw-r--r--src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc8
-rw-r--r--src/lib/process/d_cfg_mgr.cc9
-rw-r--r--src/lib/process/testutils/d_test_stubs.cc10
6 files changed, 21 insertions, 18 deletions
diff --git a/src/lib/cc/command_interpreter.cc b/src/lib/cc/command_interpreter.cc
index 68f880cfc1..c3c2a7a233 100644
--- a/src/lib/cc/command_interpreter.cc
+++ b/src/lib/cc/command_interpreter.cc
@@ -52,7 +52,7 @@ createAnswer(const int status_code, const std::string& text,
ConstElementPtr
createAnswer() {
- return (createAnswer(0, string(""), ConstElementPtr()));
+ return (createAnswer(CONTROL_RESULT_SUCCESS, string(""), ConstElementPtr()));
}
ConstElementPtr
diff --git a/src/lib/cc/tests/command_interpreter_unittests.cc b/src/lib/cc/tests/command_interpreter_unittests.cc
index 12b3eab658..e393eeb473 100644
--- a/src/lib/cc/tests/command_interpreter_unittests.cc
+++ b/src/lib/cc/tests/command_interpreter_unittests.cc
@@ -42,17 +42,17 @@ TEST(CommandInterpreterTest, createAnswer) {
EXPECT_EQ("{ \"result\": 0 }", answer->str());
// Let's check if we can generate an error.
- answer = createAnswer(1, "error");
+ answer = createAnswer(CONTROL_RESULT_ERROR, "error");
EXPECT_EQ("{ \"result\": 1, \"text\": \"error\" }", answer->str());
// This is expected to throw. When status code is non-zero (indicating error),
// textual explanation is mandatory.
- EXPECT_THROW(createAnswer(1, ElementPtr()), CtrlChannelError);
- EXPECT_THROW(createAnswer(1, Element::create(1)), CtrlChannelError);
+ EXPECT_THROW(createAnswer(CONTROL_RESULT_ERROR, ElementPtr()), CtrlChannelError);
+ EXPECT_THROW(createAnswer(CONTROL_RESULT_ERROR, Element::create(1)), CtrlChannelError);
// Let's check if answer can be generate with some data in it.
ConstElementPtr arg = el("[ \"just\", \"some\", \"data\" ]");
- answer = createAnswer(0, arg);
+ answer = createAnswer(CONTROL_RESULT_SUCCESS, arg);
EXPECT_EQ("{ \"arguments\": [ \"just\", \"some\", \"data\" ], \"result\": 0 }",
answer->str());
}
diff --git a/src/lib/config/hooked_command_mgr.cc b/src/lib/config/hooked_command_mgr.cc
index 3562e71ff3..8ec31c75f4 100644
--- a/src/lib/config/hooked_command_mgr.cc
+++ b/src/lib/config/hooked_command_mgr.cc
@@ -120,7 +120,7 @@ HookedCommandMgr::handleCommand(const std::string& cmd_name,
// registered
// for it, combine the lists of commands.
if (!hooks_commands->empty()) {
- response = combineCommandsLists(response, createAnswer(0, hooks_commands));
+ response = combineCommandsLists(response, createAnswer(CONTROL_RESULT_SUCCESS, hooks_commands));
}
}
}
diff --git a/src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc b/src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc
index 038314500f..2f052804f1 100644
--- a/src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc
+++ b/src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc
@@ -191,7 +191,7 @@ public:
// Answer will hold the result.
ConstElementPtr answer;
if (!config_set) {
- answer = isc::config::createAnswer(1,
+ answer = isc::config::createAnswer(CONTROL_RESULT_ERROR,
string("Can't parse NULL config"));
return (answer);
}
@@ -302,13 +302,13 @@ public:
}
// Everything was fine. Configuration is successful.
- answer = isc::config::createAnswer(0, "Configuration committed.");
+ answer = isc::config::createAnswer(CONTROL_RESULT_SUCCESS, "Configuration committed.");
} catch (const isc::Exception& ex) {
- answer = isc::config::createAnswer(1,
+ answer = isc::config::createAnswer(CONTROL_RESULT_ERROR,
string("Configuration parsing failed: ") + ex.what());
} catch (...) {
- answer = isc::config::createAnswer(1,
+ answer = isc::config::createAnswer(CONTROL_RESULT_ERROR,
string("Configuration parsing failed"));
}
diff --git a/src/lib/process/d_cfg_mgr.cc b/src/lib/process/d_cfg_mgr.cc
index 4a67183128..5ee15ec7fb 100644
--- a/src/lib/process/d_cfg_mgr.cc
+++ b/src/lib/process/d_cfg_mgr.cc
@@ -26,6 +26,7 @@
using namespace std;
using namespace isc;
+using namespace isc::config;
using namespace isc::dhcp;
using namespace isc::data;
using namespace isc::asiolink;
@@ -76,8 +77,8 @@ DCfgMgrBase::simpleParseConfig(isc::data::ConstElementPtr config_set,
bool check_only,
const std::function<void()>& post_config_cb) {
if (!config_set) {
- return (isc::config::createAnswer(1,
- std::string("Can't parse NULL config")));
+ return (isc::config::createAnswer(CONTROL_RESULT_ERROR,
+ std::string("Can't parse NULL config")));
}
LOG_DEBUG(dctl_logger, isc::log::DBGLVL_COMMAND, DCTL_CONFIG_START)
.arg(redactConfig(config_set)->str());
@@ -122,7 +123,7 @@ DCfgMgrBase::simpleParseConfig(isc::data::ConstElementPtr config_set,
}
// Use the answer provided.
- //answer = isc::config::createAnswer(0, "Configuration committed.");
+ //answer = isc::config::createAnswer(CONTROL_RESULT_SUCCESS, "Configuration committed.");
} else {
LOG_INFO(dctl_logger, DCTL_CONFIG_CHECK_COMPLETE)
.arg(getConfigSummary(0))
@@ -131,7 +132,7 @@ DCfgMgrBase::simpleParseConfig(isc::data::ConstElementPtr config_set,
} catch (const std::exception& ex) {
LOG_ERROR(dctl_logger, DCTL_PARSER_FAIL).arg(ex.what());
- answer = isc::config::createAnswer(1, ex.what());
+ answer = isc::config::createAnswer(CONTROL_RESULT_ERROR, ex.what());
rollback = true;
}
diff --git a/src/lib/process/testutils/d_test_stubs.cc b/src/lib/process/testutils/d_test_stubs.cc
index 1186729e06..78b73d6ecf 100644
--- a/src/lib/process/testutils/d_test_stubs.cc
+++ b/src/lib/process/testutils/d_test_stubs.cc
@@ -61,15 +61,16 @@ DStubProcess::shutdown(isc::data::ConstElementPtr /* args */) {
setShutdownFlag(true);
stopIOService();
- return (isc::config::createAnswer(0, "Shutdown initiated."));
+ return (isc::config::createAnswer(isc::config::CONTROL_RESULT_SUCCESS,
+ "Shutdown initiated."));
}
isc::data::ConstElementPtr
DStubProcess::configure(isc::data::ConstElementPtr config_set, bool check_only) {
if (SimFailure::shouldFailOn(SimFailure::ftProcessConfigure)) {
// Simulates a process configure failure.
- return (isc::config::createAnswer(1,
- "Simulated process configuration error."));
+ return (isc::config::createAnswer(isc::config::CONTROL_RESULT_ERROR,
+ "Simulated process configuration error."));
}
return (getCfgMgr()->simpleParseConfig(config_set, check_only));
@@ -329,7 +330,8 @@ DStubCfgMgr::createNewContext() {
isc::data::ConstElementPtr
DStubCfgMgr::parse(isc::data::ConstElementPtr /*config*/, bool /*check_only*/) {
- return (isc::config::createAnswer(0, "It all went fine. I promise"));
+ return (isc::config::createAnswer(isc::config::CONTROL_RESULT_SUCCESS,
+ "It all went fine. I promise"));
}
} // namespace isc::process