]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[65-libyang-pool] Addressed comments and updated base code
authorFrancis Dupont <fdupont@isc.org>
Fri, 5 Oct 2018 22:54:44 +0000 (00:54 +0200)
committerFrancis Dupont <fdupont@isc.org>
Fri, 5 Oct 2018 22:54:44 +0000 (00:54 +0200)
12 files changed:
src/lib/yang/models/kea-dhcp4-server.yang
src/lib/yang/pretests/sysrepo_setup_tests.cc
src/lib/yang/tests/adaptor_unittests.cc
src/lib/yang/tests/sysrepo_setup.h
src/lib/yang/tests/translator_option_data_unittests.cc
src/lib/yang/tests/translator_option_def_unittests.cc
src/lib/yang/tests/translator_pool_unittests.cc
src/lib/yang/translator_option_data.cc
src/lib/yang/translator_option_def.cc
src/lib/yang/translator_pool.cc
src/lib/yang/translator_pool.h
src/lib/yang/yang_models.h

index bbd5422c16044f28ea1dd44991a104a50ac22c66..e997dfbede44d6344f1801fb419631e6f310aef1 100644 (file)
@@ -115,7 +115,7 @@ module kea-dhcp4-server {
     uses server-hostname;
     uses boot-file-name;
     uses dhcp:host-user-context;
-  }    
+  }
 
   grouping reservations {
     description "Host reservations grouping.";
index f385ab858f1fec928ff6791ffecc4a7d2d59a48d..5f7e5e1ee263d7e5352918970e26065c20b05ded 100644 (file)
@@ -11,6 +11,8 @@
 
 using namespace std;
 
+/// Not using libyang headers, e.g. yang_models.h.
+
 const string TEST_MODULE = "keatest-module";
 const string IETF_TYPES = "ietf-inet-types";
 const string YANG_TYPES = "ietf-yang-types";
index 7ddf419e68aa06c40988bc672c2f4e9a08f58209..73660be3de6141f805382ab322bb7793b1e323f9 100644 (file)
@@ -8,7 +8,6 @@
 
 #include <yang/adaptor.h>
 
-#include <boost/scoped_ptr.hpp>
 #include <gtest/gtest.h>
 
 using namespace std;
index fbab42c5ddf293bf6d9c0b00c69a60be8453f128..b6005049166539a629c524c9423b96d4516cb9cc 100644 (file)
@@ -59,7 +59,7 @@ public:
     /// @brief Shared pointer to the transaction object.
     boost::shared_ptr<Type> t_obj_;
 };
-            
+
 } // namespace test
 } // namespace yang
 } // namespace isc
index 8365f60f5dffbbc9b35aea4d566eb0db962576cb..f02911607aa95e30575f5132904fe5e23ea93298 100644 (file)
@@ -7,6 +7,7 @@
 #include <config.h>
 
 #include <yang/translator_option_data.h>
+#include <yang/yang_models.h>
 #include <yang/tests/sysrepo_setup.h>
 
 #include <gtest/gtest.h>
@@ -38,7 +39,7 @@ public:
 // This test verifies that an empty option data list can be properly
 // translated from YANG to JSON.
 TEST_F(TranslatorOptionDataListTest, getEmpty) {
-    useModel("kea-dhcp4-server");
+    useModel(KEA_DHCP4_SERVER);
 
     // Get the option data list and checks it is empty.
     const string& xpath = "/kea-dhcp4-server:config/option-data-list";
@@ -52,7 +53,7 @@ TEST_F(TranslatorOptionDataListTest, getEmpty) {
 // This test verifies that one option data can be properly translated
 // from YANG to JSON.
 TEST_F(TranslatorOptionDataListTest, get) {
-    useModel("kea-dhcp6-server");
+    useModel(KEA_DHCP6_SERVER);
 
     // Create the option code 100.
     const string& xpath = "/kea-dhcp6-server:config/option-data-list";
@@ -65,7 +66,7 @@ TEST_F(TranslatorOptionDataListTest, get) {
     S_Val s_data(new Val("12121212"));
     ASSERT_NO_THROW(sess_->set_item(xdata.c_str(), s_data));
     ASSERT_NO_THROW(sess_->set_item(xsend.c_str(), s_false));
-    
+
     // Get the option data.
     ConstElementPtr option;
     EXPECT_NO_THROW(option = t_obj_->getOptionData(xoption));
@@ -91,7 +92,7 @@ TEST_F(TranslatorOptionDataListTest, get) {
 // This test verifies that an empty option data list can be properly
 // translated from JSON to YANG.
 TEST_F(TranslatorOptionDataListTest, setEmpty) {
-    useModel("kea-dhcp4-server");
+    useModel(KEA_DHCP4_SERVER);
 
     // Set empty list.
     const string& xpath = "/kea-dhcp4-server:config/option-data-list";
@@ -113,7 +114,7 @@ TEST_F(TranslatorOptionDataListTest, setEmpty) {
 // This test verifies that one option data can be properly translated
 // from JSON to YANG.
 TEST_F(TranslatorOptionDataListTest, set) {
-    useModel("kea-dhcp6-server");
+    useModel(KEA_DHCP6_SERVER);
 
     // Set one option data.
     const string& xpath = "/kea-dhcp6-server:config/option-data-list";
index 490efe5f275ae88429ac0603117765dffe4a4beb..556d81f63a15ff9d2a0ec091452732c946144b20 100644 (file)
@@ -7,6 +7,7 @@
 #include <config.h>
 
 #include <yang/translator_option_def.h>
+#include <yang/yang_models.h>
 #include <yang/tests/sysrepo_setup.h>
 
 #include <gtest/gtest.h>
@@ -38,7 +39,7 @@ public:
 // This test verifies that an empty option definition list can be properly
 // translated from YANG to JSON.
 TEST_F(TranslatorOptionDefListTest, getEmpty) {
-    useModel("kea-dhcp4-server");
+    useModel(KEA_DHCP4_SERVER);
 
     // Get the option definition list and checks it is empty.
     const string& xpath = "/kea-dhcp4-server:config/option-def-list";
@@ -52,7 +53,7 @@ TEST_F(TranslatorOptionDefListTest, getEmpty) {
 // This test verifies that one option definition can be properly
 // translated from YANG to JSON.
 TEST_F(TranslatorOptionDefListTest, get) {
-    useModel("kea-dhcp6-server");
+    useModel(KEA_DHCP6_SERVER);
 
     // Create the option code 100.
     const string& xpath = "/kea-dhcp6-server:config/option-def-list";
@@ -66,7 +67,7 @@ TEST_F(TranslatorOptionDefListTest, get) {
     ASSERT_NO_THROW(sess_->set_item(xtype.c_str(), s_type));
     S_Val s_array(new Val(false));
     ASSERT_NO_THROW(sess_->set_item(xarray.c_str(), s_array));
-    
+
     // Get the option def.
     ConstElementPtr def;
     EXPECT_NO_THROW(def = t_obj_->getOptionDef(xdef));
@@ -91,7 +92,7 @@ TEST_F(TranslatorOptionDefListTest, get) {
 // This test verifies that an empty option definition list can be properly
 // translated from JSON to YANG.
 TEST_F(TranslatorOptionDefListTest, setEmpty) {
-    useModel("kea-dhcp4-server");
+    useModel(KEA_DHCP4_SERVER);
 
     // Set empty list.
     const string& xpath = "/kea-dhcp4-server:config/option-def-list";
@@ -113,7 +114,7 @@ TEST_F(TranslatorOptionDefListTest, setEmpty) {
 // This test verifies that one option definition can be properly
 // translated from JSON to YANG.
 TEST_F(TranslatorOptionDefListTest, set) {
-    useModel("kea-dhcp6-server");
+    useModel(KEA_DHCP6_SERVER);
 
     // Set one option def.
     const string& xpath = "/kea-dhcp6-server:config/option-def-list";
index 29b4c7ef75cf2bfd56ec0a406d6924522f5dffb5..82a56efb067a5f3dac71874a1ad7377f5d33d76a 100644 (file)
@@ -7,6 +7,7 @@
 #include <config.h>
 
 #include <yang/translator_pool.h>
+#include <yang/yang_models.h>
 #include <yang/tests/sysrepo_setup.h>
 
 #include <gtest/gtest.h>
@@ -38,7 +39,7 @@ public:
 // This test verifies that an empty pool list can be properly
 // translated from YANG to JSON using IETF model.
 TEST_F(TranslatorPoolsTest, getEmptyIetf) {
-    useModel("ietf-dhcpv6-server");
+    useModel(IETF_DHCPV6_SERVER);
 
     // Get the pool list and checks it is empty.
     const string& xpath = "/ietf-dhcpv6-server:server/server-config/"
@@ -53,7 +54,7 @@ TEST_F(TranslatorPoolsTest, getEmptyIetf) {
 // This test verifies that an empty pool list can be properly
 // translated from YANG to JSON using Kea ad hoc model.
 TEST_F(TranslatorPoolsTest, getEmptyKea) {
-    useModel("kea-dhcp6-server");
+    useModel(KEA_DHCP6_SERVER);
 
     // Get the pool list and checks it is empty.
     const string& xpath =
@@ -68,7 +69,7 @@ TEST_F(TranslatorPoolsTest, getEmptyKea) {
 // This test verifies that one pool can be properly
 // translated from YANG to JSON using IETF model.
 TEST_F(TranslatorPoolsTest, getIetf) {
-    useModel("ietf-dhcpv6-server");
+    useModel(IETF_DHCPV6_SERVER);
 
     // Create the subnet 2001:db8::/48 #111.
     const string& subnet = "/ietf-dhcpv6-server:server/server-config/"
@@ -101,7 +102,7 @@ TEST_F(TranslatorPoolsTest, getIetf) {
 // This test verifies that one pool can be properly
 // translated from YANG to JSON using Kea ad hoc model.
 TEST_F(TranslatorPoolsTest, getKea) {
-    useModel("kea-dhcp6-server");
+    useModel(KEA_DHCP6_SERVER);
 
     // Create the subnet 2001:db8::/48 #111.
     const string& subnet =
@@ -146,7 +147,7 @@ TEST_F(TranslatorPoolsTest, getKea) {
 // This test verifies that an empty pool list can be properly
 // translated from JSON to YANG using IETF model.
 TEST_F(TranslatorPoolsTest, setEmptyIetf) {
-    useModel("ietf-dhcpv6-server");
+    useModel(IETF_DHCPV6_SERVER);
 
     // Create the subnet 2001:db8::/48 #111.
     const string& subnet = "/ietf-dhcpv6-server:server/server-config/"
@@ -171,7 +172,7 @@ TEST_F(TranslatorPoolsTest, setEmptyIetf) {
 // This test verifies that an empty pool list can be properly
 // translated from JSON to YANG using Kea ad hoc model.
 TEST_F(TranslatorPoolsTest, setEmptyKea) {
-    useModel("kea-dhcp6-server");
+    useModel(KEA_DHCP6_SERVER);
 
     // Create the subnet 2001:db8::/48 #111.
     const string& subnet =
@@ -196,7 +197,7 @@ TEST_F(TranslatorPoolsTest, setEmptyKea) {
 // This test verifies that one pool can be properly
 // translated from JSON to YANG using IETF model.
 TEST_F(TranslatorPoolsTest, setIetf) {
-    useModel("ietf-dhcpv6-server");
+    useModel(IETF_DHCPV6_SERVER);
 
     // Create the subnet 2001:db8::/48 #111.
     const string& subnet = "/ietf-dhcpv6-server:server/server-config/"
@@ -257,7 +258,7 @@ TEST_F(TranslatorPoolsTest, setIetf) {
 // This test verifies that one pool can be properly
 // translated from JSON to YANG using Kea ad hoc model.
 TEST_F(TranslatorPoolsTest, setKea) {
-    useModel("kea-dhcp6-server");
+    useModel(KEA_DHCP6_SERVER);
 
     // Create the subnet 2001:db8::/48 #111.
     const string& subnet =
index fde715bbbf1d14db2b40101053ce4ee12706f3a1..1c7c6d812d837850fc37175f760f8a0b9a6e7759 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <yang/translator_option_data.h>
 #include <yang/adaptor.h>
+#include <yang/yang_models.h>
 #include <sstream>
 
 using namespace std;
@@ -25,8 +26,8 @@ TranslatorOptionData::~TranslatorOptionData() {
 ElementPtr
 TranslatorOptionData::getOptionData(const string& xpath) {
     try {
-        if ((model_ == "kea-dhcp4-server") ||
-            (model_ == "kea-dhcp6-server")) {
+        if ((model_ == KEA_DHCP4_SERVER) ||
+            (model_ == KEA_DHCP6_SERVER)) {
             return (getOptionDataKea(xpath));
         }
     } catch (const sysrepo_exception& ex) {
@@ -77,8 +78,8 @@ void
 TranslatorOptionData::setOptionData(const string& xpath,
                                     ConstElementPtr elem) {
     try {
-        if ((model_ == "kea-dhcp4-server") ||
-            (model_ == "kea-dhcp6-server")) {
+        if ((model_ == KEA_DHCP4_SERVER) ||
+            (model_ == KEA_DHCP6_SERVER)) {
             setOptionDataKea(xpath, elem);
         } else {
             isc_throw(NotImplemented,
@@ -131,8 +132,8 @@ TranslatorOptionDataList::~TranslatorOptionDataList() {
 ConstElementPtr
 TranslatorOptionDataList::getOptionDataList(const string& xpath) {
     try {
-        if ((model_ == "kea-dhcp4-server") ||
-            (model_ == "kea-dhcp6-server")) {
+        if ((model_ == KEA_DHCP4_SERVER) ||
+            (model_ == KEA_DHCP6_SERVER)) {
             return (getOptionDataListKea(xpath));
         }
     } catch (const sysrepo_exception& ex) {
@@ -167,8 +168,8 @@ void
 TranslatorOptionDataList::setOptionDataList(const string& xpath,
                                             ConstElementPtr elem) {
     try {
-        if ((model_ == "kea-dhcp4-server") ||
-            (model_ == "kea-dhcp6-server")) {
+        if ((model_ == KEA_DHCP4_SERVER) ||
+            (model_ == KEA_DHCP6_SERVER)) {
             setOptionDataListKea(xpath, elem);
         } else {
             isc_throw(NotImplemented,
index 47e279cd05ada34274b6f84036dc9fcc8908eb56..b5365052c5125bf3ae646c4f8f14be2bede2a554 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <yang/translator_option_def.h>
 #include <yang/adaptor.h>
+#include <yang/yang_models.h>
 #include <sstream>
 
 using namespace std;
@@ -25,8 +26,8 @@ TranslatorOptionDef::~TranslatorOptionDef() {
 ElementPtr
 TranslatorOptionDef::getOptionDef(const string& xpath) {
     try {
-        if ((model_ == "kea-dhcp4-server") ||
-            (model_ == "kea-dhcp6-server")) {
+        if ((model_ == KEA_DHCP4_SERVER) ||
+            (model_ == KEA_DHCP6_SERVER)) {
             return (getOptionDefKea(xpath));
         }
     } catch (const sysrepo_exception& ex) {
@@ -80,8 +81,8 @@ TranslatorOptionDef::getOptionDefKea(const string& xpath) {
 void
 TranslatorOptionDef::setOptionDef(const string& xpath, ConstElementPtr elem) {
     try {
-        if ((model_ == "kea-dhcp4-server") ||
-            (model_ == "kea-dhcp6-server")) {
+        if ((model_ == KEA_DHCP4_SERVER) ||
+            (model_ == KEA_DHCP6_SERVER)) {
             setOptionDefKea(xpath, elem);
         } else {
             isc_throw(NotImplemented,
@@ -140,8 +141,8 @@ TranslatorOptionDefList::~TranslatorOptionDefList() {
 ConstElementPtr
 TranslatorOptionDefList::getOptionDefList(const string& xpath) {
     try {
-        if ((model_ == "kea-dhcp4-server") ||
-            (model_ == "kea-dhcp6-server")) {
+        if ((model_ == KEA_DHCP4_SERVER) ||
+            (model_ == KEA_DHCP6_SERVER)) {
             return (getOptionDefListKea(xpath));
         }
     } catch (const sysrepo_exception& ex) {
@@ -176,8 +177,8 @@ void
 TranslatorOptionDefList::setOptionDefList(const string& xpath,
                                           ConstElementPtr elem) {
     try {
-        if ((model_ == "kea-dhcp4-server") ||
-            (model_ == "kea-dhcp6-server")) {
+        if ((model_ == KEA_DHCP4_SERVER) ||
+            (model_ == KEA_DHCP6_SERVER)) {
             setOptionDefListKea(xpath, elem);
         } else {
             isc_throw(NotImplemented,
index ca4988ae289e99fa39003d15cce21f96e989ae72..d9c038566987893de1547ab5bf4c8af72d1b1613 100644 (file)
@@ -54,7 +54,7 @@ TranslatorPool::getPoolIetf6(const string& xpath) {
     // Skip pool-id which exists but is not used.
     ConstElementPtr pool = getItem(xpath + "/pool-prefix");
     if (!pool) {
-        isc_throw(BadValue, "getPoolIetf6 requires pool prefix");
+        isc_throw(BadValue, "getPoolIetf6 requires pool prefix at " << xpath);
     }
     result->set("pool", pool);
     // Ignore start-address - end-address as prefix form is mandatory?
@@ -97,7 +97,7 @@ TranslatorPool::getPoolKea(const string& xpath) {
         ConstElementPtr end_addr = getItem(xpath + "/end-address");
         if (!start_addr || !end_addr) {
             isc_throw(BadValue, "getPoolKea requires either prefix or "
-                      "both start and end addresses");
+                      "both start and end addresses at " << xpath);
         }
         ostringstream range;
         range << start_addr->stringValue() << " - "
@@ -161,7 +161,7 @@ TranslatorPool::setPoolIetf6(const string& xpath, ConstElementPtr elem) {
     const IOAddress& base(addr);
     setItem(xpath + "/start-address",
             Element::create(firstAddrInPrefix(base, plen).toText()),
-            SR_STRING_T);    
+            SR_STRING_T);
     setItem(xpath + "/end-address",
             Element::create(lastAddrInPrefix(base, plen).toText()),
             SR_STRING_T);
@@ -301,10 +301,10 @@ void
 TranslatorPools::setPools(const string& xpath, ConstElementPtr elem) {
     try {
         if (model_ == IETF_DHCPV6_SERVER) {
-            setPoolsbyId(xpath, elem);
+            setPoolsById(xpath, elem);
         } else if ((model_ == KEA_DHCP4_SERVER) ||
                    (model_ == KEA_DHCP6_SERVER)) {
-            setPoolsbyAddresses(xpath, elem);
+            setPoolsByAddresses(xpath, elem);
         } else {
             isc_throw(NotImplemented,
                       "setPools not implemented for the model: " << model_);
@@ -317,7 +317,7 @@ TranslatorPools::setPools(const string& xpath, ConstElementPtr elem) {
 }
 
 void
-TranslatorPools::setPoolsbyId(const string& xpath, ConstElementPtr elem) {
+TranslatorPools::setPoolsById(const string& xpath, ConstElementPtr elem) {
     for (size_t i = 0; i < elem->size(); ++i) {
         ConstElementPtr pool = elem->get(i);
         ostringstream prefix;
@@ -327,12 +327,12 @@ TranslatorPools::setPoolsbyId(const string& xpath, ConstElementPtr elem) {
 }
 
 void
-TranslatorPools::setPoolsbyAddresses(const string& xpath,
+TranslatorPools::setPoolsByAddresses(const string& xpath,
                                      ConstElementPtr elem) {
     for (size_t i = 0; i < elem->size(); ++i) {
         ConstElementPtr pool = elem->get(i);
         if (!pool->contains("pool")) {
-            isc_throw(BadValue, "setPoolsbyAddresses: missing required pool: "
+            isc_throw(BadValue, "setPoolsByAddresses: missing required pool: "
                       << pool->str());
         }
         string pref = pool->get("pool")->stringValue();
index 0a8e3421c276b700d1c0b6ce2eebeba204a70b05..1e702af7c7f8f72c48aff3ea2318e38e4a1cf056 100644 (file)
@@ -225,7 +225,7 @@ protected:
     ///
     /// @param xpath The xpath of the pool list.
     /// @param elem The JSON element.
-    void setPoolsbyId(const std::string& xpath,
+    void setPoolsById(const std::string& xpath,
                       isc::data::ConstElementPtr elem);
 
     /// @brief setPools using address pair.
@@ -233,7 +233,7 @@ protected:
     /// @param xpath The xpath of the pool list.
     /// @param elem The JSON element.
     /// @throw BadValue on a pool without a prefix.
-    void setPoolsbyAddresses(const std::string& xpath,
+    void setPoolsByAddresses(const std::string& xpath,
                              isc::data::ConstElementPtr elem);
 
     /// @brief The model.
index 31aa9a2c42bebedf7388feaf9952fc68a066e3b2..42f0f0fac2a5f10e5f8b7e5e8698ad9ed0efbad9 100644 (file)
@@ -7,6 +7,8 @@
 #ifndef ISC_YANG_MODELS
 #define ISC_YANG_MODELS 1
 
+#include <string>
+
 namespace isc {
 namespace yang {
 
@@ -18,9 +20,16 @@ static const std::string IETF_DHCPV6_SERVER = "ietf-dhcpv6-server";
 /// This model is being developed by ISC and is dedicated to Kea.
 static const std::string KEA_DHCP4_SERVER = "kea-dhcp4-server";
 
+/// This model is being developed by ISC and is dedicated to Kea.
+static const std::string KEA_DHCP6_SERVER = "kea-dhcp6-server";
+
 /// This model is currently in prototype phase. It will be developed
 /// by ISC in the near future.
-static const std::string KEA_DHCP6_SERVER = "kea-dhcp6-server";
+static const std::string KEA_DHCP_DDNS = "kea-dhcp-ddns";
+
+/// This model is currently in prototype phase. It will be developed
+/// by ISC in the near future.
+ static const std::string KEA_CTRL_AGENT = "kea-ctrl-agent";
 
 }; // end of namespace isc::yang
 }; // end of namespace isc