From: Andrei Pavel Date: Thu, 22 Jul 2021 19:31:52 +0000 (+0300) Subject: [#1077] formatting changes to YANG and NETCONF X-Git-Tag: Kea-1.9.10~44 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ea14639433229bd265161fd932b799713d83a49e;p=thirdparty%2Fkea.git [#1077] formatting changes to YANG and NETCONF --- diff --git a/src/bin/netconf/netconf.cc b/src/bin/netconf/netconf.cc index ddb3a6a961..fae5564600 100644 --- a/src/bin/netconf/netconf.cc +++ b/src/bin/netconf/netconf.cc @@ -486,19 +486,18 @@ NetconfAgent::subscribeToNotifications(const CfgServersMapPair& service_pair) { .arg(model); S_Subscribe subscription(std::make_shared(running_sess_)); - auto event_notif_callback = - [=](sysrepo::S_Session session, - sr_ev_notif_type_t const notification_type, char const* path, - sysrepo::S_Vals const vals, time_t timestamp) { - NetconfAgentCallback agent(service_pair); - return agent.event_notif(session, notification_type, path, vals, - timestamp, nullptr); - }; + auto callback = [=](sysrepo::S_Session session, + sr_ev_notif_type_t const notification_type, + char const* path, + sysrepo::S_Vals const vals, + time_t timestamp) { + NetconfAgentCallback agent(service_pair); + return agent.event_notif(session, notification_type, path, vals, timestamp, nullptr); + }; try { // The alternative event_notif_subscribe_tree() might expose more data // as S_Data_Node if needed. - subscription->event_notif_subscribe(model.c_str(), - event_notif_callback); + subscription->event_notif_subscribe(model.c_str(), callback); } catch (const std::exception& ex) { ostringstream msg; msg << "event notification subscription for model " << model << @@ -540,7 +539,7 @@ NetconfAgent::change(S_Session sess, const CfgServersMapPair& service_pair) { LOG_ERROR(netconf_logger, NETCONF_VALIDATE_CONFIG_FAILED) .arg(service_pair.first) .arg(msg.str()); - return SR_ERR_OPERATION_FAILED; + return (SR_ERR_OPERATION_FAILED); } else { LOG_DEBUG(netconf_logger, NETCONF_DBG_TRACE_DETAIL_DATA, NETCONF_VALIDATE_CONFIG) diff --git a/src/bin/netconf/netconf.h b/src/bin/netconf/netconf.h index d8cfc37611..81621163ff 100644 --- a/src/bin/netconf/netconf.h +++ b/src/bin/netconf/netconf.h @@ -114,6 +114,8 @@ protected: /// @brief Retrieve names and revisions of installed modules through the /// sysrepo API. + /// + /// @throw Unexpected if module information cannot be retrieved from sysrepo void getModules(); /// @brief Check module availability. @@ -124,6 +126,9 @@ protected: /// @param servers the configured servers to check against YANG_REVISIONS. /// Is empty by default for when the caller only wants to check /// installed modules. + /// + /// @throw Unexpected if a module from YANG_REVISIONS is not installed or + /// has the wrong revision. void checkModules(CfgServersMapPtr const& servers = {}) const; /// @brief Retrieve Kea server configuration from the YANG startup diff --git a/src/lib/yang/pretests/sysrepo_setup_tests.cc b/src/lib/yang/pretests/sysrepo_setup_tests.cc index 1527c063de..4ef9bd3003 100644 --- a/src/lib/yang/pretests/sysrepo_setup_tests.cc +++ b/src/lib/yang/pretests/sysrepo_setup_tests.cc @@ -78,7 +78,7 @@ int main() { } catch (const sysrepo_exception& ex) { cerr << "ERROR: Can't initialize sysrepo: " << ex.what() << endl; cerr << "ERROR: Make sure you have the right permissions to the sysrepo repository." << endl; - return 1; + return (1); } S_Session sess; @@ -87,7 +87,7 @@ int main() { } catch (const sysrepo_exception& ex) { cerr << "ERROR: Can't establish a sysrepo session: " << ex.what() << endl; - return 2; + return (2); } vector modules; @@ -96,19 +96,19 @@ int main() { modules = context->get_module_iter(); } catch (const sysrepo_exception& ex) { cerr << "ERROR: Can't retrieve available modules: " << ex.what() << endl; - return 3; + return (3); } std::unordered_map installed_modules; for (S_Module const& module : modules) { if (!module->name()) { cerr << "ERROR: module name is mangled" << endl; - return 4; + return (4); } string const name(module->name()); if (!module->rev() || !module->rev()->date()) { cerr << "ERROR: module revision is mangled" << endl; - return 5; + return (5); } string const revision(module->rev()->date()); installed_modules.emplace(name, revision); @@ -119,12 +119,12 @@ int main() { std::string const& revision(kv.second); if (!installed_modules.count(name)) { cerr << missingModuleText(name, revision); - return 6; + return (6); } string const& expected_revision(installed_modules.at(name)); if (expected_revision != revision) { cerr << badRevisionModuleText(name, expected_revision, revision); - return 7; + return (7); } } diff --git a/src/lib/yang/tests/translator_unittests.cc b/src/lib/yang/tests/translator_unittests.cc index 3deed28eff..f5c96293e1 100644 --- a/src/lib/yang/tests/translator_unittests.cc +++ b/src/lib/yang/tests/translator_unittests.cc @@ -313,7 +313,8 @@ TEST(TranslatorBasicTest, getItem) { // Not found. xpath = "/keatest-module:main/no_such_string"; - // sysrepo_exception: "Invalid argument" ¯\_(ツ)_/¯ + + // sysrepo_exception: "Invalid argument" EXPECT_THROW(sess->delete_item(xpath.c_str()), sysrepo_exception); EXPECT_THROW(elem = t_obj->getItem(xpath), SysrepoError); EXPECT_FALSE(elem); @@ -595,7 +596,8 @@ TEST(TranslatorBasicTest, setItem) { sess->set_item_str(xpath.c_str(), "2"); sess->set_item_str(xpath.c_str(), "3"); sess->apply_changes(); - // sysrepo_exception: "Invalid argument" ¯\_(ツ)_/¯ + + // sysrepo_exception: "Invalid argument" EXPECT_THROW(data_node = sess->get_subtree(xpath.c_str()), sysrepo_exception); EXPECT_FALSE(data_node); @@ -646,7 +648,8 @@ TEST(TranslatorBasicTest, setItem) { EXPECT_TRUE(s_val); s_val.reset(); EXPECT_NO_THROW(t_obj->delItem(xpath)); - // sysrepo_exception: "Item not found" ¯\_(ツ)_/¯ + + // sysrepo_exception: "Item not found" EXPECT_THROW(s_val = sess->get_item(xpath.c_str()), sysrepo_exception); EXPECT_FALSE(s_val); EXPECT_NO_THROW(t_obj->delItem(xpath));