From d67f8aca89f47ff45619e4e8bb192161e08e38c7 Mon Sep 17 00:00:00 2001 From: Andrei Pavel Date: Thu, 24 Nov 2022 19:03:44 +0200 Subject: [PATCH] [#2601] address review comments * make all-keys.json loadable by Kea again * formatting * EXPECT_NO_THROW -> EXPECT_NO_THROW_LOG * add missing YANG tests for i64 and ui64 * memmove -> memcpy * fix doxygen comments * make checking of empty containers consistent when retrieving YANG data * remove unnecessary setting of v6 YANG nodes for v4 modules * fix hash of keatest-module.yang --- doc/examples/kea4/all-keys-netconf.json | 12 ++++--- doc/examples/kea4/all-keys.json | 12 ++++--- doc/examples/kea6/all-keys-netconf.json | 11 +++++-- doc/examples/kea6/all-keys.json | 11 +++++-- src/bin/dhcp4/tests/dhcp4_srv_unittest.cc | 1 + src/bin/dhcp6/tests/dhcp6_srv_unittest.cc | 1 + src/bin/netconf/Makefile.am | 1 - src/bin/netconf/netconf.cc | 1 - .../netconf/tests/control_socket_unittests.cc | 3 +- src/bin/netconf/tests/get_config_unittest.cc | 6 ++-- .../tests/netconf_cfg_mgr_unittests.cc | 2 +- .../tests/netconf_controller_unittests.cc | 1 - src/bin/netconf/tests/netconf_unittests.cc | 1 - src/lib/yang/adaptor_config.h | 2 +- src/lib/yang/adaptor_host.h | 2 +- src/lib/yang/adaptor_option.h | 2 +- src/lib/yang/adaptor_pool.cc | 2 +- src/lib/yang/pretests/Makefile.am | 4 --- .../yang/tests/adaptor_config_unittests.cc | 1 - src/lib/yang/tests/config_unittests.cc | 2 +- src/lib/yang/tests/translator_unittests.cc | 30 ++++++++--------- .../yang/tests/translator_utils_unittests.cc | 12 +++++++ src/lib/yang/tests/yang_configs.h | 4 +++ src/lib/yang/testutils/translator_test.cc | 6 ++-- src/lib/yang/translator.cc | 28 ++++++++-------- src/lib/yang/translator.h | 33 ++++++++++--------- src/lib/yang/translator_class.cc | 4 +-- src/lib/yang/translator_config.cc | 24 +++++++------- src/lib/yang/translator_control_socket.cc | 2 +- src/lib/yang/translator_database.cc | 4 +-- src/lib/yang/translator_database.h | 1 - src/lib/yang/translator_host.cc | 4 +-- src/lib/yang/translator_logger.cc | 2 +- src/lib/yang/translator_option_data.cc | 4 +-- src/lib/yang/translator_option_def.cc | 4 +-- src/lib/yang/translator_option_def.h | 1 - src/lib/yang/translator_pd_pool.cc | 4 +-- src/lib/yang/translator_pool.cc | 4 +-- src/lib/yang/translator_shared_network.cc | 4 +-- src/lib/yang/translator_subnet.cc | 8 ++--- src/lib/yang/yang.dox | 6 ++-- .../hashes/keatest-module@2022-11-30.hash | 2 +- 42 files changed, 141 insertions(+), 128 deletions(-) diff --git a/doc/examples/kea4/all-keys-netconf.json b/doc/examples/kea4/all-keys-netconf.json index 732e057281..7e9b6b7b17 100644 --- a/doc/examples/kea4/all-keys-netconf.json +++ b/doc/examples/kea4/all-keys-netconf.json @@ -83,7 +83,6 @@ // class when the given expression evaluates to true. "test": "member('HA_server2')" }, - { // Third class name. "name": "late", @@ -96,10 +95,15 @@ "only-if-required": true, // Class selection expression. - "test": "member('ALL')", + "test": "member('ALL')" + }, + { + // Fourth class name. + "name": "my-template-class", - // Template class flag. - "template-test": "" + // Template class flag that holds the expression used to generate the names for all + // the spawned subclasses. In this case, the classes are named after the client ID. + "template-test": "substring(option[1].hex, 0, all)" } ], diff --git a/doc/examples/kea4/all-keys.json b/doc/examples/kea4/all-keys.json index 47fed5debe..960c14e4ad 100644 --- a/doc/examples/kea4/all-keys.json +++ b/doc/examples/kea4/all-keys.json @@ -83,7 +83,6 @@ // class when the given expression evaluates to true. "test": "member('HA_server2')" }, - { // Third class name. "name": "late", @@ -96,10 +95,15 @@ "only-if-required": true, // Class selection expression. - "test": "member('ALL')", + "test": "member('ALL')" + }, + { + // Fourth class name. + "name": "my-template-class", - // Template class flag. - "template-test": "" + // Template class flag that holds the expression used to generate the names for all + // the spawned subclasses. In this case, the classes are named after the client ID. + "template-test": "substring(option[61].hex, 0, all)" } ], diff --git a/doc/examples/kea6/all-keys-netconf.json b/doc/examples/kea6/all-keys-netconf.json index 51ebf5d795..b3a043cd40 100644 --- a/doc/examples/kea6/all-keys-netconf.json +++ b/doc/examples/kea6/all-keys-netconf.json @@ -65,10 +65,15 @@ "only-if-required": true, // Class selection expression. - "test": "member('ALL')", + "test": "member('ALL')" + }, + { + // Fourth class name. + "name": "my-template-class", - // Template class flag. - "template-test": "" + // Template class flag that holds the expression used to generate the names for all + // the spawned subclasses. In this case, the classes are named after the client ID. + "template-test": "substring(option[1].hex, 0, all)" } ], diff --git a/doc/examples/kea6/all-keys.json b/doc/examples/kea6/all-keys.json index fe0a6f424e..07c9cade38 100644 --- a/doc/examples/kea6/all-keys.json +++ b/doc/examples/kea6/all-keys.json @@ -65,10 +65,15 @@ "only-if-required": true, // Class selection expression. - "test": "member('ALL')", + "test": "member('ALL')" + }, + { + // Fourth class name. + "name": "my-template-class", - // Template class flag. - "template-test": "" + // Template class flag that holds the expression used to generate the names for all + // the spawned subclasses. In this case, the classes are named after the client ID. + "template-test": "substring(option[1].hex, 0, all)" } ], diff --git a/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc b/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc index 9812e4844d..a6840f6b29 100644 --- a/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc +++ b/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc @@ -2907,6 +2907,7 @@ Dhcpv4SrvTest::checkConfigFiles() { vector examples = { "advanced.json", #if defined (HAVE_MYSQL) && defined (HAVE_PGSQL) + "all-keys.json", "all-keys-netconf.json", "all-options.json", #endif diff --git a/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc b/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc index 69bd8a567b..498b57ea2c 100644 --- a/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc +++ b/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc @@ -292,6 +292,7 @@ Dhcpv6SrvTest::checkConfigFiles() { vector examples = { "advanced.json", #if defined (HAVE_MYSQL) && defined (HAVE_PGSQL) + "all-keys.json", "all-keys-netconf.json", "all-options.json", #endif diff --git a/src/bin/netconf/Makefile.am b/src/bin/netconf/Makefile.am index 8475234bcb..859d567ec0 100644 --- a/src/bin/netconf/Makefile.am +++ b/src/bin/netconf/Makefile.am @@ -71,7 +71,6 @@ kea_netconf_LDADD += $(LIBYANGCPP_LIBS) kea_netconf_LDADD += $(SYSREPO_LIBS) kea_netconf_LDADD += $(SYSREPOCPP_LIBS) - kea_netconfdir = $(pkgdatadir) # If we want to get rid of all generated messages files, we need to use diff --git a/src/bin/netconf/netconf.cc b/src/bin/netconf/netconf.cc index e84207e092..5d8e3fd2a6 100644 --- a/src/bin/netconf/netconf.cc +++ b/src/bin/netconf/netconf.cc @@ -463,7 +463,6 @@ NetconfAgent::subscribeToDataChanges(const CfgServersMapPair& service_pair) { } } - void NetconfAgent::subscribeToNotifications(const CfgServersMapPair& service_pair) { string const& server(service_pair.first); diff --git a/src/bin/netconf/tests/control_socket_unittests.cc b/src/bin/netconf/tests/control_socket_unittests.cc index aa25f37e25..8a95d9bb4b 100644 --- a/src/bin/netconf/tests/control_socket_unittests.cc +++ b/src/bin/netconf/tests/control_socket_unittests.cc @@ -147,7 +147,6 @@ public: : ThreadedTest(), io_service_() { } - void SetUp() override { SysrepoSetup::cleanSharedMemory(); removeUnixSocketFile(); @@ -428,7 +427,7 @@ public: /// @brief Create a new request. /// /// @return Pointer to the new instance of the HttpRequest. - HttpRequestPtr createNewHttpRequest() const override final { + HttpRequestPtr createNewHttpRequest() const override final { return (HttpRequestPtr(new PostHttpRequestJson())); } diff --git a/src/bin/netconf/tests/get_config_unittest.cc b/src/bin/netconf/tests/get_config_unittest.cc index 5ee3398803..2eaa7b1d65 100644 --- a/src/bin/netconf/tests/get_config_unittest.cc +++ b/src/bin/netconf/tests/get_config_unittest.cc @@ -221,9 +221,9 @@ public: EXPECT_TRUE(executeConfiguration(config, "reset config")); } - unique_ptr srv_; ///< Netconf server under test - int rcode_; ///< Return code from element parsing - ConstElementPtr comment_; ///< Reason for parse fail + unique_ptr srv_; ///< Netconf server under test + int rcode_; ///< Return code from element parsing + ConstElementPtr comment_; ///< Reason for parse fail }; // NetconfGetCfgTest // Test a simple configuration. diff --git a/src/bin/netconf/tests/netconf_cfg_mgr_unittests.cc b/src/bin/netconf/tests/netconf_cfg_mgr_unittests.cc index 4068a0825e..897e2921de 100644 --- a/src/bin/netconf/tests/netconf_cfg_mgr_unittests.cc +++ b/src/bin/netconf/tests/netconf_cfg_mgr_unittests.cc @@ -363,7 +363,7 @@ TEST(NetconfParser, badSocketType) { ElementPtr json; ParserContext parser; EXPECT_NO_THROW_LOG(json = parser.parseString(NETCONF_CONFIGS[10], - ParserContext::PARSER_JSON)); + ParserContext::PARSER_JSON)); ConstElementPtr answer; NakedNetconfCfgMgr cfg_mgr; EXPECT_NO_THROW_LOG(answer = cfg_mgr.parse(json, false)); diff --git a/src/bin/netconf/tests/netconf_controller_unittests.cc b/src/bin/netconf/tests/netconf_controller_unittests.cc index 922e19f528..03002f7c4c 100644 --- a/src/bin/netconf/tests/netconf_controller_unittests.cc +++ b/src/bin/netconf/tests/netconf_controller_unittests.cc @@ -104,7 +104,6 @@ TEST_F(NetconfControllerTest, basicInstanceTesting) { EXPECT_FALSE(checkProcess()); } - // Tests basic command line processing. // Verifies that: // 1. Standard command line options are supported. diff --git a/src/bin/netconf/tests/netconf_unittests.cc b/src/bin/netconf/tests/netconf_unittests.cc index d905bc0bfa..b1bff51898 100644 --- a/src/bin/netconf/tests/netconf_unittests.cc +++ b/src/bin/netconf/tests/netconf_unittests.cc @@ -87,7 +87,6 @@ void clearYang(NakedNetconfAgentPtr agent) { } } - // Empirically the requested subnets have sometimes returned in decreasing // order of subnet ID. To avoid flaky test failures, sort them before // comparing. diff --git a/src/lib/yang/adaptor_config.h b/src/lib/yang/adaptor_config.h index 930e4245df..4848250ce7 100644 --- a/src/lib/yang/adaptor_config.h +++ b/src/lib/yang/adaptor_config.h @@ -280,7 +280,7 @@ protected: const std::string& space); }; // AdaptorConfig -} //namespace yang +} // namespace yang } // namespace isc #endif // ISC_ADAPTOR_CONFIG_H diff --git a/src/lib/yang/adaptor_host.h b/src/lib/yang/adaptor_host.h index bbd96642b2..75dee523c1 100644 --- a/src/lib/yang/adaptor_host.h +++ b/src/lib/yang/adaptor_host.h @@ -38,7 +38,7 @@ public: static void quoteIdentifier(isc::data::ElementPtr host); }; // AdaptorHost -} //namespace yang +} // namespace yang } // namespace isc #endif // ISC_ADAPTOR_HOST_H diff --git a/src/lib/yang/adaptor_option.h b/src/lib/yang/adaptor_option.h index 1dedf19873..6acbeefed2 100644 --- a/src/lib/yang/adaptor_option.h +++ b/src/lib/yang/adaptor_option.h @@ -96,7 +96,7 @@ protected: size_t params_size); }; // AdaptorOption -} //namespace yang +} // namespace yang } // namespace isc #endif // ISC_ADAPTOR_OPTION_H diff --git a/src/lib/yang/adaptor_pool.cc b/src/lib/yang/adaptor_pool.cc index 54966afc5a..6d9aeaee28 100644 --- a/src/lib/yang/adaptor_pool.cc +++ b/src/lib/yang/adaptor_pool.cc @@ -79,5 +79,5 @@ AdaptorPool::toSubnetIetf6(ElementPtr subnet, ConstElementPtr pools) { Adaptor::toParent("rebind-timer", subnet, pools); } -} //namespace yang +} // namespace yang } // namespace isc diff --git a/src/lib/yang/pretests/Makefile.am b/src/lib/yang/pretests/Makefile.am index cc28db62ae..17c9b202b5 100644 --- a/src/lib/yang/pretests/Makefile.am +++ b/src/lib/yang/pretests/Makefile.am @@ -1,7 +1,3 @@ - - - - CLEANFILES = *.gcno *.gcda TESTS = sysrepo_setup_tests diff --git a/src/lib/yang/tests/adaptor_config_unittests.cc b/src/lib/yang/tests/adaptor_config_unittests.cc index 115083a663..d4ab70854e 100644 --- a/src/lib/yang/tests/adaptor_config_unittests.cc +++ b/src/lib/yang/tests/adaptor_config_unittests.cc @@ -23,7 +23,6 @@ using namespace isc::yang; namespace { - /// @brief Fixture class that helps testing AdaptorConfig class AdaptorConfigTest : public ::testing::Test { public: diff --git a/src/lib/yang/tests/config_unittests.cc b/src/lib/yang/tests/config_unittests.cc index 1d4214bec0..176e4181ab 100644 --- a/src/lib/yang/tests/config_unittests.cc +++ b/src/lib/yang/tests/config_unittests.cc @@ -188,7 +188,7 @@ struct ConfigTestKeaV4 : ConfigTest { ConfigTestKeaV4() { model_ = KEA_DHCP4_SERVER; } -}; // ConfigTestKeav4 +}; // ConfigTestKeaV4 struct ConfigTestKeaV6 : ConfigTest { ConfigTestKeaV6() { model_ = KEA_DHCP6_SERVER; diff --git a/src/lib/yang/tests/translator_unittests.cc b/src/lib/yang/tests/translator_unittests.cc index 2fec24f281..936a9b4129 100644 --- a/src/lib/yang/tests/translator_unittests.cc +++ b/src/lib/yang/tests/translator_unittests.cc @@ -354,7 +354,7 @@ TEST_F(TranslatorTest, getItem) { EXPECT_FALSE(element); } - +// Check the Translator::deleteItem function. TEST_F(TranslatorTest, deleteItem) { ElementPtr got; string xpath; @@ -363,31 +363,31 @@ TEST_F(TranslatorTest, deleteItem) { Translator translator(Connection{}.sessionStart(), "keatest-module"); // Missing schema node - EXPECT_NO_THROW(translator.deleteItem("/keatest-module:main/no_such_node")); + EXPECT_NO_THROW_LOG(translator.deleteItem("/keatest-module:main/no_such_node")); // Existing schema node, but no data xpath = "/keatest-module:main/string"; - EXPECT_NO_THROW(translator.deleteItem(xpath)); + EXPECT_NO_THROW_LOG(translator.deleteItem(xpath)); EXPECT_NO_THROW_LOG(got = translator.getItemFromAbsoluteXpath(xpath)); EXPECT_FALSE(got); got.reset(); // Existing schema node, existing data translator.setItem(xpath, Element::create("value"), LeafBaseType::String); - EXPECT_NO_THROW(translator.deleteItem(xpath)); + EXPECT_NO_THROW_LOG(translator.deleteItem(xpath)); EXPECT_NO_THROW_LOG(got = translator.getItemFromAbsoluteXpath(xpath)); EXPECT_FALSE(got); got.reset(); // Container schema node, no data - EXPECT_NO_THROW(translator.deleteItem("/keatest-module:main")); + EXPECT_NO_THROW_LOG(translator.deleteItem("/keatest-module:main")); EXPECT_NO_THROW_LOG(got = translator.getItemFromAbsoluteXpath(xpath)); EXPECT_FALSE(got); got.reset(); // Container schema node, existing data translator.setItem(xpath, Element::create("value"), LeafBaseType::String); - EXPECT_NO_THROW(translator.deleteItem("/keatest-module:main")); + EXPECT_NO_THROW_LOG(translator.deleteItem("/keatest-module:main")); EXPECT_NO_THROW_LOG(got = translator.getItemFromAbsoluteXpath(xpath)); EXPECT_FALSE(got); got.reset(); @@ -466,7 +466,7 @@ TEST_F(TranslatorTest, valueTo) { EXPECT_EQ(element->str(), value); element.reset(); - // Signed 32 bit integer. + // Signed 64 bit integer. element = Element::create(int64_t(-1234567890123456)); EXPECT_NO_THROW_LOG(value = Translator::translateToYang(element, LeafBaseType::Int64)); EXPECT_EQ("-1234567890123456", value); @@ -822,8 +822,7 @@ TEST_F(TranslatorTest, container) { Translator translator(Connection{}.sessionStart(), "keatest-module"); // Container with no data apparently throws. - EXPECT_THROW_MSG(element = translator.getItemFromAbsoluteXpath("/keatest-module:container"), - NotImplemented, + EXPECT_THROW_MSG(element = translator.getItemFromAbsoluteXpath("/keatest-module:container"), NotImplemented, "getting node of type 1 not supported, xpath is '/keatest-module:container'"); EXPECT_FALSE(element); element.reset(); @@ -839,13 +838,12 @@ TEST_F(TranslatorTest, container) { element, LeafBaseType::String)); element.reset(); EXPECT_THROW_MSG( - element = translator.getItemFromAbsoluteXpath("/keatest-module:container"), - NotImplemented, + element = translator.getItemFromAbsoluteXpath("/keatest-module:container"), NotImplemented, "getting node of type 1 not supported, xpath is '/keatest-module:container'"); EXPECT_FALSE(element); element.reset(); - EXPECT_NO_THROW_LOG(element = translator.getItemFromAbsoluteXpath("/keatest-module:container[key1=" - "'key1'][key2='key2']")); + EXPECT_NO_THROW_LOG( + element = translator.getItemFromAbsoluteXpath("/keatest-module:container[key1='key1'][key2='key2']")); EXPECT_FALSE(element); } @@ -869,14 +867,12 @@ TEST_F(TranslatorTest, list) { LeafBaseType::String)); element.reset(); EXPECT_THROW_MSG( - element = translator.getItemFromAbsoluteXpath("/keatest-module:container/list"), - NotImplemented, + element = translator.getItemFromAbsoluteXpath("/keatest-module:container/list"), NotImplemented, "getting node of type 16 not supported, xpath is '/keatest-module:container/list'"); EXPECT_FALSE(element); element.reset(); EXPECT_THROW_MSG(element = translator.getItemFromAbsoluteXpath( - "/keatest-module:container/list[key1='key1'][key2='key2']"), - NotImplemented, + "/keatest-module:container/list[key1='key1'][key2='key2']"), NotImplemented, "getting node of type 16 not supported, xpath is " "'/keatest-module:container/list[key1='key1'][key2='key2']'"); EXPECT_FALSE(element); diff --git a/src/lib/yang/tests/translator_utils_unittests.cc b/src/lib/yang/tests/translator_utils_unittests.cc index db050a1743..1f92e3d4c3 100644 --- a/src/lib/yang/tests/translator_utils_unittests.cc +++ b/src/lib/yang/tests/translator_utils_unittests.cc @@ -112,6 +112,12 @@ TEST(YangReprTest, getTest) { EXPECT_NO_THROW_LOG(sess.setItem(xpath, value)); EXPECT_NO_THROW_LOG(sess.applyChanges()); + xpath = "/keatest-module:main/ui64"; + uint32_t u64(64); + value = to_string(u64); + EXPECT_NO_THROW_LOG(sess.setItem(xpath, value)); + EXPECT_NO_THROW_LOG(sess.applyChanges()); + xpath = "/keatest-module:main/i8"; int8_t s8(8); value = to_string(s8); @@ -130,6 +136,12 @@ TEST(YangReprTest, getTest) { EXPECT_NO_THROW_LOG(sess.setItem(xpath, value)); EXPECT_NO_THROW_LOG(sess.applyChanges()); + xpath = "/keatest-module:main/i64"; + int32_t s64(64); + value = to_string(s64); + EXPECT_NO_THROW_LOG(sess.setItem(xpath, value)); + EXPECT_NO_THROW_LOG(sess.applyChanges()); + xpath = "/keatest-module:main/id_ref"; value = "keatest-module:id_1"; EXPECT_NO_THROW_LOG(sess.setItem(xpath, value)); diff --git a/src/lib/yang/tests/yang_configs.h b/src/lib/yang/tests/yang_configs.h index 994a8939ed..c3bb0530c7 100644 --- a/src/lib/yang/tests/yang_configs.h +++ b/src/lib/yang/tests/yang_configs.h @@ -33,12 +33,16 @@ const YRTree testTree = YangRepr::buildTreeFromVector({ "16", libyang::LeafBaseType::Uint16, true }, { "/keatest-module:main/ui32", "32", libyang::LeafBaseType::Uint32, true }, + { "/keatest-module:main/ui64", + "64", libyang::LeafBaseType::Uint64, true }, { "/keatest-module:main/i8", "8", libyang::LeafBaseType::Int8, true }, { "/keatest-module:main/i16", "16", libyang::LeafBaseType::Int16, true }, { "/keatest-module:main/i32", "32", libyang::LeafBaseType::Int32, true }, + { "/keatest-module:main/i64", + "64", libyang::LeafBaseType::Int64, true }, { "/keatest-module:main/id_ref", "keatest-module:id_1", libyang::LeafBaseType::IdentityRef, true }, { "/keatest-module:main/enum", diff --git a/src/lib/yang/testutils/translator_test.cc b/src/lib/yang/testutils/translator_test.cc index aa0e1ca8a9..36012db557 100644 --- a/src/lib/yang/testutils/translator_test.cc +++ b/src/lib/yang/testutils/translator_test.cc @@ -99,12 +99,10 @@ YangRepr::YangReprItem::get(const string& xpath, Session session) { // Get the underlying type. type = data_node->schema().asLeaf().valueType().asLeafRef().resolvedType().base(); } - value = Translator::translateToYang(Translator::translateFromYang(data_node), - type); + value = Translator::translateToYang(Translator::translateFromYang(data_node), type); val_xpath = string(data_node->path()); } catch (Error const& ex) { - isc_throw(NetconfError, - "in YangReprItem: " << ex.what()); + isc_throw(NetconfError, "in YangReprItem: " << ex.what()); } return (YangReprItem(val_xpath, value, type, settable)); } diff --git a/src/lib/yang/translator.cc b/src/lib/yang/translator.cc index abc40d714b..aa87f19311 100644 --- a/src/lib/yang/translator.cc +++ b/src/lib/yang/translator.cc @@ -59,17 +59,6 @@ Translator::checkAndGetAndJsonifyLeaf(ElementPtr& storage, } } -void -Translator::checkAndStringifyAndSetLeaf(ConstElementPtr const& from, - string const& xpath, - string const& name) { - ConstElementPtr const& x(from->get(name)); - if (x) { - ElementPtr const& json(Element::create(x->str())); - setItem(xpath + "/" + name, json, LeafBaseType::String); - } -} - void Translator::checkAndSetLeaf(ConstElementPtr const& from, string const& xpath, string const& name, @@ -113,8 +102,18 @@ void Translator::checkAndSetUserContext(ConstElementPtr const& from, } void -Translator::deleteItem(string const& xpath) { +Translator::checkAndStringifyAndSetLeaf(ConstElementPtr const& from, + string const& xpath, + string const& name) { + ConstElementPtr const& x(from->get(name)); + if (x) { + ElementPtr const& json(Element::create(x->str())); + setItem(xpath + "/" + name, json, LeafBaseType::String); + } +} +void +Translator::deleteItem(string const& xpath) { try { if (session_.getData(xpath)) { session_.deleteItem(xpath); @@ -201,7 +200,6 @@ Translator::getMandatoryLeaf(ElementPtr& storage, storage->set(name, x); } - void Translator::getMandatoryDivergingLeaf(ElementPtr& storage, DataNode const& data_node, @@ -310,7 +308,7 @@ Translator::decode64(string const& input) { decodeBase64(input, binary); string result; result.resize(binary.size()); - memmove(&result[0], &binary[0], result.size()); + memcpy(&result[0], &binary[0], result.size()); return (result); } @@ -318,7 +316,7 @@ string Translator::encode64(string const& input) { vector binary; binary.resize(input.size()); - memmove(&binary[0], input.c_str(), binary.size()); + memcpy(&binary[0], input.c_str(), binary.size()); return (encodeBase64(binary)); } diff --git a/src/lib/yang/translator.h b/src/lib/yang/translator.h index d092092768..688f86d2ce 100644 --- a/src/lib/yang/translator.h +++ b/src/lib/yang/translator.h @@ -119,19 +119,8 @@ public: /// /// @param from the parent configuration node from which to take the value /// @param xpath the xpath to the YANG node without the last node - /// @param name the name of the YANG node which should also match the map - /// key in the JSON configuration - void checkAndStringifyAndSetLeaf(isc::data::ConstElementPtr const& from, - std::string const& xpath, - std::string const& name); - - /// @brief Get an element from given ElementPtr node and set it in sysrepo - /// at given xpath. - /// - /// @param from the parent configuration node from which to take the value - /// @param xpath the xpath to the YANG node without the last node - /// @param name the name of the YANG node which should also match the map - /// key in the JSON configuration + /// @param name the name of the YANG node which should also match the key + /// under which data is set in the MapElement {from} /// @param type the YANG node type void checkAndSetLeaf(isc::data::ConstElementPtr const& from, std::string const& xpath, @@ -146,8 +135,8 @@ public: /// /// @param from the parent configuration node from which to take the value /// @param xpath the xpath to the YANG node without the last node - /// @param name the name of the parameter to be set in storage - /// @param yang_name the name by which to find the parameter in the YANG data node + /// @param name the key under which data is set in the MapElement {from} + /// @param yang_name the name of the YANG node /// @param type the YANG node type void checkAndSetDivergingLeaf(isc::data::ConstElementPtr const& from, std::string const& xpath, @@ -160,7 +149,8 @@ public: /// /// @param from the parent configuration node from which to take the values /// @param xpath the xpath to the YANG node without the last node - /// @param name the name of the parameter to be set in storage + /// @param name the name of the YANG node which should also match the key + /// under which data is set in the MapElement {from} /// @param type the YANG node type of the underlying leaf-list nodes void checkAndSetLeafList(isc::data::ConstElementPtr const& from, std::string const& xpath, @@ -175,6 +165,17 @@ public: void checkAndSetUserContext(isc::data::ConstElementPtr const& from, std::string const& xpath); + /// @brief Get an element from given ElementPtr node and set it in sysrepo + /// at given xpath. + /// + /// @param from the parent configuration node from which to take the value + /// @param xpath the xpath to the YANG node without the last node + /// @param name the name of the YANG node which should also match the key + /// under which data is set in the MapElement {from} + void checkAndStringifyAndSetLeaf(isc::data::ConstElementPtr const& from, + std::string const& xpath, + std::string const& name); + /// @brief Delete basic value from YANG. /// /// @param xpath The xpath of the basic value. diff --git a/src/lib/yang/translator_class.cc b/src/lib/yang/translator_class.cc index 6aa8bc08b3..40edca9b03 100644 --- a/src/lib/yang/translator_class.cc +++ b/src/lib/yang/translator_class.cc @@ -47,7 +47,7 @@ ElementPtr TranslatorClass::getClassFromAbsoluteXpath(string const& xpath) { try { return getClass(findXPath(xpath)); - } catch(NetconfError const&) { + } catch (NetconfError const&) { return ElementPtr(); } } @@ -170,7 +170,7 @@ ElementPtr TranslatorClasses::getClassesFromAbsoluteXpath(string const& xpath) { try { return getClasses(findXPath(xpath)); - } catch(NetconfError const&) { + } catch (NetconfError const&) { return ElementPtr(); } } diff --git a/src/lib/yang/translator_config.cc b/src/lib/yang/translator_config.cc index d2d18fd9f6..13a29d82bf 100644 --- a/src/lib/yang/translator_config.cc +++ b/src/lib/yang/translator_config.cc @@ -71,7 +71,7 @@ TranslatorConfig::getConfigIetf6() { optional config; try { config = findXPath(xpath); - } catch(NetconfError const&) { + } catch (NetconfError const&) { return result; } @@ -180,7 +180,7 @@ TranslatorConfig::getInterfacesKea(DataNode const& config) { checkAndGetAndJsonifyLeaf(result, interfaces_config, "user-context"); } - return result; + return (result->empty() ? ElementPtr() : result); } ElementPtr @@ -289,22 +289,22 @@ TranslatorConfig::getServerKeaDhcpCommon(DataNode const& data_node) { }); ConstElementPtr options = getOptionDataList(data_node); - if (options && !options->empty()) { + if (options) { result->set("option-data", options); } ConstElementPtr defs = getOptionDefList(data_node); - if (defs && !defs->empty()) { + if (defs) { result->set("option-def", defs); } ConstElementPtr hosts = getHosts(data_node); - if (hosts && !hosts->empty()) { + if (hosts) { result->set("reservations", hosts); } ConstElementPtr networks = getSharedNetworks(data_node); - if (networks && !networks->empty()) { + if (networks) { result->set("shared-networks", networks); } @@ -325,7 +325,7 @@ TranslatorConfig::getServerKeaDhcp4() { optional config_optional; try { config_optional = findXPath(xpath); - } catch(NetconfError const&) { + } catch (NetconfError const&) { return ElementPtr(); } DataNode const config(*config_optional); @@ -341,13 +341,13 @@ TranslatorConfig::getServerKeaDhcp4() { // Handle interfaces. ElementPtr interfaces_config(getInterfacesKea(config)); - if (interfaces_config && !interfaces_config->empty()) { + if (interfaces_config) { result->set("interfaces-config", interfaces_config); } // Handle subnets. ConstElementPtr subnets = getSubnets(config); - if (subnets && !subnets->empty()) { + if (subnets) { result->set("subnet4", subnets); } @@ -360,7 +360,7 @@ TranslatorConfig::getServerKeaDhcp6() { optional config_optional; try { config_optional = findXPath(xpath); - } catch(NetconfError const&) { + } catch (NetconfError const&) { return ElementPtr(); } DataNode const config(*config_optional); @@ -376,7 +376,7 @@ TranslatorConfig::getServerKeaDhcp6() { // Handle interfaces. ElementPtr interfaces_config(getInterfacesKea(config)); - if (interfaces_config && !interfaces_config->empty()) { + if (interfaces_config) { result->set("interfaces-config", interfaces_config); } @@ -399,7 +399,7 @@ TranslatorConfig::getServerKeaDhcp6() { // Handle subnets. ConstElementPtr subnets = getSubnets(config); - if (subnets && !subnets->empty()) { + if (subnets) { result->set("subnet6", subnets); } diff --git a/src/lib/yang/translator_control_socket.cc b/src/lib/yang/translator_control_socket.cc index e3dabdf6ff..2d44b2f567 100644 --- a/src/lib/yang/translator_control_socket.cc +++ b/src/lib/yang/translator_control_socket.cc @@ -54,7 +54,7 @@ ElementPtr TranslatorControlSocket::getControlSocketFromAbsoluteXpath(string const& xpath) { try { return getControlSocket(findXPath(xpath)); - } catch(NetconfError const&) { + } catch (NetconfError const&) { return ElementPtr(); } } diff --git a/src/lib/yang/translator_database.cc b/src/lib/yang/translator_database.cc index ad5dd86efd..1e6bb6e4cd 100644 --- a/src/lib/yang/translator_database.cc +++ b/src/lib/yang/translator_database.cc @@ -42,7 +42,7 @@ ElementPtr TranslatorDatabase::getDatabaseFromAbsoluteXpath(string const& xpath) { try { return getDatabase(findXPath(xpath)); - } catch(NetconfError const&) { + } catch (NetconfError const&) { return ElementPtr(); } } @@ -155,7 +155,7 @@ ElementPtr TranslatorDatabases::getDatabasesFromAbsoluteXpath(string const& xpath) { try { return getDatabases(findXPath(xpath), xpath); - } catch(NetconfError const&) { + } catch (NetconfError const&) { return ElementPtr(); } } diff --git a/src/lib/yang/translator_database.h b/src/lib/yang/translator_database.h index 6fca6aae7a..7480fa7530 100644 --- a/src/lib/yang/translator_database.h +++ b/src/lib/yang/translator_database.h @@ -9,7 +9,6 @@ #include - namespace isc { namespace yang { diff --git a/src/lib/yang/translator_host.cc b/src/lib/yang/translator_host.cc index 82b84ccf4b..7aa6fa407d 100644 --- a/src/lib/yang/translator_host.cc +++ b/src/lib/yang/translator_host.cc @@ -45,7 +45,7 @@ ElementPtr TranslatorHost::getHostFromAbsoluteXpath(string const& xpath) { try { return getHost(findXPath(xpath)); - } catch(NetconfError const&) { + } catch (NetconfError const&) { return ElementPtr(); } } @@ -144,7 +144,7 @@ ElementPtr TranslatorHosts::getHostsFromAbsoluteXpath(string const& xpath) { try { return getHosts(findXPath(xpath)); - } catch(NetconfError const&) { + } catch (NetconfError const&) { return ElementPtr(); } } diff --git a/src/lib/yang/translator_logger.cc b/src/lib/yang/translator_logger.cc index 7613f5650b..bff43db77d 100644 --- a/src/lib/yang/translator_logger.cc +++ b/src/lib/yang/translator_logger.cc @@ -164,7 +164,7 @@ ConstElementPtr TranslatorLoggers::getLoggersFromAbsoluteXpath(string const& xpath) { try { return getLoggers(findXPath(xpath)); - } catch(NetconfError const&) { + } catch (NetconfError const&) { return ElementPtr(); } } diff --git a/src/lib/yang/translator_option_data.cc b/src/lib/yang/translator_option_data.cc index f401c7dc3a..bc5df73c9a 100644 --- a/src/lib/yang/translator_option_data.cc +++ b/src/lib/yang/translator_option_data.cc @@ -44,7 +44,7 @@ ElementPtr TranslatorOptionData::getOptionDataFromAbsoluteXpath(string const& xpath) { try { return getOptionData(findXPath(xpath)); - } catch(NetconfError const&) { + } catch (NetconfError const&) { return ElementPtr(); } } @@ -124,7 +124,7 @@ ConstElementPtr TranslatorOptionDataList::getOptionDataListFromAbsoluteXpath(string const& xpath) { try { return getOptionDataList(findXPath(xpath)); - } catch(NetconfError const&) { + } catch (NetconfError const&) { return ElementPtr(); } } diff --git a/src/lib/yang/translator_option_def.cc b/src/lib/yang/translator_option_def.cc index 0cf4f69010..70bdd9f1d1 100644 --- a/src/lib/yang/translator_option_def.cc +++ b/src/lib/yang/translator_option_def.cc @@ -44,7 +44,7 @@ ElementPtr TranslatorOptionDef::getOptionDefFromAbsoluteXpath(string const& xpath) { try { return getOptionDef(findXPath(xpath)); - } catch(NetconfError const&) { + } catch (NetconfError const&) { return ElementPtr(); } } @@ -126,7 +126,7 @@ ConstElementPtr TranslatorOptionDefList::getOptionDefListFromAbsoluteXpath(string const& xpath) { try { return getOptionDefList(findXPath(xpath)); - } catch(NetconfError const&) { + } catch (NetconfError const&) { return ElementPtr(); } } diff --git a/src/lib/yang/translator_option_def.h b/src/lib/yang/translator_option_def.h index 700cdd8b0a..b36ba476f0 100644 --- a/src/lib/yang/translator_option_def.h +++ b/src/lib/yang/translator_option_def.h @@ -9,7 +9,6 @@ #include - namespace isc { namespace yang { diff --git a/src/lib/yang/translator_pd_pool.cc b/src/lib/yang/translator_pd_pool.cc index 60380d5b4e..d0f888050e 100644 --- a/src/lib/yang/translator_pd_pool.cc +++ b/src/lib/yang/translator_pd_pool.cc @@ -48,7 +48,7 @@ ElementPtr TranslatorPdPool::getPdPoolFromAbsoluteXpath(string const& xpath) { try { return getPdPool(findXPath(xpath)); - } catch(NetconfError const&) { + } catch (NetconfError const&) { return ElementPtr(); } } @@ -260,7 +260,7 @@ ElementPtr TranslatorPdPools::getPdPoolsFromAbsoluteXpath(string const& xpath) { try { return getPdPools(findXPath(xpath)); - } catch(NetconfError const&) { + } catch (NetconfError const&) { return ElementPtr(); } } diff --git a/src/lib/yang/translator_pool.cc b/src/lib/yang/translator_pool.cc index d8df4b062d..05fdec6a8d 100644 --- a/src/lib/yang/translator_pool.cc +++ b/src/lib/yang/translator_pool.cc @@ -52,7 +52,7 @@ ElementPtr TranslatorPool::getPoolFromAbsoluteXpath(string const& xpath) { try { return getPool(findXPath(xpath)); - } catch(NetconfError const&) { + } catch (NetconfError const&) { return ElementPtr(); } } @@ -253,7 +253,7 @@ ElementPtr TranslatorPools::getPoolsFromAbsoluteXpath(string const& xpath) { try { return getPools(findXPath(xpath)); - } catch(NetconfError const&) { + } catch (NetconfError const&) { return ElementPtr(); } } diff --git a/src/lib/yang/translator_shared_network.cc b/src/lib/yang/translator_shared_network.cc index ec597d8437..f4b19f2d50 100644 --- a/src/lib/yang/translator_shared_network.cc +++ b/src/lib/yang/translator_shared_network.cc @@ -55,7 +55,7 @@ ElementPtr TranslatorSharedNetwork::getSharedNetworkFromAbsoluteXpath(string const& xpath) { try { return getSharedNetwork(findXPath(xpath)); - } catch(NetconfError const&) { + } catch (NetconfError const&) { return ElementPtr(); } } @@ -254,7 +254,7 @@ ElementPtr TranslatorSharedNetworks::getSharedNetworksFromAbsoluteXpath(string const& xpath) { try { return getSharedNetworks(findXPath(xpath)); - } catch(NetconfError const&) { + } catch (NetconfError const&) { return ElementPtr(); } } diff --git a/src/lib/yang/translator_subnet.cc b/src/lib/yang/translator_subnet.cc index 055b327bd4..ae9c0f654f 100644 --- a/src/lib/yang/translator_subnet.cc +++ b/src/lib/yang/translator_subnet.cc @@ -54,7 +54,7 @@ ElementPtr TranslatorSubnet::getSubnetFromAbsoluteXpath(string const& xpath) { try { return getSubnet(findXPath(xpath)); - } catch(NetconfError const&) { + } catch (NetconfError const&) { return ElementPtr(); } } @@ -310,11 +310,7 @@ TranslatorSubnet::setSubnetKea(string const& xpath, ConstElementPtr elem) { checkAndSetLeaf(elem, xpath, "authoritative", LeafBaseType::Bool); checkAndSetLeaf(elem, xpath, "boot-file-name", LeafBaseType::String); checkAndSetLeaf(elem, xpath, "match-client-id", LeafBaseType::Bool); - checkAndSetLeaf(elem, xpath, "max-preferred-lifetime", LeafBaseType::Uint32); - checkAndSetLeaf(elem, xpath, "min-preferred-lifetime", LeafBaseType::Uint32); checkAndSetLeaf(elem, xpath, "next-server", LeafBaseType::String); - checkAndSetLeaf(elem, xpath, "preferred-lifetime", LeafBaseType::Uint32); - checkAndSetLeaf(elem, xpath, "rapid-commit", LeafBaseType::Bool); checkAndSetLeaf(elem, xpath, "server-hostname", LeafBaseType::String); checkAndSetDivergingLeaf(elem, xpath, "4o6-interface", "subnet-4o6-interface", LeafBaseType::String); @@ -360,7 +356,7 @@ ElementPtr TranslatorSubnets::getSubnetsFromAbsoluteXpath(string const& xpath) { try { return getSubnets(findXPath(xpath)); - } catch(NetconfError const&) { + } catch (NetconfError const&) { return ElementPtr(); } } diff --git a/src/lib/yang/yang.dox b/src/lib/yang/yang.dox index b2d580b395..6941974b9a 100644 --- a/src/lib/yang/yang.dox +++ b/src/lib/yang/yang.dox @@ -85,7 +85,7 @@ the basic / base class and recursively from translators for embedded parts. - @c isc::yang::Translator::getItem() retrieves and translates a leaf from YANG to Element. - - @c isc::yang::Translator::getList() retrieves a list from Sysrepo and + - @c isc::yang::Translator::getList() retrieves a list from sysrepo and translates it form YANG to Element. - @c isc::yang::Translator::getMandatoryLeaf() fetches a leaf that is expected @@ -96,7 +96,7 @@ the basic / base class and recursively from translators for embedded parts. substitute logic that had been previously removed. - @c isc::yang::Translator::setItem() translates a leaf from Element to - YANG and sets it in Sysrepo. + YANG and sets it in sysrepo. - @c isc::yang::Translator::setMandatoryLeaf() sets a leaf that is expected to be present in the Element node, most of the time a YANG key. @@ -270,7 +270,7 @@ them. @section yangMTConsiderations Multi-Threading Consideration for YANG Utilities The YANG utilities are not thread-safe. Note as they are used only in a -configuration context it is not a problem, and the YANG / Sysrepo libraries +configuration context it is not a problem, and the libyang and sysrepo libraries are multi-threaded so their APIs are thread-safe. */ diff --git a/src/share/yang/modules/hashes/keatest-module@2022-11-30.hash b/src/share/yang/modules/hashes/keatest-module@2022-11-30.hash index fcc45c7f05..6a6f5be7ba 100644 --- a/src/share/yang/modules/hashes/keatest-module@2022-11-30.hash +++ b/src/share/yang/modules/hashes/keatest-module@2022-11-30.hash @@ -1 +1 @@ -154760167c8e5986b3e3dfa52dbde018ffd23de2399da76ce30583feb10071f9 +a4c5fd6a22da33a8973b9a83a10bde57fd93123d1072276e190ddb0482299374