#include <config.h>
#include <cc/data.h>
+#include <cc/command_interpreter.h>
#include <dhcp4/ctrl_dhcp4_srv.h>
#include <dhcp4/dhcp4_log.h>
#include <dhcp4/dhcp4to6_ipc.h>
ConstElementPtr
ControlledDhcpv4Srv::commandSetConfigHandler(const string&,
ConstElementPtr args) {
- const int status_code = 1; // 1 indicates an error
+ const int status_code = CONTROL_RESULT_ERROR; // 1 indicates an error
ConstElementPtr dhcp4;
string message;
ConstElementPtr
ControlledDhcpv4Srv::commandConfigTestHandler(const string&,
ConstElementPtr args) {
- const int status_code = 1; // 1 indicates an error
+ const int status_code = CONTROL_RESULT_ERROR; // 1 indicates an error
ConstElementPtr dhcp4;
string message;
ConstElementPtr
ControlledDhcpv4Srv::commandLeasesReclaimHandler(const string&,
ConstElementPtr args) {
- int status_code = 1;
+ int status_code = CONTROL_RESULT_ERROR;
string message;
// args must be { "remove": <bool> }
/// in them.
///
/// Currently supported commands are:
+ /// - config-reload
+ /// - config-test
/// - shutdown
/// - libreload
- /// - config-reload
/// - leases-reclaim
/// ...
///
///
/// This is a method for checking incoming configuration.
///
- /// @param new_config textual representation of the new configuration
+ /// @param new_config JSON representation of the new configuration
///
/// @return status of the config check
isc::data::ConstElementPtr
// Should fail with a syntax error
EXPECT_EQ("{ \"result\": 1, "
- "\"text\": \"subnet configuration failed: mandatory 'subnet' parameter is missing for a subnet being configured (<string>:20:17)\" }",
+ "\"text\": \"subnet configuration failed: mandatory 'subnet' "
+ "parameter is missing for a subnet being configured (<string>:20:17)\" }",
response);
// Check that the config was not lost
<< "}\n" // close dhcp4
<< "}}";
- /* Verify the control channel socket exists */
+ // Verify the control channel socket exists.
ASSERT_TRUE(fileExists(socket_path_));
- // Send the set-config command
+ // Send the set-config command.
sendUnixCommand(os.str(), response);
- /* Verify the control channel socket no longer exists */
+ // Verify the control channel socket no longer exists.
EXPECT_FALSE(fileExists(socket_path_));
// With no command channel, should still receive the response.
// Should fail with a syntax error
EXPECT_EQ("{ \"result\": 1, "
- "\"text\": \"subnet configuration failed: mandatory 'subnet' parameter is missing for a subnet being configured (<string>:20:17)\" }",
+ "\"text\": \"subnet configuration failed: mandatory 'subnet' "
+ "parameter is missing for a subnet being configured (<string>:20:17)\" }",
response);
// Check that the config was not lost
<< "}\n" // close dhcp4
<< "}}";
- /* Verify the control channel socket exists */
+ // Verify the control channel socket exists.
ASSERT_TRUE(fileExists(socket_path_));
// Send the config-test command
sendUnixCommand(os.str(), response);
- /* Verify the control channel socket still exists */
+ // Verify the control channel socket still exists.
EXPECT_TRUE(fileExists(socket_path_));
// Verify the configuration was successful.
- EXPECT_EQ("{ \"result\": 0, \"text\": \"Configuration seems sane. Control-socket, hook-libraries, and D2 configuration were sanity checked, but not applied.\" }",
+ EXPECT_EQ("{ \"result\": 0, \"text\": \"Configuration seems sane. "
+ "Control-socket, hook-libraries, and D2 configuration were "
+ "sanity checked, but not applied.\" }",
response);
// Check that the config was not applied
#include <config.h>
#include <cc/data.h>
+#include <cc/command_interpreter.h>
#include <config/command_mgr.h>
#include <dhcp/libdhcp++.h>
#include <dhcpsrv/cfgmgr.h>
ConstElementPtr
ControlledDhcpv6Srv::commandSetConfigHandler(const string&,
ConstElementPtr args) {
- const int status_code = 1; // 1 indicates an error
+ const int status_code = CONTROL_RESULT_ERROR;
ConstElementPtr dhcp6;
string message;
// the logging first in case there's a configuration failure.
int rcode = 0;
isc::config::parseAnswer(rcode, result);
- if (rcode == 0) {
+ if (rcode == CONTROL_RESULT_SUCCESS) {
CfgMgr::instance().getStagingCfg()->applyLoggingCfg();
// Use new configuration.
ConstElementPtr
ControlledDhcpv6Srv::commandConfigTestHandler(const string&,
ConstElementPtr args) {
- const int status_code = 1; // 1 indicates an error
+ const int status_code = CONTROL_RESULT_ERROR; // 1 indicates an error
ConstElementPtr dhcp6;
string message;
ControlledDhcpv6Srv* srv = ControlledDhcpv6Srv::getInstance();
if (!srv) {
- ConstElementPtr no_srv = isc::config::createAnswer(1,
- "Server object not initialized, can't process config.");
+ ConstElementPtr no_srv = isc::config::createAnswer(
+ CONTROL_RESULT_ERROR,
+ "Server object not initialized, can't process config.");
return (no_srv);
}
/// in them.
///
/// Currently supported commands are:
- /// - shutdown
- /// - libreload
/// - config-reload
+ /// - config-test
/// - leases-reclaim
+ /// - libreload
+ /// - shutdown
/// ...
///
/// @note It never throws.
///
/// This is a method for checking incoming configuration.
///
- /// @param new_config textual representation of the new configuration
+ /// @param new_config JSON representation of the new configuration
///
/// @return status of the config check
isc::data::ConstElementPtr
}
// Check that the "set-config" command will replace current configuration
-TEST_F(CtrlChannelDhcpv6SrvTest, set_config) {
+TEST_F(CtrlChannelDhcpv6SrvTest, configSet) {
createUnixChannelServer();
// Define strings to permutate the config arguments
<< "}\n" // close dhcp6
<< "}}";
- /* Verify the control channel socket exists */
+ // Verify the control channel socket exists.
ASSERT_TRUE(fileExists(socket_path_));
- // Send the set-config command
+ // Send the set-config command.
sendUnixCommand(os.str(), response);
- /* Verify the control channel socket no longer exists */
+ // Verify the control channel socket no longer exists.
EXPECT_FALSE(fileExists(socket_path_));
// With no command channel, should still receive the response.
}
// Verify that the "config-test" command will do what we expect.
-TEST_F(CtrlChannelDhcpv6SrvTest, config_test) {
+TEST_F(CtrlChannelDhcpv6SrvTest, configTest) {
createUnixChannelServer();
// Define strings to permutate the config arguments
// Should fail with a syntax error
EXPECT_EQ("{ \"result\": 1, "
- "\"text\": \"subnet configuration failed: mandatory 'subnet' parameter is missing for a subnet being configured (<string>:21:17)\" }",
+ "\"text\": \"subnet configuration failed: mandatory 'subnet' parameter "
+ "is missing for a subnet being configured (<string>:21:17)\" }",
response);
// Check that the config was not lost
<< "}\n" // close dhcp6
<< "}}";
- /* Verify the control channel socket exists */
+ // Verify the control channel socket exists.
ASSERT_TRUE(fileExists(socket_path_));
- // Send the config-test command
+ // Send the config-test command.
sendUnixCommand(os.str(), response);
- /* Verify the control channel socket still exists */
+ // Verify the control channel socket still exists.
EXPECT_TRUE(fileExists(socket_path_));
// Verify the configuration was successful.
- EXPECT_EQ("{ \"result\": 0, \"text\": \"Configuration seems sane. Control-socket, hook-libraries, and D2 configuration were sanity checked, but not applied.\" }",
+ EXPECT_EQ("{ \"result\": 0, \"text\": \"Configuration seems sane. "
+ "Control-socket, hook-libraries, and D2 configuration were "
+ "sanity checked, but not applied.\" }",
response);
// Check that the config was not applied.
CfgMgr::instance().clear();
}
-
typedef std::map<std::string, isc::data::ConstElementPtr> ElementMap;
// This test checks which commands are registered by the DHCPv4 server.