Commit 7b18ca62 authored by Francis Dupont's avatar Francis Dupont Committed by Tomek Mrugalski

[65-libyang-shared-network-translator] Addressed shared network comments

parent 90f65bd8
......@@ -182,12 +182,14 @@ TEST_F(TranslatorSharedNetworksTest, getList) {
const string& xnetwork3 = xpath + "/shared-network[name='baz']";
const string& exp_net1 =
"{ \"name\": \"foo\", \"subnet6\": [ { \"id\": 1, \"subnet\": "
"\"2001:db8:1::/48\" }, { \"id\": 2, \"subnet\": \"2001:db8:2::/48\" } ] }";
"{ \"name\": \"foo\", \"subnet6\": [ { \"id\": 1, "
"\"subnet\": \"2001:db8:1::/48\" }, "
"{ \"id\": 2, \"subnet\": \"2001:db8:2::/48\" } ] }";
const string& exp_net2 =
"{ \"name\": \"bar\", \"subnet6\": [ { \"id\": 101, \"subnet\": "
"\"2001:db8:101::/48\" }, { \"id\": 102, \"subnet\": \"2001:db8:102::/48\" } ] }";
"{ \"name\": \"bar\", \"subnet6\": [ { \"id\": 101, "
"\"subnet\": \"2001:db8:101::/48\" }, "
"{ \"id\": 102, \"subnet\": \"2001:db8:102::/48\" } ] }";
const string exp_both =
"[ " + exp_net1 + ", " + exp_net2 + " ]";
......@@ -227,9 +229,7 @@ TEST_F(TranslatorSharedNetworksTest, getList) {
EXPECT_EQ(exp_net2, network->str());
// Check that networks with non-existent name are not returned.
EXPECT_NO_THROW(network = t_obj_->getSharedNetwork(xnetwork3));
EXPECT_FALSE(network) << "Unexpected shared network returned, "
<< " expected null, but got: " << network->str();
EXPECT_THROW(network = t_obj_->getSharedNetwork(xnetwork3), Unexpected);
// Now test returns all networks
ConstElementPtr networks;
......
......@@ -55,7 +55,12 @@ ElementPtr
TranslatorSharedNetwork::getSharedNetworkKea(const string& xpath,
const std::string& subsel) {
ElementPtr result = Element::createMap();
result->set("name", getItem(xpath + "/name"));
ConstElementPtr name = getItem(xpath + "/name");
if (!name) {
// Can't happen as the name is the key.
isc_throw(Unexpected, "getSharedNetworkKea requires name: " << xpath);
}
result->set("name", name);
ConstElementPtr subnets = getSubnets(xpath + "/" + subsel);
if (subnets && (subnets->size() > 0)) {
result->set(subsel, subnets);
......
......@@ -61,7 +61,7 @@ namespace yang {
/// }
/// @endcode
///
/// YANG syntax for kea-dhcp[46] is with name as the list key:
/// YANG syntax for kea-dhcp[46]-server is with name as the list key:
/// @code
/// +--rw name string
/// +--rw valid-lifetime? uint32
......@@ -152,7 +152,8 @@ public:
isc::data::ConstElementPtr elem);
protected:
/// @brief getSharedNetwork for kea-dhcp4-server and kea-dhcp6-server models
/// @brief getSharedNetwork for kea-dhcp4-server and
/// kea-dhcp6-server models
///
/// @param xpath The xpath of the shared network.
/// @param subsel The subnet list name (either "subnet4" or "subnet6").
......@@ -160,7 +161,8 @@ protected:
isc::data::ElementPtr getSharedNetworkKea(const std::string& xpath,
const std::string& subsel);
/// @brief setSharedNetwork for kea-dhcp4-server and kea-dhcp6-server models
/// @brief setSharedNetwork for kea-dhcp4-server and
/// kea-dhcp6-server models
///
/// @param xpath The xpath of the shared network.
/// @param elem The JSON element.
......@@ -205,7 +207,8 @@ public:
isc::data::ConstElementPtr elem);
protected:
/// @brief setSharedNetworks for kea-dhcp[46]-server.
/// @brief setSharedNetworks for kea-dhcp4-server and
/// kea-dhcp6-server
///
/// @param xpath The xpath of the shared network list.
/// @param elem The JSON element.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment