Commit 3db17a8c authored by Francis Dupont's avatar Francis Dupont

[30-implement-control-socket-for-ddns-2] Finished unit tests

parent f9db8f64
...@@ -50,9 +50,6 @@ D2Controller::D2Controller() ...@@ -50,9 +50,6 @@ D2Controller::D2Controller()
void void
D2Controller::registerCommands() { D2Controller::registerCommands() {
// CommandMgr uses IO service to run asynchronous socket operations.
CommandMgr::instance().setIOService(getIOService());
// These are the commands always supported by the D2 server. // These are the commands always supported by the D2 server.
// Please keep the list in alphabetic order. // Please keep the list in alphabetic order.
CommandMgr::instance().registerCommand(BUILD_REPORT_COMMAND, CommandMgr::instance().registerCommand(BUILD_REPORT_COMMAND,
......
...@@ -24,8 +24,7 @@ const unsigned int D2Process::QUEUE_RESTART_PERCENT = 80; ...@@ -24,8 +24,7 @@ const unsigned int D2Process::QUEUE_RESTART_PERCENT = 80;
D2Process::D2Process(const char* name, const asiolink::IOServicePtr& io_service) D2Process::D2Process(const char* name, const asiolink::IOServicePtr& io_service)
: DProcessBase(name, io_service, DCfgMgrBasePtr(new D2CfgMgr())), : DProcessBase(name, io_service, DCfgMgrBasePtr(new D2CfgMgr())),
reconf_queue_flag_(false), reconf_control_socket_flag_(false), reconf_queue_flag_(false), shutdown_type_(SD_NORMAL) {
shutdown_type_(SD_NORMAL) {
// Instantiate queue manager. Note that queue manager does not start // Instantiate queue manager. Note that queue manager does not start
// listening at this point. That can only occur after configuration has // listening at this point. That can only occur after configuration has
...@@ -43,6 +42,8 @@ D2Process::D2Process(const char* name, const asiolink::IOServicePtr& io_service) ...@@ -43,6 +42,8 @@ D2Process::D2Process(const char* name, const asiolink::IOServicePtr& io_service)
void void
D2Process::init() { D2Process::init() {
// CommandMgr uses IO service to run asynchronous socket operations.
isc::config::CommandMgr::instance().setIOService(getIoService());
}; };
void void
...@@ -56,11 +57,6 @@ D2Process::run() { ...@@ -56,11 +57,6 @@ D2Process::run() {
// Loop forever until we are allowed to shutdown. // Loop forever until we are allowed to shutdown.
while (!canShutdown()) { while (!canShutdown()) {
// Check if the command channel should be (re-)configured.
if (getReconfControlSocketFlag()) {
reconfigureCommandChannel();
}
// Check on the state of the request queue. Take any // Check on the state of the request queue. Take any
// actions necessary regarding it. // actions necessary regarding it.
checkQueueStatus(); checkQueueStatus();
...@@ -215,7 +211,8 @@ D2Process::configure(isc::data::ConstElementPtr config_set, bool check_only) { ...@@ -215,7 +211,8 @@ D2Process::configure(isc::data::ConstElementPtr config_set, bool check_only) {
.arg(config_set->str()); .arg(config_set->str());
isc::data::ConstElementPtr answer; isc::data::ConstElementPtr answer;
answer = getCfgMgr()->simpleParseConfig(config_set, check_only); answer = getCfgMgr()->simpleParseConfig(config_set, check_only,
boost::bind(&D2Process::reconfigureCommandChannel, this));
if (check_only) { if (check_only) {
return (answer); return (answer);
} }
...@@ -229,7 +226,6 @@ D2Process::configure(isc::data::ConstElementPtr config_set, bool check_only) { ...@@ -229,7 +226,6 @@ D2Process::configure(isc::data::ConstElementPtr config_set, bool check_only) {
// action. In integrated mode, this will send a failed response back // action. In integrated mode, this will send a failed response back
// to the configuration backend. // to the configuration backend.
reconf_queue_flag_ = false; reconf_queue_flag_ = false;
reconf_control_socket_flag_ = false;
return (answer); return (answer);
} }
...@@ -245,7 +241,6 @@ D2Process::configure(isc::data::ConstElementPtr config_set, bool check_only) { ...@@ -245,7 +241,6 @@ D2Process::configure(isc::data::ConstElementPtr config_set, bool check_only) {
// things that need reconfiguration. It might also be useful if we // things that need reconfiguration. It might also be useful if we
// did some analysis to decide what if anything we need to do.) // did some analysis to decide what if anything we need to do.)
reconf_queue_flag_ = true; reconf_queue_flag_ = true;
reconf_control_socket_flag_ = true;
// If we are here, configuration was valid, at least it parsed correctly // If we are here, configuration was valid, at least it parsed correctly
// and therefore contained no invalid values. // and therefore contained no invalid values.
...@@ -413,36 +408,35 @@ const char* D2Process::getShutdownTypeStr(const ShutdownType& type) { ...@@ -413,36 +408,35 @@ const char* D2Process::getShutdownTypeStr(const ShutdownType& type) {
void void
D2Process::reconfigureCommandChannel() { D2Process::reconfigureCommandChannel() {
reconf_control_socket_flag_ = false;
// Current socket configuration.
static isc::data::ConstElementPtr current_sock_cfg;
// Get new socket configuration. // Get new socket configuration.
isc::data::ConstElementPtr sock_cfg = getD2CfgMgr()->getControlSocketInfo(); isc::data::ConstElementPtr sock_cfg = getD2CfgMgr()->getControlSocketInfo();
// Determine if the socket configuration has changed. It has if // Determine if the socket configuration has changed. It has if
// both old and new configuration is specified but respective // both old and new configuration is specified but respective
// data elements aren't equal. // data elements aren't equal.
bool sock_changed = (sock_cfg && current_sock_cfg && bool sock_changed = (sock_cfg && current_control_socket_ &&
!sock_cfg->equals(*current_sock_cfg)); !sock_cfg->equals(*current_control_socket_));
// If the previous or new socket configuration doesn't exist or // If the previous or new socket configuration doesn't exist or
// the new configuration differs from the old configuration we // the new configuration differs from the old configuration we
// close the existing socket and open a new socket as appropriate. // close the existing socket and open a new socket as appropriate.
// Note that closing an existing socket means the client will not // Note that closing an existing socket means the client will not
// receive the configuration result. // receive the configuration result.
if (!sock_cfg || !current_sock_cfg || sock_changed) { if (!sock_cfg || !current_control_socket_ || sock_changed) {
// Close the existing socket (if any). // Close the existing socket.
isc::config::CommandMgr::instance().closeCommandSocket(); if (current_control_socket_) {
isc::config::CommandMgr::instance().closeCommandSocket();
current_control_socket_.reset();
}
// Open the new socket.
if (sock_cfg) { if (sock_cfg) {
isc::config::CommandMgr::instance().openCommandSocket(sock_cfg); isc::config::CommandMgr::instance().openCommandSocket(sock_cfg);
} }
} }
// Commit the new socket configuration. // Commit the new socket configuration.
current_sock_cfg = sock_cfg; current_control_socket_ = sock_cfg;
} }
}; // namespace isc::d2 }; // namespace isc::d2
......
...@@ -67,10 +67,8 @@ public: ...@@ -67,10 +67,8 @@ public:
/// PRIOR to configuration reception. The base class provides this method /// PRIOR to configuration reception. The base class provides this method
/// as a place to perform any derivation-specific initialization steps /// as a place to perform any derivation-specific initialization steps
/// that are inappropriate for the constructor but necessary prior to /// that are inappropriate for the constructor but necessary prior to
/// launch. So far, no such steps have been identified for D2, so its /// configure.
/// implementation is empty but required. /// For D2 it is used to initialize the command manager.
///
/// @throw DProcessBaseError if the initialization fails.
virtual void init(); virtual void init();
/// @brief Implements the process's event loop. /// @brief Implements the process's event loop.
...@@ -284,11 +282,6 @@ public: ...@@ -284,11 +282,6 @@ public:
return (reconf_queue_flag_); return (reconf_queue_flag_);
} }
/// @brief Returns true if the control socket should be reconfigured.
bool getReconfControlSocketFlag() const {
return (reconf_control_socket_flag_);
}
/// @brief Returns the type of shutdown requested. /// @brief Returns the type of shutdown requested.
/// ///
/// Note, this value is meaningless unless shouldShutdown() returns true. /// Note, this value is meaningless unless shouldShutdown() returns true.
...@@ -314,11 +307,12 @@ private: ...@@ -314,11 +307,12 @@ private:
/// @brief Indicates if the queue manager should be reconfigured. /// @brief Indicates if the queue manager should be reconfigured.
bool reconf_queue_flag_; bool reconf_queue_flag_;
/// @brief Indicates if the control socket should be reconfigured.
bool reconf_control_socket_flag_;
/// @brief Indicates the type of shutdown requested. /// @brief Indicates the type of shutdown requested.
ShutdownType shutdown_type_; ShutdownType shutdown_type_;
/// @brief Current socket control configuration.
isc::data::ConstElementPtr current_control_socket_;
}; };
/// @brief Defines a shared pointer to D2Process. /// @brief Defines a shared pointer to D2Process.
......
...@@ -51,7 +51,7 @@ public: ...@@ -51,7 +51,7 @@ public:
return (getController()); return (getController());
} }
virtual ~NakedD2Controller() { } virtual ~NakedD2Controller() { deregisterCommands(); }
using DControllerBase::getIOService; using DControllerBase::getIOService;
using DControllerBase::initProcess; using DControllerBase::initProcess;
...@@ -129,7 +129,7 @@ public: ...@@ -129,7 +129,7 @@ public:
/// @brief Destructor. /// @brief Destructor.
~CtrlChannelD2Test() { ~CtrlChannelD2Test() {
// Include deregister & co. // Deregister & co.
server_.reset(); server_.reset();
// Remove files. // Remove files.
...@@ -202,6 +202,7 @@ public: ...@@ -202,6 +202,7 @@ public:
ASSERT_TRUE(proc); ASSERT_TRUE(proc);
ConstElementPtr answer = proc->configure(config, false); ConstElementPtr answer = proc->configure(config, false);
ASSERT_TRUE(answer); ASSERT_TRUE(answer);
ASSERT_NO_THROW(d2Controller()->registerCommands());
int status = 0; int status = 0;
ConstElementPtr txt = parseAnswer(status, answer); ConstElementPtr txt = parseAnswer(status, answer);
...@@ -686,6 +687,7 @@ TEST_F(CtrlChannelD2Test, configTest) { ...@@ -686,6 +687,7 @@ TEST_F(CtrlChannelD2Test, configTest) {
ASSERT_TRUE(answer); ASSERT_TRUE(answer);
EXPECT_EQ("{ \"result\": 0, \"text\": \"Configuration applied successfully.\" }", EXPECT_EQ("{ \"result\": 0, \"text\": \"Configuration applied successfully.\" }",
answer->str()); answer->str());
ASSERT_NO_THROW(d2Controller()->registerCommands());
// Check that the config was indeed applied. // Check that the config was indeed applied.
D2CfgMgrPtr cfg_mgr = proc->getD2CfgMgr(); D2CfgMgrPtr cfg_mgr = proc->getD2CfgMgr();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment