]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2601] addressed review comments
authorRazvan Becheriu <razvan@isc.org>
Fri, 25 Nov 2022 20:31:38 +0000 (22:31 +0200)
committerAndrei Pavel <andrei@isc.org>
Fri, 25 Nov 2022 20:48:36 +0000 (22:48 +0200)
doc/examples/kea4/all-keys-netconf.json
src/lib/yang/tests/translator_unittests.cc
src/lib/yang/tests/translator_utils_unittests.cc
src/lib/yang/translator.cc
src/lib/yang/translator.h
src/lib/yang/translator_class.cc
src/lib/yang/translator_shared_network.cc
src/lib/yang/yang.dox

index 7e9b6b7b17cca673bf1c22287b0f7870a136b305..c333464799183eb92e9c3ea5f8b8924fc92868b4 100644 (file)
 
                 // 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)"
+                "template-test": "substring(option[61].hex, 0, all)"
             }
         ],
 
index 936a9b41299517d0091645952873a7db67b930e1..853241902a7c35be6ab90c1113489816208ecd35 100644 (file)
@@ -127,7 +127,7 @@ TEST_F(TranslatorTest, getItem) {
 
     // Unsigned 64 bit integer.
     xpath = "/keatest-module:main/ui64";
-    uint32_t u64(64);
+    uint64_t u64(64);
     value = to_string(u64);
     EXPECT_NO_THROW_LOG(sess.setItem(xpath, value));
     sess.applyChanges();
@@ -186,7 +186,7 @@ TEST_F(TranslatorTest, getItem) {
 
     // Signed 64 bit integer.
     xpath = "/keatest-module:main/i64";
-    int32_t s64(64);
+    int64_t s64(64);
     value = to_string(s64);
     EXPECT_NO_THROW_LOG(sess.setItem(xpath, value));
     sess.applyChanges();
index 1f92e3d4c399d74fa1e0783d997ed712da4ec505..ddd4cb91e11695d3f46260880adfbf982c5bdd84 100644 (file)
@@ -113,7 +113,7 @@ TEST(YangReprTest, getTest) {
     EXPECT_NO_THROW_LOG(sess.applyChanges());
 
     xpath = "/keatest-module:main/ui64";
-    uint32_t u64(64);
+    uint64_t u64(64);
     value = to_string(u64);
     EXPECT_NO_THROW_LOG(sess.setItem(xpath, value));
     EXPECT_NO_THROW_LOG(sess.applyChanges());
@@ -137,7 +137,7 @@ TEST(YangReprTest, getTest) {
     EXPECT_NO_THROW_LOG(sess.applyChanges());
 
     xpath = "/keatest-module:main/i64";
-    int32_t s64(64);
+    int64_t s64(64);
     value = to_string(s64);
     EXPECT_NO_THROW_LOG(sess.setItem(xpath, value));
     EXPECT_NO_THROW_LOG(sess.applyChanges());
index aa87f1931160a947be17abbb6fbb0d43238a676e..9c5ed9ce0415733453c7f60160bb45d0a8896cf0 100644 (file)
@@ -59,31 +59,34 @@ Translator::checkAndGetAndJsonifyLeaf(ElementPtr& storage,
     }
 }
 
-void Translator::checkAndSetLeaf(ConstElementPtr const& from,
-                                 string const& xpath,
-                                 string const& name,
-                                 LeafBaseType const type) {
+void
+Translator::checkAndSetLeaf(ConstElementPtr const& from,
+                            string const& xpath,
+                            string const& name,
+                            LeafBaseType const type) {
     ConstElementPtr const& x(from->get(name));
     if (x) {
         setItem(xpath + "/" + name, x, type);
     }
 }
 
-void Translator::checkAndSetDivergingLeaf(ConstElementPtr const& from,
-                                          string const& xpath,
-                                          string const& name,
-                                          string const& yang_name,
-                                          LeafBaseType const type) {
+void
+Translator::checkAndSetDivergingLeaf(ConstElementPtr const& from,
+                                     string const& xpath,
+                                     string const& name,
+                                     string const& yang_name,
+                                     LeafBaseType const type) {
     ConstElementPtr const& x(from->get(name));
     if (x) {
         setItem(xpath + "/" + yang_name, x, type);
     }
 }
 
-void Translator::checkAndSetLeafList(ConstElementPtr const& from,
-                                     string const& xpath,
-                                     string const& name,
-                                     LeafBaseType const type) {
+void
+Translator::checkAndSetLeafList(ConstElementPtr const& from,
+                                string const& xpath,
+                                string const& name,
+                                LeafBaseType const type) {
     ConstElementPtr const& leaf_list(from->get(name));
     if (leaf_list && !leaf_list->empty()) {
         for (ElementPtr const& leaf : leaf_list->listValue()) {
@@ -92,8 +95,9 @@ void Translator::checkAndSetLeafList(ConstElementPtr const& from,
     }
 }
 
-void Translator::checkAndSetUserContext(ConstElementPtr const& from,
-                                        string const& xpath) {
+void
+Translator::checkAndSetUserContext(ConstElementPtr const& from,
+                                   string const& xpath) {
     ConstElementPtr const& user_context(Adaptor::getContext(from));
     if (user_context) {
         setItem(xpath + "/user-context", Element::create(user_context->str()),
@@ -212,7 +216,8 @@ Translator::getMandatoryDivergingLeaf(ElementPtr& storage,
     storage->set(name, x);
 }
 
-bool Translator::schemaNodeExists(string const& xpath) const {
+bool
+Translator::schemaNodeExists(string const& xpath) const {
     Context const& context(session_.getContext());
     try {
         context.findPath(xpath);
index 688f86d2cee545148804ae2c2af9913ff5eec70f..2cb38a33eb338be42b652eb3088fa347ae375d8e 100644 (file)
@@ -295,7 +295,8 @@ public:
     ///
     /// @param storage ElementMap where result will be stored
     /// @param data_node parent data node of container type
-    /// @param name name of the parameter
+    /// @param name the name of the YANG node which should also match the map
+    /// key in the JSON configuration
     ///
     /// @throw MissingNode if leaf is not found
     void getMandatoryLeaf(isc::data::ElementPtr& storage,
@@ -310,9 +311,10 @@ public:
     ///
     /// @param storage ElementMap where result will be stored
     /// @param data_node parent data node of container type
-    /// @param name name of the parameter
+    /// @param name the map key in the JSON configuration
     /// @param yang_name the name by which to find the parameter in the YANG data node
     ///
+
     /// @throw MissingNode if leaf is not found
     void getMandatoryDivergingLeaf(isc::data::ElementPtr& storage,
                                    libyang::DataNode const& data_node,
@@ -353,8 +355,7 @@ 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
+    /// @param name the map key in the JSON configuration
     /// @param yang_name the name by which to find the parameter in the YANG data node
     /// @param type the YANG node type
     void setMandatoryDivergingLeaf(isc::data::ConstElementPtr const& from,
index 40edca9b034a5c1d831a05ea85a729ddb25d4e00..7d3ec401890e1eaf8529ac7794a8894cb82869ed 100644 (file)
@@ -71,15 +71,16 @@ TranslatorClass::getClassKea(DataNode const& data_node) {
     if (options) {
         result->set("option-data", options);
     }
-    ConstElementPtr defs = getOptionDefList(data_node);
-    if (defs) {
-        result->set("option-def", defs);
-    }
 
     if (model_ == KEA_DHCP4_SERVER) {
         checkAndGetLeaf(result, data_node, "boot-file-name");
         checkAndGetLeaf(result, data_node, "next-server");
         checkAndGetLeaf(result, data_node, "server-hostname");
+
+        ConstElementPtr defs = getOptionDefList(data_node);
+        if (defs) {
+            result->set("option-def", defs);
+        }
     } else if (model_ == KEA_DHCP6_SERVER) {
         checkAndGetLeaf(result, data_node, "max-preferred-lifetime");
         checkAndGetLeaf(result, data_node, "min-preferred-lifetime");
index f4b19f2d50eaa48ba6ffe0b8c241e18a24394026..ad5d121ffcd727ece9d9c813da0a08449349d898 100644 (file)
@@ -173,18 +173,18 @@ TranslatorSharedNetwork::setSharedNetworkKea(string const& xpath,
     checkAndSetLeaf(elem, xpath, "hostname-char-replacement", LeafBaseType::String);
     checkAndSetLeaf(elem, xpath, "hostname-char-set", LeafBaseType::String);
     checkAndSetLeaf(elem, xpath, "interface", LeafBaseType::String);
+    checkAndSetLeaf(elem, xpath, "max-valid-lifetime", LeafBaseType::Uint32);
+    checkAndSetLeaf(elem, xpath, "min-valid-lifetime", LeafBaseType::Uint32);
+    checkAndSetLeaf(elem, xpath, "rebind-timer", LeafBaseType::Uint32);
+    checkAndSetLeaf(elem, xpath, "renew-timer", LeafBaseType::Uint32);
     checkAndSetLeaf(elem, xpath, "reservation-mode", LeafBaseType::Enum);
     checkAndSetLeaf(elem, xpath, "reservations-global", LeafBaseType::Bool);
     checkAndSetLeaf(elem, xpath, "reservations-in-subnet", LeafBaseType::Bool);
     checkAndSetLeaf(elem, xpath, "reservations-out-of-pool", LeafBaseType::Bool);
     checkAndSetLeaf(elem, xpath, "store-extended-info", LeafBaseType::Bool);
-    checkAndSetLeaf(elem, xpath, "valid-lifetime", LeafBaseType::Uint32);
-    checkAndSetLeaf(elem, xpath, "max-valid-lifetime", LeafBaseType::Uint32);
-    checkAndSetLeaf(elem, xpath, "min-valid-lifetime", LeafBaseType::Uint32);
-    checkAndSetLeaf(elem, xpath, "rebind-timer", LeafBaseType::Uint32);
-    checkAndSetLeaf(elem, xpath, "renew-timer", LeafBaseType::Uint32);
     checkAndSetLeaf(elem, xpath, "t1-percent", LeafBaseType::Dec64);
     checkAndSetLeaf(elem, xpath, "t2-percent", LeafBaseType::Dec64);
+    checkAndSetLeaf(elem, xpath, "valid-lifetime", LeafBaseType::Uint32);
 
     checkAndSetLeafList(elem, xpath, "require-client-classes", LeafBaseType::String);
 
index 6941974b9a19b62c59b628aca0f92d67a32ceef9..e0fcab04936d5d0d199fad538b7c257de3b49f9f 100644 (file)
@@ -86,7 +86,7 @@ the basic / base class and recursively from translators for embedded parts.
     from YANG to Element.
 
   - @c isc::yang::Translator::getList() retrieves a list from sysrepo and
-    translates it form YANG to Element.
+    translates it from YANG to Element.
 
   - @c isc::yang::Translator::getMandatoryLeaf() fetches a leaf that is expected
     to be present in the YANG data node, most of the time a YANG key.