Skip to content

Commit

Permalink
Fixed issue CiscoDevNet#803
Browse files Browse the repository at this point in the history
  • Loading branch information
Yan Gorelik committed Jan 11, 2019
1 parent af1f0e1 commit c24a515
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 4 deletions.
10 changes: 7 additions & 3 deletions sdk/cpp/core/src/netconf_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ bool NetconfService::edit_config(NetconfServiceProvider& provider, DataStore tar

string payload = "";
for (auto entity : config_list) {
payload += get_xml_subtree_filter_payload(*entity, provider);
payload += get_data_payload(*entity, provider);
}

return edit_payload(provider, target, payload, default_operation, test_option, error_option);
Expand All @@ -256,7 +256,9 @@ get_from_list(NetconfServiceProvider& provider, DataStore source, vector<Entity*
// Build filter
string filter_string = "";
for (auto entity : filter_list) {
filter_string += get_xml_subtree_filter_payload(*entity, provider);
filter_string += (entity->is_top_level_class) ?
get_xml_subtree_filter_payload(*entity, provider) :
get_data_payload(*entity, provider);
}

// Source options: candidate | running | startup
Expand Down Expand Up @@ -328,7 +330,9 @@ get_entity(NetconfServiceProvider& provider, DataStore source, Entity& filter, c
}

// filter
std::string filter_string = get_xml_subtree_filter_payload(filter, provider);
string filter_string = (filter.is_top_level_class) ?
get_xml_subtree_filter_payload(filter, provider) :
get_data_payload(filter, provider);
rpc->get_input_node().create_datanode("filter", filter_string);

shared_ptr<path::DataNode> result_datanode = (*rpc)(provider.get_session());
Expand Down
62 changes: 61 additions & 1 deletion sdk/cpp/tests/test_netconf_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <ydk_ydktest/openconfig_bgp.hpp>
#include <ydk_ydktest/openconfig_interfaces.hpp>
#include <ydk/types.hpp>
#include <ydk/filters.hpp>
#include <ydk/common_utilities.hpp>

#include <spdlog/spdlog.h>
Expand Down Expand Up @@ -98,7 +99,6 @@ TEST_CASE("delete_config")

DataStore target = DataStore::url;

// auto reply = ns.delete_config(session, target, "http://test");
CHECK_THROWS_AS(ns.delete_config(provider, target, "http://test"), YError);
}

Expand Down Expand Up @@ -331,6 +331,66 @@ TEST_CASE("ietf_get_rpc")
}
}

TEST_CASE("create_list_with_yfilter")
{
path::Repository repo{TEST_HOME};
NetconfServiceProvider provider{repo, "127.0.0.1", "admin", "admin", 12022};
ydk::path::RootSchemaNode& schema = provider.get_session().get_root_schema();
NetconfService ns{};

auto runner = ydktest_sanity::Runner{};
runner.yfilter = YFilter::delete_;
auto reply = ns.edit_config(provider, DataStore::running, runner);
REQUIRE(reply);

runner.yfilter = YFilter::merge;
vector<Entity*> merge_list{};
merge_list.push_back(&runner);

reply = ns.edit_config(provider, DataStore::running, merge_list);
REQUIRE(reply);

reply = ns.discard_changes(provider);
REQUIRE(reply);
}

TEST_CASE("create_get_non_top")
{
ydk::path::Repository repo{TEST_HOME};
NetconfServiceProvider provider{repo, "127.0.0.1", "admin", "admin", 12022};
NetconfService ns{};

// Create global configuration
auto bgp_set = openconfig_bgp::Bgp();
bgp_set.yfilter = YFilter::replace;
bgp_set.global->config->as = 65001;
bgp_set.global->config->router_id = "1.2.3.4";
auto reply = ns.edit_config(provider, DataStore::candidate, bgp_set);
REQUIRE(reply);

// Add neighbor configuration
auto neighbor = openconfig_bgp::Bgp::Neighbors::Neighbor();
neighbor.neighbor_address = "1.2.3.4";
neighbor.config->neighbor_address = "1.2.3.4";
reply = ns.edit_config(provider, DataStore::candidate, neighbor);
REQUIRE(reply);

// Get and validate neighbor configuration
auto bgp_filter = openconfig_bgp::Bgp();
auto neighbor_filter = make_shared<openconfig_bgp::Bgp::Neighbors::Neighbor>();
neighbor_filter->neighbor_address = "1.2.3.4";
bgp_filter.neighbors->neighbor.append(neighbor_filter);
auto neighbor_entity = ns.get_config(provider, DataStore::candidate, *neighbor_filter);
REQUIRE(neighbor_entity!=nullptr);

auto neighbor_ptr = dynamic_cast<openconfig_bgp::Bgp::Neighbors::Neighbor*>(neighbor_entity.get());
REQUIRE(neighbor_ptr!=nullptr);
REQUIRE(*neighbor_ptr == neighbor);

reply = ns.discard_changes(provider);
REQUIRE(reply);
}

TEST_CASE("get_openconfig_interfaces_and_bgp")
{
NetconfServiceProvider provider{"127.0.0.1", "admin", "admin", 12022};
Expand Down

0 comments on commit c24a515

Please sign in to comment.