From: Tomek Mrugalski Date: Wed, 17 Oct 2018 16:19:09 +0000 (+0200) Subject: [#65,!45] Added missing unit-test. X-Git-Tag: 153-netconf-agent_base~1^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=04d1db886851d160b1d54fcb881568143f7df65f;p=thirdparty%2Fkea.git [#65,!45] Added missing unit-test. --- diff --git a/src/lib/yang/tests/translator_pd_pool_unittests.cc b/src/lib/yang/tests/translator_pd_pool_unittests.cc index dc703c7f7a..a87a77d88c 100644 --- a/src/lib/yang/tests/translator_pd_pool_unittests.cc +++ b/src/lib/yang/tests/translator_pd_pool_unittests.cc @@ -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 diff --git a/src/lib/yang/translator_pd_pool.cc b/src/lib/yang/translator_pd_pool.cc index 16636e3f5b..1180c027b9 100644 --- a/src/lib/yang/translator_pd_pool.cc +++ b/src/lib/yang/translator_pd_pool.cc @@ -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("/"); diff --git a/src/lib/yang/translator_pd_pool.h b/src/lib/yang/translator_pd_pool.h index 7fe0881980..d2cd13014c 100644 --- a/src/lib/yang/translator_pd_pool.h +++ b/src/lib/yang/translator_pd_pool.h @@ -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": , @@ -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: