]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#65,!45] Added missing unit-test.
authorTomek Mrugalski <tomasz@isc.org>
Wed, 17 Oct 2018 16:19:09 +0000 (18:19 +0200)
committerTomek Mrugalski <tomasz@isc.org>
Wed, 17 Oct 2018 16:19:09 +0000 (18:19 +0200)
src/lib/yang/tests/translator_pd_pool_unittests.cc
src/lib/yang/translator_pd_pool.cc
src/lib/yang/translator_pd_pool.h

index dc703c7f7a352cb2b0fb142d1220582599a1ba8c..a87a77d88cf5f24cb0a8bb0fc49d82ac04416c8d 100644 (file)
@@ -67,7 +67,7 @@ TEST_F(TranslatorPdPoolsTest, getEmptyKea) {
     EXPECT_EQ(0, pools->size());
 }
 
-// This test verifies that one empty pd pool can be properly
+// This test verifies that one non-empty pd pool can be properly
 // translated from YANG to JSON using the IETF model.
 TEST_F(TranslatorPdPoolsTest, getIetf) {
     useModel(IETF_DHCPV6_SERVER);
@@ -108,7 +108,7 @@ TEST_F(TranslatorPdPoolsTest, getIetf) {
     EXPECT_TRUE(pool->equals(*pools->get(0)));
 }
 
-// This test verifies that one empty pd pool can be properly
+// This test verifies that one non-empty pd pool can be properly
 // translated from YANG to JSON using the Kea ad hoc model.
 TEST_F(TranslatorPdPoolsTest, getKea) {
     useModel(KEA_DHCP6_SERVER);
@@ -319,4 +319,49 @@ TEST_F(TranslatorPdPoolsTest, setKea) {
     EXPECT_NO_THROW(sess_->validate());
 }
 
+// This test verifies that a list of non-empty pd pools can be properly
+// translated from YANG to JSON using the Kea ad hoc model.
+TEST_F(TranslatorPdPoolsTest, getListKea) {
+    useModel(KEA_DHCP6_SERVER);
+
+    // Create the subnet 2001:db8::/48 #111.
+    const string& subnet =
+        "/kea-dhcp6-server:config/subnet6/subnet6[id='111']";
+    S_Val v_subnet(new Val("2001:db8::/48", SR_STRING_T));
+    const string& subnet_subnet = subnet + "/subnet";
+    EXPECT_NO_THROW(sess_->set_item(subnet_subnet.c_str(), v_subnet));
+
+    // Create the first pd-pool 2001:db8:0:1000::/56.
+    const string& xpath = subnet + "/pd-pools";
+    const string& prefix = "2001:db8:0:1000::/56";
+    ostringstream spool;
+    spool << xpath + "/pd-pool[prefix='" << prefix << "']";
+    const string& x_delegated = spool.str() + "/delegated-len";
+    uint8_t dl = 64;
+    S_Val s_delegated(new Val(dl, SR_UINT8_T));
+    EXPECT_NO_THROW(sess_->set_item(x_delegated.c_str(), s_delegated));
+
+    // Create the second pd-pool 2001:db8:0:2000::/56
+    const string& xpath2 = subnet + "/pd-pools";
+    const string& prefix2 = "2001:db8:0:2000::/56";
+    ostringstream spool2;
+    spool2 << xpath2 + "/pd-pool[prefix='" << prefix2 << "']";
+    const string& x_delegated2 = spool2.str() + "/delegated-len";
+    uint8_t dl2 = 60;
+    S_Val s_delegated2(new Val(dl2, SR_UINT8_T));
+    EXPECT_NO_THROW(sess_->set_item(x_delegated2.c_str(), s_delegated2));
+
+
+    // Get the pools list.
+    ConstElementPtr pools;
+    EXPECT_NO_THROW(pools = t_obj_->getPdPools(xpath2));
+    ASSERT_TRUE(pools);
+
+    // Check that both of them are returned properly.
+    EXPECT_EQ(pools->str(),
+              "[ { \"delegated-len\": 64, \"prefix\": \"2001:db8:0:1000::\", "
+              "\"prefix-len\": 56 }, { \"delegated-len\": 60, \"prefix\": "
+              "\"2001:db8:0:2000::\", \"prefix-len\": 56 } ]");
+}
+
 }; // end of anonymous namespace
index 16636e3f5bc2cb2262f36debe85d1d2f208a771d..1180c027b973d826600379dbd581bcfc73ff170a 100644 (file)
@@ -101,7 +101,8 @@ TranslatorPdPool::getPdPoolKea(const string& xpath) {
     ElementPtr result = Element::createMap();
     ConstElementPtr pref = getItem(xpath + "/prefix");
     if (!pref) {
-        isc_throw(BadValue, "getPdPoolKea: prefix is required");
+        isc_throw(BadValue, "getPdPoolKea: no prefix defined at requested xpath("
+                  << xpath << "/prefix");
     }
     const string& prefix = pref->stringValue();
     size_t slash = prefix.find("/");
index 7fe0881980f2e1fbd134ca72ca87406897508201..d2cd13014cc0f3623737eb5640fdce581f9b4ef3 100644 (file)
@@ -15,7 +15,7 @@ namespace yang {
 
 /// Prefix delegation pool translation between YANG and JSON
 ///
-/// JSON syntax for both kea-dhcp4 and kea-dhcp6 is:
+/// JSON syntax for kea-dhcp6-server is:
 /// @code
 /// {
 ///     "prefix": <prefix base>,
@@ -47,7 +47,7 @@ namespace yang {
 ///     /server/server-config/option-sets/option-set/option-set-id
 /// @endcode
 ///
-/// YANG syntax for kea-dhcp6 is with prefix as the key.
+/// YANG syntax for kea-dhcp6-server is with prefix as the key.
 /// @code
 ///  +--rw prefix?                  inet:ipv6-prefix
 ///  +--rw delegated-len?           uint8
@@ -112,7 +112,9 @@ namespace yang {
 /// @brief A translator class for converting a pd-pool between
 /// YANG and JSON.
 ///
-/// Currently supports on kea-dhcp[46]-server and partially ietf-dhcpv6-server.
+/// Currently supported models:
+/// - kea-dhcp6-server
+/// - ietf-dhcpv6-server (partial support)
 class TranslatorPdPool : virtual public TranslatorOptionDataList {
 public:
 
@@ -176,7 +178,9 @@ protected:
 /// @brief A translator class for converting a pd-pool list between
 /// YANG and JSON.
 ///
-/// Currently supports on kea-dhcp[46]-server and partially ietf-dhcpv6-server.
+/// Currently supports the following models:
+/// - kea-dhcp6-server
+/// - ietf-dhcpv6-server (partial support)
 class TranslatorPdPools : virtual public TranslatorPdPool {
 public: