From 9fe8a1523527e8d62d8e16e5bd52829856553968 Mon Sep 17 00:00:00 2001 From: Francis Dupont Date: Mon, 22 Oct 2018 14:34:01 +0200 Subject: [PATCH] [65-libyang-subnet] Addressed subnet comments --- .../yang/tests/translator_host_unittests.cc | 5 ++-- .../tests/translator_option_data_unittests.cc | 2 +- .../tests/translator_option_def_unittests.cc | 2 +- .../tests/translator_pd_pool_unittests.cc | 8 +++---- .../yang/tests/translator_pool_unittests.cc | 8 +++---- .../yang/tests/translator_subnet_unittests.cc | 12 +++++----- src/lib/yang/translator_subnet.cc | 24 +++++++++---------- src/lib/yang/translator_subnet.h | 4 ++-- src/lib/yang/yang.dox | 4 +++- 9 files changed, 36 insertions(+), 33 deletions(-) diff --git a/src/lib/yang/tests/translator_host_unittests.cc b/src/lib/yang/tests/translator_host_unittests.cc index 15da1e9644..5a7b26a806 100644 --- a/src/lib/yang/tests/translator_host_unittests.cc +++ b/src/lib/yang/tests/translator_host_unittests.cc @@ -41,7 +41,7 @@ public: TEST_F(TranslatorHostsTest, getEmpty) { useModel(KEA_DHCP6_SERVER); - // Get the host reservation list and checks it is empty. + // Get the host reservation list and check if it is empty. const string& xpath = "/kea-dhcp6-server:config/subnet6/subnet6[id='111']/reservations"; ConstElementPtr hosts; @@ -83,7 +83,8 @@ TEST_F(TranslatorHostsTest, get) { expected->set("ip-addresses", addresses); EXPECT_TRUE(expected->equals(*host)); - // Get the host reservation list and checks the host reservation is in it. + // Get the host reservation list and check if the host reservation + // is in it. ConstElementPtr hosts; EXPECT_NO_THROW(hosts = t_obj_->getHosts(xpath)); ASSERT_TRUE(hosts); diff --git a/src/lib/yang/tests/translator_option_data_unittests.cc b/src/lib/yang/tests/translator_option_data_unittests.cc index f02911607a..9daa348786 100644 --- a/src/lib/yang/tests/translator_option_data_unittests.cc +++ b/src/lib/yang/tests/translator_option_data_unittests.cc @@ -41,7 +41,7 @@ public: TEST_F(TranslatorOptionDataListTest, getEmpty) { useModel(KEA_DHCP4_SERVER); - // Get the option data list and checks it is empty. + // Get the option data list and check if it is empty. const string& xpath = "/kea-dhcp4-server:config/option-data-list"; ConstElementPtr options; EXPECT_NO_THROW(options = t_obj_->getOptionDataList(xpath)); diff --git a/src/lib/yang/tests/translator_option_def_unittests.cc b/src/lib/yang/tests/translator_option_def_unittests.cc index 556d81f63a..03b5dc865e 100644 --- a/src/lib/yang/tests/translator_option_def_unittests.cc +++ b/src/lib/yang/tests/translator_option_def_unittests.cc @@ -41,7 +41,7 @@ public: TEST_F(TranslatorOptionDefListTest, getEmpty) { useModel(KEA_DHCP4_SERVER); - // Get the option definition list and checks it is empty. + // Get the option definition list and check if it is empty. const string& xpath = "/kea-dhcp4-server:config/option-def-list"; ConstElementPtr options; EXPECT_NO_THROW(options = t_obj_->getOptionDefList(xpath)); diff --git a/src/lib/yang/tests/translator_pd_pool_unittests.cc b/src/lib/yang/tests/translator_pd_pool_unittests.cc index 5acb3a8dd3..e82e06565a 100644 --- a/src/lib/yang/tests/translator_pd_pool_unittests.cc +++ b/src/lib/yang/tests/translator_pd_pool_unittests.cc @@ -41,7 +41,7 @@ public: TEST_F(TranslatorPdPoolsTest, getEmptyIetf) { useModel(IETF_DHCPV6_SERVER); - // Get the pd-pool list and checks it is empty. + // Get the pd-pool list and check if it is empty. const string& xpath = "/ietf-dhcpv6-server:server/server-config/network-ranges" "/network-range[network-range-id='111']/pd-pools"; @@ -57,7 +57,7 @@ TEST_F(TranslatorPdPoolsTest, getEmptyIetf) { TEST_F(TranslatorPdPoolsTest, getEmptyKea) { useModel(KEA_DHCP6_SERVER); - // Get the pd-pool list and checks it is empty. + // Get the pd-pool list and check if it is empty. const string& xpath = "/kea-dhcp6-server:config/subnet6/subnet6[id='111']/pd-pools"; ConstElementPtr pools; @@ -99,7 +99,7 @@ TEST_F(TranslatorPdPoolsTest, getIetf) { expected->set("prefix-len", Element::create(56)); EXPECT_TRUE(expected->equals(*pool)); - // Get the pd-pool list and checks the pd-pool is in it. + // Get the pd-pool list and check if the pd-pool is in it. ConstElementPtr pools; EXPECT_NO_THROW(pools = t_obj_->getPdPools(subnet + "/pd-pools")); ASSERT_TRUE(pools); @@ -140,7 +140,7 @@ TEST_F(TranslatorPdPoolsTest, getKea) { expected->set("delegated-len", Element::create(64)); EXPECT_TRUE(expected->equals(*pool)); - // Get the pd-pool list and checks the pd-pool is in it. + // Get the pd-pool list and check if the pd-pool is in it. ConstElementPtr pools; EXPECT_NO_THROW(pools = t_obj_->getPdPools(xpath)); ASSERT_TRUE(pools); diff --git a/src/lib/yang/tests/translator_pool_unittests.cc b/src/lib/yang/tests/translator_pool_unittests.cc index 82a56efb06..18f191344e 100644 --- a/src/lib/yang/tests/translator_pool_unittests.cc +++ b/src/lib/yang/tests/translator_pool_unittests.cc @@ -41,7 +41,7 @@ public: TEST_F(TranslatorPoolsTest, getEmptyIetf) { useModel(IETF_DHCPV6_SERVER); - // Get the pool list and checks it is empty. + // Get the pool list and check if it is empty. const string& xpath = "/ietf-dhcpv6-server:server/server-config/" "network-ranges/network-range[network-range-id='111']/address-pools"; ConstElementPtr pools; @@ -56,7 +56,7 @@ TEST_F(TranslatorPoolsTest, getEmptyIetf) { TEST_F(TranslatorPoolsTest, getEmptyKea) { useModel(KEA_DHCP6_SERVER); - // Get the pool list and checks it is empty. + // Get the pool list and check if it is empty. const string& xpath = "/kea-dhcp6-server:config/subnet6/subnet6[id='111']/pools"; ConstElementPtr pools; @@ -90,7 +90,7 @@ TEST_F(TranslatorPoolsTest, getIetf) { ASSERT_TRUE(pool); EXPECT_EQ("{ \"pool\": \"2001:db8::1:0/112\" }", pool->str()); - // Get the pool list and checks the pool is in it. + // Get the pool list and check if the pool is in it. ConstElementPtr pools; EXPECT_NO_THROW(pools = t_obj_->getPools(xpath)); ASSERT_TRUE(pools); @@ -135,7 +135,7 @@ TEST_F(TranslatorPoolsTest, getKea) { expected->set("pool", Element::create(string("2001:db8::1:0/112"))); EXPECT_TRUE(expected->equals(*pool)); - // Get the pool list and checks the pool is in it. + // Get the pool list and check if the pool is in it. ConstElementPtr pools; EXPECT_NO_THROW(pools = t_obj_->getPools(xpath)); ASSERT_TRUE(pools); diff --git a/src/lib/yang/tests/translator_subnet_unittests.cc b/src/lib/yang/tests/translator_subnet_unittests.cc index 0e63f15546..233bd3b61d 100644 --- a/src/lib/yang/tests/translator_subnet_unittests.cc +++ b/src/lib/yang/tests/translator_subnet_unittests.cc @@ -40,7 +40,7 @@ public: TEST_F(TranslatorSubnetsTest, getEmptyIetf) { useModel(IETF_DHCPV6_SERVER); - // Get the subnet list and checks it is empty. + // Get the subnet list and check if it is empty. const string& xpath = "/ietf-dhcpv6-server:server/server-config/network-ranges"; ConstElementPtr subnets; @@ -55,7 +55,7 @@ TEST_F(TranslatorSubnetsTest, getEmptyIetf) { TEST_F(TranslatorSubnetsTest, getEmptyKea) { useModel(KEA_DHCP6_SERVER); - // Get the subnet list and checks it is empty. + // Get the subnet list and check if it is empty. const string& xpath = "/kea-dhcp6-server:config/subnet6"; ConstElementPtr subnets; EXPECT_NO_THROW(subnets = t_obj_->getSubnets(xpath)); @@ -85,7 +85,7 @@ TEST_F(TranslatorSubnetsTest, getIetf) { "\"subnet\": \"2001:db8::/48\" }", subnet->str()); - // Get the subnet list and checks the subnet is in it. + // Get the subnet list and check if the subnet is in it. ConstElementPtr subnets; EXPECT_NO_THROW(subnets = t_obj_->getSubnets(xpath)); ASSERT_TRUE(subnets); @@ -115,7 +115,7 @@ TEST_F(TranslatorSubnetsTest, getKea) { expected->set("subnet", Element::create(string("2001:db8::/48"))); EXPECT_TRUE(expected->equals(*subnet)); - // Get the subnet list and checks the subnet is in it. + // Get the subnet list and check if the subnet is in it. ConstElementPtr subnets; EXPECT_NO_THROW(subnets = t_obj_->getSubnets(xpath)); ASSERT_TRUE(subnets); @@ -172,7 +172,7 @@ TEST_F(TranslatorSubnetsTest, getPoolsIetf) { "}"; EXPECT_EQ(expected, prettyPrint(subnet)); - // Get the subnet list and checks the subnet is in it. + // Get the subnet list and check if the subnet is in it. ConstElementPtr subnets; EXPECT_NO_THROW(subnets = t_obj_->getSubnets(xpath)); ASSERT_TRUE(subnets); @@ -230,7 +230,7 @@ TEST_F(TranslatorSubnetsTest, getPoolsKea) { "}"; EXPECT_EQ(expected, prettyPrint(subnet)); - // Get the subnet list and checks the subnet is in it. + // Get the subnet list and check if the subnet is in it. ConstElementPtr subnets; EXPECT_NO_THROW(subnets = t_obj_->getSubnets(xpath)); ASSERT_TRUE(subnets); diff --git a/src/lib/yang/translator_subnet.cc b/src/lib/yang/translator_subnet.cc index 85cfe016d8..3358214857 100644 --- a/src/lib/yang/translator_subnet.cc +++ b/src/lib/yang/translator_subnet.cc @@ -52,11 +52,11 @@ TranslatorSubnet::getSubnet(const string& xpath) { ElementPtr TranslatorSubnet::getSubnetIetf6(const string& xpath) { ElementPtr result = Element::createMap(); - // @todo timers - // @todo: option-data + /// @todo timers + /// @todo: option-data ConstElementPtr pools = getPools(xpath + "/address-pools"); if (pools) { - // Set empty list too. + /// Set empty list too. result->set("pools", pools); } pools = getPdPools(xpath + "/pd-pools"); @@ -73,16 +73,16 @@ TranslatorSubnet::getSubnetIetf6(const string& xpath) { isc_throw(BadValue, "getSubnetIetf6 requires network range id"); } result->set("id", id); - // @todo: reservations - // missing a lot of things + /// @todo: reservations + /// missing a lot of things ConstElementPtr description = getItem(xpath + "/network-description"); - // Adding description if exists. + /// Adding description if exists. if (description) { ElementPtr context = Element::createMap(); context->set("description", description); result->set("user-context", context); } - // missing a lot of things + /// missing a lot of things AdaptorPool::toSubnet(model_, result, result->get("pools")); return (result); } @@ -228,7 +228,7 @@ TranslatorSubnet::setSubnet(const string& xpath, ConstElementPtr elem) { void TranslatorSubnet::setSubnetIetf6(const string& xpath, ConstElementPtr elem) { - // Skip id as it is the key. + /// Skip id as it is the key. AdaptorPool::fromSubnet(model_, elem, elem->get("pools")); ConstElementPtr context = elem->get("user-context"); if (context && context->contains("description")) { @@ -242,7 +242,7 @@ TranslatorSubnet::setSubnetIetf6(const string& xpath, ConstElementPtr elem) { isc_throw(BadValue, "setSubnetIetf6 requires subnet: " << elem->str()); } setItem(xpath + "/network-prefix", subnet, SR_STRING_T); - // @todo option-data + /// @todo option-data ConstElementPtr pools = elem->get("pools"); if (pools && (pools->size() > 0)) { setPools(xpath + "/address-pools", pools); @@ -251,12 +251,12 @@ TranslatorSubnet::setSubnetIetf6(const string& xpath, ConstElementPtr elem) { if (pools && (pools->size() > 0)) { setPdPools(xpath + "/pd-pools", pools); } - // @todo reservations + /// @todo reservations } void TranslatorSubnet::setSubnetKea(const string& xpath, ConstElementPtr elem) { - // Skip id as it is the key. + /// Skip id as it is the key. if (model_ == KEA_DHCP6_SERVER) { ConstElementPtr preferred = elem->get("preferred-lifetime"); if (preferred) { @@ -400,7 +400,7 @@ TranslatorSubnets::getSubnets(const string& xpath) { ElementPtr result = Element::createList(); S_Iter_Value iter = getIter(xpath + "/*"); if (!iter) { - // Can't happen. + /// Can't happen. isc_throw(Unexpected, "getSubnets: can't get iterator: " << xpath); } for (;;) { diff --git a/src/lib/yang/translator_subnet.h b/src/lib/yang/translator_subnet.h index dc2b0d0575..ea8736c056 100644 --- a/src/lib/yang/translator_subnet.h +++ b/src/lib/yang/translator_subnet.h @@ -25,7 +25,7 @@ namespace yang { /// "renew-timer": , /// "rebind-timer": , /// "option-data": [ ], -/// "pools": [ ], +/// "pools": [ ], /// "subnet": "", /// "interface": "", /// "id": , @@ -54,7 +54,7 @@ namespace yang { /// "renew-timer": , /// "rebind-timer": , /// "option-data": [ ], -/// "pools": [ ], +/// "pools": [ ], /// "pd-pools": [ ], /// "subnet": "", /// "interface": "", diff --git a/src/lib/yang/yang.dox b/src/lib/yang/yang.dox index c21e72f11e..2001cb30af 100644 --- a/src/lib/yang/yang.dox +++ b/src/lib/yang/yang.dox @@ -46,7 +46,9 @@ the basic / base class and recursively of translators for embedded parts. @c isc::yang::TranslatorPool is the standard example of a translator for a structured value. Its constructor takes a model name: the code implements some variants to accommodate the model with shared code -moved into a common private routine. +moved into a common private routine. When called with an unsupported +model, generic methods of all structure translators throw +@c isc::NotImplemented. @c isc::yang::TranslatorPools deals with a list of pools. The getPools method iterates over the list in both ways. Look at examples in unit -- 2.47.2