Skip to content

Commit 66eacf5

Browse files
author
Razvan Becheriu
committed
[#2960] removed more code
1 parent f4a474c commit 66eacf5

14 files changed

+42
-160
lines changed

src/bin/dhcp4/ctrl_dhcp4_srv.cc

Lines changed: 16 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,14 @@ CtrlDhcp4Hooks Hooks;
7575
///
7676
/// @param signo Signal number received.
7777
void signalHandler(int signo) {
78-
// SIGHUP signals a request to reconfigure the server.
79-
if (signo == SIGHUP) {
80-
ControlledDhcpv4Srv::processCommand("config-reload",
81-
ConstElementPtr());
82-
} else if ((signo == SIGTERM) || (signo == SIGINT)) {
83-
ControlledDhcpv4Srv::processCommand("shutdown",
84-
ConstElementPtr());
78+
try {
79+
// SIGHUP signals a request to reconfigure the server.
80+
if (signo == SIGHUP) {
81+
CommandMgr::instance().processCommand(createCommand("config-reload"));
82+
} else if ((signo == SIGTERM) || (signo == SIGINT)) {
83+
CommandMgr::instance().processCommand(createCommand("shutdown"));
84+
}
85+
} catch (const isc::Exception& ex) {
8586
}
8687
}
8788

@@ -108,10 +109,6 @@ ControlledDhcpv4Srv::init(const std::string& file_name) {
108109
isc_throw(isc::BadValue, reason);
109110
}
110111

111-
// We don't need to call openActiveSockets() or startD2() as these
112-
// methods are called in processConfig() which is called by
113-
// processCommand("config-set", ...)
114-
115112
// Set signal handlers. When the SIGHUP is received by the process
116113
// the server reconfiguration will be triggered. When SIGTERM or
117114
// SIGINT will be received, the server will start shutting down.
@@ -162,13 +159,19 @@ ControlledDhcpv4Srv::loadConfigFile(const std::string& file_name) {
162159
}
163160

164161
// Use parsed JSON structures to configure the server
165-
result = ControlledDhcpv4Srv::processCommand("config-set", json);
162+
try {
163+
result = CommandMgr::instance().processCommand(createCommand("config-set", json));
164+
} catch (const isc::Exception& ex) {
165+
result = isc::config::createAnswer(CONTROL_RESULT_ERROR, string("Error while processing command "
166+
"'config-set': ") + ex.what() +
167+
", params: '" + json->str() + "'");
168+
}
166169
if (!result) {
167170
// Undetermined status of the configuration. This should never
168171
// happen, but as the configureDhcp4Server returns a pointer, it is
169172
// theoretically possible that it will return NULL.
170173
isc_throw(isc::BadValue, "undefined result of "
171-
"processCommand(\"config-set\", json)");
174+
"process command \"config-set\"");
172175
}
173176

174177
// Now check is the returned result is successful (rcode=0) or not
@@ -833,45 +836,6 @@ ControlledDhcpv4Srv::commandStatisticSetMaxSampleAgeAllHandler(const string&,
833836
return (answer);
834837
}
835838

836-
ConstElementPtr
837-
ControlledDhcpv4Srv::processCommand(const string& command,
838-
ConstElementPtr args) {
839-
string txt = args ? args->str() : "(none)";
840-
841-
LOG_DEBUG(dhcp4_logger, DBG_DHCP4_COMMAND, DHCP4_COMMAND_RECEIVED)
842-
.arg(command).arg(txt);
843-
844-
ControlledDhcpv4Srv* srv = ControlledDhcpv4Srv::getInstance();
845-
846-
if (!srv) {
847-
ConstElementPtr no_srv = isc::config::createAnswer(CONTROL_RESULT_ERROR,
848-
"Server object not initialized, so can't process command '" +
849-
command + "', arguments: '" + txt + "'.");
850-
return (no_srv);
851-
}
852-
853-
try {
854-
if (command == "shutdown") {
855-
return (srv->commandShutdownHandler(command, args));
856-
857-
} else if (command == "config-reload") {
858-
return (srv->commandConfigReloadHandler(command, args));
859-
860-
} else if (command == "config-set") {
861-
return (srv->commandConfigSetHandler(command, args));
862-
863-
}
864-
865-
return (isc::config::createAnswer(CONTROL_RESULT_ERROR, "Unrecognized command:"
866-
+ command));
867-
868-
} catch (const isc::Exception& ex) {
869-
return (isc::config::createAnswer(CONTROL_RESULT_ERROR, "Error while processing command '"
870-
+ command + "': " + ex.what() +
871-
", params: '" + txt + "'"));
872-
}
873-
}
874-
875839
isc::data::ConstElementPtr
876840
ControlledDhcpv4Srv::processConfig(isc::data::ConstElementPtr config) {
877841
ControlledDhcpv4Srv* srv = ControlledDhcpv4Srv::getInstance();

src/bin/dhcp4/ctrl_dhcp4_srv.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,6 @@ class ControlledDhcpv4Srv : public isc::dhcp::Dhcpv4Srv {
7272
/// @param exit_value integer value to the process should exit with.
7373
virtual void shutdownServer(int exit_value);
7474

75-
/// @brief Command processor
76-
///
77-
/// Currently supported commands are:
78-
/// - shutdown
79-
/// - config-reload
80-
/// - config-set
81-
///
82-
/// @note It never throws.
83-
///
84-
/// @param command Text representation of the command (e.g. "shutdown")
85-
/// @param args Optional parameters
86-
///
87-
/// @return status of the command
88-
static isc::data::ConstElementPtr
89-
processCommand(const std::string& command, isc::data::ConstElementPtr args);
90-
9175
/// @brief Configuration processor
9276
///
9377
/// This is a method for handling incoming configuration updates.

src/bin/dhcp4/dhcp4_messages.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ extern const isc::log::MessageID DHCP4_CLIENT_HOSTNAME_DATA = "DHCP4_CLIENT_HOST
2929
extern const isc::log::MessageID DHCP4_CLIENT_HOSTNAME_MALFORMED = "DHCP4_CLIENT_HOSTNAME_MALFORMED";
3030
extern const isc::log::MessageID DHCP4_CLIENT_HOSTNAME_PROCESS = "DHCP4_CLIENT_HOSTNAME_PROCESS";
3131
extern const isc::log::MessageID DHCP4_CLIENT_NAME_PROC_FAIL = "DHCP4_CLIENT_NAME_PROC_FAIL";
32-
extern const isc::log::MessageID DHCP4_COMMAND_RECEIVED = "DHCP4_COMMAND_RECEIVED";
3332
extern const isc::log::MessageID DHCP4_CONFIG_COMPLETE = "DHCP4_CONFIG_COMPLETE";
3433
extern const isc::log::MessageID DHCP4_CONFIG_FETCH = "DHCP4_CONFIG_FETCH";
3534
extern const isc::log::MessageID DHCP4_CONFIG_LOAD_FAIL = "DHCP4_CONFIG_LOAD_FAIL";
@@ -216,7 +215,6 @@ const char* values[] = {
216215
"DHCP4_CLIENT_HOSTNAME_MALFORMED", "%1: client hostname option malformed: %2",
217216
"DHCP4_CLIENT_HOSTNAME_PROCESS", "%1: processing client's Hostname option",
218217
"DHCP4_CLIENT_NAME_PROC_FAIL", "%1: failed to process the fqdn or hostname sent by a client: %2",
219-
"DHCP4_COMMAND_RECEIVED", "received command %1, arguments: %2",
220218
"DHCP4_CONFIG_COMPLETE", "DHCPv4 server has completed configuration: %1",
221219
"DHCP4_CONFIG_FETCH", "Fetching configuration data from config backends.",
222220
"DHCP4_CONFIG_LOAD_FAIL", "configuration error using file: %1, reason: %2",

src/bin/dhcp4/dhcp4_messages.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ extern const isc::log::MessageID DHCP4_CLIENT_HOSTNAME_DATA;
3030
extern const isc::log::MessageID DHCP4_CLIENT_HOSTNAME_MALFORMED;
3131
extern const isc::log::MessageID DHCP4_CLIENT_HOSTNAME_PROCESS;
3232
extern const isc::log::MessageID DHCP4_CLIENT_NAME_PROC_FAIL;
33-
extern const isc::log::MessageID DHCP4_COMMAND_RECEIVED;
3433
extern const isc::log::MessageID DHCP4_CONFIG_COMPLETE;
3534
extern const isc::log::MessageID DHCP4_CONFIG_FETCH;
3635
extern const isc::log::MessageID DHCP4_CONFIG_LOAD_FAIL;

src/bin/dhcp4/dhcp4_messages.mes

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,6 @@ name was malformed or due to internal server error. The first argument
149149
contains the client and transaction identification information. The
150150
second argument holds the detailed description of the error.
151151

152-
% DHCP4_COMMAND_RECEIVED received command %1, arguments: %2
153-
A debug message listing the command (and possible arguments) received
154-
from the Kea control system by the DHCPv4 server.
155-
156152
% DHCP4_CONFIG_COMPLETE DHCPv4 server has completed configuration: %1
157153
This is an informational message announcing the successful processing of a
158154
new configuration. It is output during server startup, and when an updated

src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -425,12 +425,12 @@ TEST_F(CtrlChannelDhcpv4SrvTest, commands) {
425425
int rcode = -1;
426426

427427
// Case 1: send bogus command
428-
ConstElementPtr result = ControlledDhcpv4Srv::processCommand("blah", params);
428+
ConstElementPtr result = CommandMgr::instance().processCommand(createCommand("blah", params));
429429
ConstElementPtr comment = parseAnswer(rcode, result);
430-
EXPECT_EQ(1, rcode); // expect failure (no such command as blah)
430+
EXPECT_EQ(2, rcode); // expect failure (no such command as blah)
431431

432432
// Case 2: send shutdown command without any parameters
433-
result = ControlledDhcpv4Srv::processCommand("shutdown", params);
433+
result = CommandMgr::instance().processCommand(createCommand("shutdown", params));
434434
comment = parseAnswer(rcode, result);
435435
EXPECT_EQ(0, rcode); // expect success
436436
// Exit value should default to 0.
@@ -440,7 +440,7 @@ TEST_F(CtrlChannelDhcpv4SrvTest, commands) {
440440
ConstElementPtr x(new isc::data::IntElement(77));
441441
params->set("exit-value", x);
442442

443-
result = ControlledDhcpv4Srv::processCommand("shutdown", params);
443+
result = CommandMgr::instance().processCommand(createCommand("shutdown", params));
444444
comment = parseAnswer(rcode, result);
445445
EXPECT_EQ(0, rcode); // expect success
446446

src/bin/dhcp4/tests/hooks_unittest.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4128,7 +4128,7 @@ TEST_F(LoadUnloadDhcpv4SrvTest, startServiceFail) {
41284128

41294129
// Configure the server.
41304130
ConstElementPtr answer;
4131-
ASSERT_NO_THROW(answer = srv->processCommand("config-set", config));
4131+
ASSERT_NO_THROW(answer = CommandMgr::instance().processCommand(createCommand("config-set", config)));
41324132

41334133
// Make sure there was an error with expected message.
41344134
int status_code;

src/bin/dhcp6/ctrl_dhcp6_srv.cc

Lines changed: 16 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,14 @@ static const char* SERVER_DUID_FILE = "kea-dhcp6-serverid";
7878
///
7979
/// @param signo Signal number received.
8080
void signalHandler(int signo) {
81-
// SIGHUP signals a request to reconfigure the server.
82-
if (signo == SIGHUP) {
83-
ControlledDhcpv6Srv::processCommand("config-reload",
84-
ConstElementPtr());
85-
} else if ((signo == SIGTERM) || (signo == SIGINT)) {
86-
ControlledDhcpv6Srv::processCommand("shutdown",
87-
ConstElementPtr());
81+
try {
82+
// SIGHUP signals a request to reconfigure the server.
83+
if (signo == SIGHUP) {
84+
CommandMgr::instance().processCommand(createCommand("config-reload"));
85+
} else if ((signo == SIGTERM) || (signo == SIGINT)) {
86+
CommandMgr::instance().processCommand(createCommand("shutdown"));
87+
}
88+
} catch (const isc::Exception& ex) {
8889
}
8990
}
9091

@@ -111,10 +112,6 @@ ControlledDhcpv6Srv::init(const std::string& file_name) {
111112
isc_throw(isc::BadValue, reason);
112113
}
113114

114-
// We don't need to call openActiveSockets() or startD2() as these
115-
// methods are called in processConfig() which is called by
116-
// processCommand("config-set", ...)
117-
118115
// Set signal handlers. When the SIGHUP is received by the process
119116
// the server reconfiguration will be triggered. When SIGTERM or
120117
// SIGINT will be received, the server will start shutting down.
@@ -165,13 +162,19 @@ ControlledDhcpv6Srv::loadConfigFile(const std::string& file_name) {
165162
}
166163

167164
// Use parsed JSON structures to configure the server
168-
result = ControlledDhcpv6Srv::processCommand("config-set", json);
165+
try {
166+
result = CommandMgr::instance().processCommand(createCommand("config-set", json));
167+
} catch (const isc::Exception& ex) {
168+
result = isc::config::createAnswer(CONTROL_RESULT_ERROR, string("Error while processing command "
169+
"'config-set': ") + ex.what() +
170+
", params: '" + json->str() + "'");
171+
}
169172
if (!result) {
170173
// Undetermined status of the configuration. This should never
171174
// happen, but as the configureDhcp6Server returns a pointer, it is
172175
// theoretically possible that it will return NULL.
173176
isc_throw(isc::BadValue, "undefined result of "
174-
"processCommand(\"config-set\", json)");
177+
"process command \"config-set\"");
175178
}
176179

177180
// Now check is the returned result is successful (rcode=0) or not
@@ -838,45 +841,6 @@ ControlledDhcpv6Srv::commandStatisticSetMaxSampleAgeAllHandler(const string&,
838841
return (answer);
839842
}
840843

841-
ConstElementPtr
842-
ControlledDhcpv6Srv::processCommand(const string& command,
843-
ConstElementPtr args) {
844-
string txt = args ? args->str() : "(none)";
845-
846-
LOG_DEBUG(dhcp6_logger, DBG_DHCP6_COMMAND, DHCP6_COMMAND_RECEIVED)
847-
.arg(command).arg(txt);
848-
849-
ControlledDhcpv6Srv* srv = ControlledDhcpv6Srv::getInstance();
850-
851-
if (!srv) {
852-
ConstElementPtr no_srv = isc::config::createAnswer(CONTROL_RESULT_ERROR,
853-
"Server object not initialized, so can't process command '" +
854-
command + "', arguments: '" + txt + "'.");
855-
return (no_srv);
856-
}
857-
858-
try {
859-
if (command == "shutdown") {
860-
return (srv->commandShutdownHandler(command, args));
861-
862-
} else if (command == "config-reload") {
863-
return (srv->commandConfigReloadHandler(command, args));
864-
865-
} else if (command == "config-set") {
866-
return (srv->commandConfigSetHandler(command, args));
867-
868-
}
869-
870-
return (isc::config::createAnswer(CONTROL_RESULT_ERROR, "Unrecognized command:"
871-
+ command));
872-
873-
} catch (const isc::Exception& ex) {
874-
return (isc::config::createAnswer(CONTROL_RESULT_ERROR, "Error while processing command '"
875-
+ command + "': " + ex.what() +
876-
", params: '" + txt + "'"));
877-
}
878-
}
879-
880844
isc::data::ConstElementPtr
881845
ControlledDhcpv6Srv::processConfig(isc::data::ConstElementPtr config) {
882846
ControlledDhcpv6Srv* srv = ControlledDhcpv6Srv::getInstance();

src/bin/dhcp6/ctrl_dhcp6_srv.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,6 @@ class ControlledDhcpv6Srv : public isc::dhcp::Dhcpv6Srv {
7272
/// @param exit_value integer value to the process should exit with.
7373
virtual void shutdownServer(int exit_value);
7474

75-
/// @brief Command processor
76-
///
77-
/// Currently supported commands are:
78-
/// - shutdown
79-
/// - config-reload
80-
/// - config-set
81-
///
82-
/// @note It never throws.
83-
///
84-
/// @param command Text representation of the command (e.g. "shutdown")
85-
/// @param args Optional parameters
86-
///
87-
/// @return status of the command
88-
static isc::data::ConstElementPtr
89-
processCommand(const std::string& command, isc::data::ConstElementPtr args);
90-
9175
/// @brief Configuration processor
9276
///
9377
/// This is a method for handling incoming configuration updates.

src/bin/dhcp6/dhcp6_messages.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ extern const isc::log::MessageID DHCP6_CLASS_ASSIGNED = "DHCP6_CLASS_ASSIGNED";
2424
extern const isc::log::MessageID DHCP6_CLASS_UNCONFIGURED = "DHCP6_CLASS_UNCONFIGURED";
2525
extern const isc::log::MessageID DHCP6_CLASS_UNDEFINED = "DHCP6_CLASS_UNDEFINED";
2626
extern const isc::log::MessageID DHCP6_CLASS_UNTESTABLE = "DHCP6_CLASS_UNTESTABLE";
27-
extern const isc::log::MessageID DHCP6_COMMAND_RECEIVED = "DHCP6_COMMAND_RECEIVED";
2827
extern const isc::log::MessageID DHCP6_CONFIG_COMPLETE = "DHCP6_CONFIG_COMPLETE";
2928
extern const isc::log::MessageID DHCP6_CONFIG_LOAD_FAIL = "DHCP6_CONFIG_LOAD_FAIL";
3029
extern const isc::log::MessageID DHCP6_CONFIG_PACKET_QUEUE = "DHCP6_CONFIG_PACKET_QUEUE";
@@ -200,7 +199,6 @@ const char* values[] = {
200199
"DHCP6_CLASS_UNCONFIGURED", "%1: client packet belongs to an unconfigured class: %2",
201200
"DHCP6_CLASS_UNDEFINED", "required class %1 has no definition",
202201
"DHCP6_CLASS_UNTESTABLE", "required class %1 has no test expression",
203-
"DHCP6_COMMAND_RECEIVED", "received command %1, arguments: %2",
204202
"DHCP6_CONFIG_COMPLETE", "DHCPv6 server has completed configuration: %1",
205203
"DHCP6_CONFIG_LOAD_FAIL", "configuration error using file: %1, reason: %2",
206204
"DHCP6_CONFIG_PACKET_QUEUE", "DHCPv6 packet queue info after configuration: %1",

src/bin/dhcp6/dhcp6_messages.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ extern const isc::log::MessageID DHCP6_CLASS_ASSIGNED;
2525
extern const isc::log::MessageID DHCP6_CLASS_UNCONFIGURED;
2626
extern const isc::log::MessageID DHCP6_CLASS_UNDEFINED;
2727
extern const isc::log::MessageID DHCP6_CLASS_UNTESTABLE;
28-
extern const isc::log::MessageID DHCP6_COMMAND_RECEIVED;
2928
extern const isc::log::MessageID DHCP6_CONFIG_COMPLETE;
3029
extern const isc::log::MessageID DHCP6_CONFIG_LOAD_FAIL;
3130
extern const isc::log::MessageID DHCP6_CONFIG_PACKET_QUEUE;

src/bin/dhcp6/dhcp6_messages.mes

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,6 @@ has no definition.
115115
This debug message informs that a class was listed for required evaluation but
116116
its definition does not include a test expression to evaluate.
117117

118-
% DHCP6_COMMAND_RECEIVED received command %1, arguments: %2
119-
A debug message listing the command (and possible arguments) received
120-
from the Kea control system by the IPv6 DHCP server.
121-
122118
% DHCP6_CONFIG_COMPLETE DHCPv6 server has completed configuration: %1
123119
This is an informational message announcing the successful processing of a
124120
new configuration. it is output during server startup, and when an updated

src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -451,20 +451,20 @@ TEST_F(CtrlDhcpv6SrvTest, commands) {
451451
int rcode = -1;
452452

453453
// Case 1: send bogus command
454-
ConstElementPtr result = ControlledDhcpv6Srv::processCommand("blah", params);
454+
ConstElementPtr result = CommandMgr::instance().processCommand(createCommand("blah", params));
455455
ConstElementPtr comment = parseAnswer(rcode, result);
456-
EXPECT_EQ(1, rcode); // expect failure (no such command as blah)
456+
EXPECT_EQ(2, rcode); // expect failure (no such command as blah)
457457

458458
// Case 2: send shutdown command without any parameters
459-
result = ControlledDhcpv6Srv::processCommand("shutdown", params);
459+
result = CommandMgr::instance().processCommand(createCommand("shutdown", params));
460460
comment = parseAnswer(rcode, result);
461461
EXPECT_EQ(0, rcode); // expect success
462462

463463
// Case 3: send shutdown command with exit-value parameter.
464464
ConstElementPtr x(new isc::data::IntElement(77));
465465
params->set("exit-value", x);
466466

467-
result = ControlledDhcpv6Srv::processCommand("shutdown", params);
467+
result = CommandMgr::instance().processCommand(createCommand("shutdown", params));
468468
comment = parseAnswer(rcode, result);
469469
EXPECT_EQ(0, rcode); // expect success
470470

src/bin/dhcp6/tests/hooks_unittest.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5922,7 +5922,7 @@ TEST_F(LoadUnloadDhcpv6SrvTest, startServiceFail) {
59225922

59235923
// Configure the server.
59245924
ConstElementPtr answer;
5925-
ASSERT_NO_THROW(answer = srv->processCommand("config-set", config));
5925+
ASSERT_NO_THROW(answer = CommandMgr::instance().processCommand(createCommand("config-set", config)));
59265926

59275927
// Make sure there was an error with expected message.
59285928
int status_code;

0 commit comments

Comments
 (0)