Commit afb5415a authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰 Committed by Francis Dupont

[#153,!82] Changes after review:

 - removed #if 0
 - cleaned up messages
parent 12ed2fdc
...@@ -40,6 +40,9 @@ public: ...@@ -40,6 +40,9 @@ public:
/// @brief Module change callback. /// @brief Module change callback.
/// ///
/// This callback is called by sysrepo when there is a change to
/// configuration data.
///
/// @param sess The running datastore session. /// @param sess The running datastore session.
/// @param module_name The module name. /// @param module_name The module name.
/// @param event The event. /// @param event The event.
...@@ -115,6 +118,8 @@ NetconfAgent::init(NetconfCfgMgrPtr cfg_mgr) { ...@@ -115,6 +118,8 @@ NetconfAgent::init(NetconfCfgMgrPtr cfg_mgr) {
if (NetconfProcess::global_shut_down_flag) { if (NetconfProcess::global_shut_down_flag) {
return; return;
} }
// Retrieve configuration from existing running DHCP daemons.
keaConfig(pair); keaConfig(pair);
if (NetconfProcess::global_shut_down_flag) { if (NetconfProcess::global_shut_down_flag) {
return; return;
...@@ -123,10 +128,13 @@ NetconfAgent::init(NetconfCfgMgrPtr cfg_mgr) { ...@@ -123,10 +128,13 @@ NetconfAgent::init(NetconfCfgMgrPtr cfg_mgr) {
if (NetconfProcess::global_shut_down_flag) { if (NetconfProcess::global_shut_down_flag) {
return; return;
} }
// Initialize sysrepo interface.
initSysrepo(); initSysrepo();
if (NetconfProcess::global_shut_down_flag) { if (NetconfProcess::global_shut_down_flag) {
return; return;
} }
for (auto pair : *servers) { for (auto pair : *servers) {
if (NetconfProcess::global_shut_down_flag) { if (NetconfProcess::global_shut_down_flag) {
return; return;
...@@ -205,7 +213,7 @@ NetconfAgent::keaConfig(const CfgServersMapPair& service_pair) { ...@@ -205,7 +213,7 @@ NetconfAgent::keaConfig(const CfgServersMapPair& service_pair) {
if (!config) { if (!config) {
LOG_ERROR(netconf_logger, NETCONF_GET_CONFIG_FAILED) LOG_ERROR(netconf_logger, NETCONF_GET_CONFIG_FAILED)
.arg(service_pair.first) .arg(service_pair.first)
.arg("configGet returned an empty configuration"); .arg("config-get returned an empty configuration");
return; return;
} }
LOG_INFO(netconf_logger, NETCONF_BOOT_UPDATE_COMPLETE) LOG_INFO(netconf_logger, NETCONF_BOOT_UPDATE_COMPLETE)
...@@ -237,19 +245,26 @@ NetconfAgent::initSysrepo() { ...@@ -237,19 +245,26 @@ NetconfAgent::initSysrepo() {
void void
NetconfAgent::yangConfig(const CfgServersMapPair& service_pair) { NetconfAgent::yangConfig(const CfgServersMapPair& service_pair) {
// If we're shutting down, or the boot-update flag is not set or the model
// associated with it is not specified.
if (NetconfProcess::global_shut_down_flag || if (NetconfProcess::global_shut_down_flag ||
!service_pair.second->getBootUpdate() || !service_pair.second->getBootUpdate() ||
service_pair.second->getModel().empty()) { service_pair.second->getModel().empty()) {
return; return;
} }
// First we need a way to reach the actual servers.
CfgControlSocketPtr ctrl_sock = service_pair.second->getCfgControlSocket(); CfgControlSocketPtr ctrl_sock = service_pair.second->getCfgControlSocket();
if (!ctrl_sock) { if (!ctrl_sock) {
return; return;
} }
LOG_DEBUG(netconf_logger, NETCONF_DBG_TRACE, NETCONF_SET_CONFIG) LOG_DEBUG(netconf_logger, NETCONF_DBG_TRACE, NETCONF_SET_CONFIG)
.arg(service_pair.first); .arg(service_pair.first);
ConstElementPtr config; ConstElementPtr config;
try { try {
// Retrieve configuration from Sysrepo.
TranslatorConfig tc(startup_sess_, service_pair.second->getModel()); TranslatorConfig tc(startup_sess_, service_pair.second->getModel());
config = tc.getConfig(); config = tc.getConfig();
if (!config) { if (!config) {
...@@ -269,7 +284,7 @@ NetconfAgent::yangConfig(const CfgServersMapPair& service_pair) { ...@@ -269,7 +284,7 @@ NetconfAgent::yangConfig(const CfgServersMapPair& service_pair) {
} }
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
ostringstream msg; ostringstream msg;
msg << "YANG getConfig for " << service_pair.first msg << "YANG config-get for " << service_pair.first
<< " failed with " << ex.what(); << " failed with " << ex.what();
LOG_ERROR(netconf_logger, NETCONF_SET_CONFIG_FAILED) LOG_ERROR(netconf_logger, NETCONF_SET_CONFIG_FAILED)
.arg(service_pair.first) .arg(service_pair.first)
...@@ -383,7 +398,7 @@ NetconfAgent::validate(S_Session sess, const CfgServersMapPair& service_pair) { ...@@ -383,7 +398,7 @@ NetconfAgent::validate(S_Session sess, const CfgServersMapPair& service_pair) {
} }
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
ostringstream msg; ostringstream msg;
msg << "YANG getConfig for " << service_pair.first msg << "YANG config-get for " << service_pair.first
<< " failed with " << ex.what(); << " failed with " << ex.what();
LOG_ERROR(netconf_logger, NETCONF_VALIDATE_CONFIG_FAILED) LOG_ERROR(netconf_logger, NETCONF_VALIDATE_CONFIG_FAILED)
.arg(service_pair.first) .arg(service_pair.first)
...@@ -468,7 +483,7 @@ NetconfAgent::update(S_Session sess, const CfgServersMapPair& service_pair) { ...@@ -468,7 +483,7 @@ NetconfAgent::update(S_Session sess, const CfgServersMapPair& service_pair) {
} }
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
ostringstream msg; ostringstream msg;
msg << "YANG getConfig for " << service_pair.first msg << "YANG config-get " << service_pair.first
<< " failed with " << ex.what(); << " failed with " << ex.what();
LOG_ERROR(netconf_logger, NETCONF_UPDATE_CONFIG_FAILED) LOG_ERROR(netconf_logger, NETCONF_UPDATE_CONFIG_FAILED)
.arg(service_pair.first) .arg(service_pair.first)
...@@ -507,6 +522,8 @@ NetconfAgent::update(S_Session sess, const CfgServersMapPair& service_pair) { ...@@ -507,6 +522,8 @@ NetconfAgent::update(S_Session sess, const CfgServersMapPair& service_pair) {
.arg(msg.str()); .arg(msg.str());
return (SR_ERR_VALIDATION_FAILED); return (SR_ERR_VALIDATION_FAILED);
} }
// rcode == CONTROL_RESULT_SUCCESS, unless the docs say otherwise :)
if (rcode != CONTROL_RESULT_SUCCESS) { if (rcode != CONTROL_RESULT_SUCCESS) {
stringstream msg; stringstream msg;
msg << "configSet returned " << answerToText(answer); msg << "configSet returned " << answerToText(answer);
......
...@@ -94,10 +94,22 @@ public: ...@@ -94,10 +94,22 @@ public:
protected: protected:
/// @brief Get and display Kea server configuration. /// @brief Get and display Kea server configuration.
/// ///
/// Retrieves current configuration via control socket (unix or http)
/// from a running Kea server. If boot-update is set to false, this
/// operation is a no-op.
///
/// @param service_pair The service name and configuration pair. /// @param service_pair The service name and configuration pair.
void keaConfig(const CfgServersMapPair& service_pair); void keaConfig(const CfgServersMapPair& service_pair);
/// @brief Kea server configuration from YANG datastore. /// @brief Retrieve Kea server configuration from YANG datastore and
/// applies it to servers.
///
/// This method retrieves the configuation from sysrepo first, then
/// established control socket connection to Kea servers (currently
/// dhcp4 and/or dhcp6) and then attempts to send configuration
/// using config-set.
///
/// If boot-update is set to false, this operation is a no-op.
/// ///
/// @param service_pair The service name and configuration pair. /// @param service_pair The service name and configuration pair.
void yangConfig(const CfgServersMapPair& service_pair); void yangConfig(const CfgServersMapPair& service_pair);
......
...@@ -50,11 +50,11 @@ are printed. ...@@ -50,11 +50,11 @@ are printed.
% NETCONF_LOG_CHANGE_FAIL Netconf configuration change logging failed: %1 % NETCONF_LOG_CHANGE_FAIL Netconf configuration change logging failed: %1
The warning message indicates that the configuration change logging The warning message indicates that the configuration change logging
encountered a not expected condition. encountered an unexpected condition. Details of it will be logged.
% NETCONF_RUN_EXIT application is exiting the event loop % NETCONF_RUN_EXIT application is exiting the event loop
This is a debug message issued when the Netconf application exits its This is a debug message issued when the Netconf application exits its
event loop. event loop. This is a normal step during kea-netconf shutdown.
% NETCONF_SET_CONFIG setting configuration to %1 server % NETCONF_SET_CONFIG setting configuration to %1 server
This debug message indicates that Netconf is trying to set the This debug message indicates that Netconf is trying to set the
...@@ -64,7 +64,7 @@ configuration to a Kea server. ...@@ -64,7 +64,7 @@ configuration to a Kea server.
This debug message indicates that Netconf set the configuration to a This debug message indicates that Netconf set the configuration to a
Kea server. The server name and the applied configuration are printed. Kea server. The server name and the applied configuration are printed.
% NETCONF_SET_CONFIG_FAILED setting configuration to %1 server: %2 % NETCONF_SET_CONFIG_FAILED setting configuration to %1 server failed: %2
The error message indicates that Netconf got an error setting the The error message indicates that Netconf got an error setting the
configuration to a Kea server. The name of the server and the error configuration to a Kea server. The name of the server and the error
are printed. Make sure that the server is up and running, has appropriate are printed. Make sure that the server is up and running, has appropriate
......
...@@ -41,7 +41,7 @@ namespace { ...@@ -41,7 +41,7 @@ namespace {
const string TEST_SOCKET = "test-socket"; const string TEST_SOCKET = "test-socket";
/// @brief Test timeout in ms. /// @brief Test timeout in ms.
const long TEST_TIMEOUT = 10000; //const long TEST_TIMEOUT = 10000;
/// @brief Type definition for the pointer to Thread objects. /// @brief Type definition for the pointer to Thread objects.
typedef boost::shared_ptr<Thread> ThreadPtr; typedef boost::shared_ptr<Thread> ThreadPtr;
...@@ -451,9 +451,8 @@ TEST_F(NetconfAgentLogTest, logChanges) { ...@@ -451,9 +451,8 @@ TEST_F(NetconfAgentLogTest, logChanges) {
usleep(1000); usleep(1000);
} }
// Enable this for debugging. // Enable this for debugging.
#if 0 // logCheckVerbose(true);
logCheckVerbose(true);
#endif
EXPECT_TRUE(checkFile()); EXPECT_TRUE(checkFile());
} }
...@@ -564,9 +563,8 @@ TEST_F(NetconfAgentLogTest, logChanges2) { ...@@ -564,9 +563,8 @@ TEST_F(NetconfAgentLogTest, logChanges2) {
usleep(1000); usleep(1000);
} }
// Enable this for debugging. // Enable this for debugging.
#if 0 // logCheckVerbose(true);
logCheckVerbose(true);
#endif
EXPECT_TRUE(checkFile()); EXPECT_TRUE(checkFile());
} }
...@@ -634,9 +632,7 @@ TEST_F(NetconfAgentTest, keaConfig) { ...@@ -634,9 +632,7 @@ TEST_F(NetconfAgentTest, keaConfig) {
ConstElementPtr pruned = prune(expected, request); ConstElementPtr pruned = prune(expected, request);
EXPECT_TRUE(expected->equals(*pruned)); EXPECT_TRUE(expected->equals(*pruned));
// Alternative showing more for debugging... // Alternative showing more for debugging...
#if 0 // EXPECT_EQ(prettyPrint(expected), prettyPrint(pruned));
EXPECT_EQ(prettyPrint(expected), prettyPrint(pruned));
#endif
// Check response. // Check response.
ASSERT_EQ(1, responses_.size()); ASSERT_EQ(1, responses_.size());
......
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