Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for multiple entities for Go #768

Merged
24 commits merged into from
Apr 27, 2018
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ matrix:
include:
- os: linux
dist: trusty
go: 1.8
group: edge
- os: osx
osx_image: xcode7.3
language: generic
go: 1.8
go: 1.9
- env: DOCKER=true OS_TYPE=centos OS_VERSION=centos7 PYTHON_VERSION=2.7
- env: DOCKER=true OS_TYPE=centos OS_VERSION=centos7 PYTHON_VERSION=3.6
- env: DOCKER=true OS_TYPE=ubuntu OS_VERSION=xenial PYTHON_VERSION=2.7
Expand Down
10 changes: 6 additions & 4 deletions sdk/cpp/core/src/path/netconf_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,9 @@ static string get_filter_payload(path::Rpc & ydk_rpc)
{
auto entity = ydk_rpc.get_input_node().find("filter");
if(entity.empty()){
YLOG_ERROR("Failed to get entity node.");
throw(YInvalidArgumentError{"Failed to get entity node"});
YLOG_WARN("Failed to get filter node for RPC; it then will be skipped.");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this changed to warning?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not an error when filter is not present. In this case the whole device configuration will be fetched.

return string{};
//throw(YInvalidArgumentError{"Failed to get entity node"});
}

auto datanode = entity[0];
Expand All @@ -500,8 +501,9 @@ static string get_filter_payload(path::Rpc & ydk_rpc)
static string get_netconf_payload(path::DataNode & input, const string & data_tag, const string & data_value)
{
path::Codec codec_service{};
input.create_datanode(data_tag, data_value);

if (data_tag != "filter" || data_value != "") {
input.create_datanode(data_tag, data_value);
}
string payload{"<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"};
payload+=codec_service.encode(input, EncodingFormat::XML, true);
payload+="</rpc>";
Expand Down
19 changes: 11 additions & 8 deletions sdk/cpp/core/src/ydk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,21 +117,23 @@ static ydk::EncodingFormat get_real_encoding(EncodingFormat encoding)
{
switch(encoding)
{
case XML:
return ydk::EncodingFormat::XML;
case JSON:
return ydk::EncodingFormat::JSON;
case XML:
default:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default cases should be avoided. Suggest removing this or adding cases for all the members of the enum

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compiler logged warning message pointing that 'default' case is missing. I was taught always include 'default' case. If not included the 'switch' must be re-factored to if-else statements.

return ydk::EncodingFormat::XML;
}
}

static ydk::Protocol get_real_protocol(Protocol protocol)
{
switch(protocol)
{
case Netconf:
return ydk::Protocol::netconf;
case Restconf:
return ydk::Protocol::restconf;
case Netconf:
default:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above. Better to avoid default switch cases

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compiler logged warning message pointing that 'default' case is missing. I was taught always include 'default' case. If not included the 'switch' must be re-factored to if-else statements.

return ydk::Protocol::netconf;
}
}

Expand Down Expand Up @@ -187,16 +189,16 @@ static void handle_error(YDKState* state)
state->error_type = YDK_MODEL_ERROR;
handle_error_message(state, e.what());
}
catch (const ydk::YError & e) {
state->error_type = YDK_ERROR;
catch(const ydk::path::YCodecError & e) {
state->error_type = YDK_CODEC_ERROR;
handle_error_message(state, e.what());
}
catch(const ydk::path::YCoreError & e) {
state->error_type = YDK_CORE_ERROR;
handle_error_message(state, e.what());
}
catch(const ydk::path::YCodecError & e) {
state->error_type = YDK_CODEC_ERROR;
catch (const ydk::YError & e) {
state->error_type = YDK_ERROR;
handle_error_message(state, e.what());
}
}
Expand Down Expand Up @@ -869,6 +871,7 @@ LogLevel GetLoggingLevel(void)

case spdlog::level::critical:
case spdlog::level::err:
default:
return ERROR;
}
}
Expand Down
27 changes: 0 additions & 27 deletions sdk/cpp/tests/test_netconf_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,30 +328,3 @@ TEST_CASE("ietf_get_rpc")
cout << "Exception while executing RPC: " << ex.what() << endl;
}
}

TEST_CASE("get_config_openconfig_interfaces_and_bgp")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason for deleting this test case?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It exposes issue 727. I will put it back after fixing the issue.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. It's probably better to comment it out with that explanation rather than deleting everything.

See this example:
https://github.com/ygorelik/ydk-gen/blob/715bed51b22bf3cb9e1e8d69aee23f9ee2d9544e/sdk/cpp/tests/test_netconf_service.cpp#L40

{
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();

std::shared_ptr<ydk::path::Rpc> read_rpc { schema.create_rpc("ietf-netconf:get") };

// filter
openconfig_interfaces::Interfaces interfaces_filter{};
openconfig_bgp::Bgp bgp_filter{};

std::string filter_string = get_xml_subtree_filter_payload(interfaces_filter, provider);
filter_string += "\n" + get_xml_subtree_filter_payload(bgp_filter, provider);

read_rpc->get_input_node().create_datanode("filter", filter_string);

auto read_result = (*read_rpc)(provider.get_session());
REQUIRE(read_result != nullptr);

// Print config
vector<shared_ptr<ydk::path::DataNode>> data_nodes = read_result->get_children();
for (auto dn : data_nodes) {
print_data_node(dn);
}
}
20 changes: 18 additions & 2 deletions sdk/go/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
- [Docker](#docker)
- [How to Install](#how-to-install)
- [System Requirements](#system-requirements)
- [Installing](#installing)
- [Installing YDK](#installing-ydk)
- [Documentation and Support](#documentation-and-support)
- [Release Notes](#release-notes)

Expand Down Expand Up @@ -64,6 +64,16 @@ $ sudo yum install https://devhub.cisco.com/artifactory/rpm-ydk/0.7.1/libydk-0.7

```

Golang
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be made to a heading? Something like

### Golang version

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.


The YDK requires Go version 1.9 or higher. If this is not the case, follow below installation steps. Make sure that environment variables GOROOT and GOPATH are properly set.
```
$ sudo wget https://storage.googleapis.com/golang/go1.9.2.linux-amd64.tar.gz &> /dev/null
$ sudo tar -zxf go1.9.2.linux-amd64.tar.gz -C /usr/local/
$ export GOROOT="/usr/local/go"
$ export PATH=$GOROOT/bin:$PATH
```

**Mac**
It is recommended to install [homebrew](http://brew.sh) and Xcode command line tools on your system before installing YDK-Go:
```
Expand All @@ -74,8 +84,14 @@ $ xcode-select --install
$ curl -O https://devhub.cisco.com/artifactory/osx-ydk/0.7.1/libydk-0.7.1-Darwin.pkg
$ sudo installer -pkg libydk-0.7.1-Darwin.pkg -target /
```
The YDK requires Go version 1.9 or higher. If this is not the case, follow below installation steps. Make sure that environment variables GOROOT and GOPATH are properly set.
```
$ export CGO_ENABLED=0
$ export GOROOT_BOOTSTRAP=$GOROOT
$ gvm install go1.9.2
```

### Installing
### Installing YDK

You can install the latest `ydk` package using:
```
Expand Down
6 changes: 4 additions & 2 deletions sdk/go/core/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
### YDK GO
### YDK GO Core and Bundle Installation

To build, first install [C++ core](https://github.com/CiscoDevNet/ydk-gen#second-step-generate--install-the-core). Then execute the below steps to install the ydk package.
The YDK requires Go version 1.9 or higher. Make sure that corresponding software is installed and environment variables GOROOT and GOPATH are properly set before the YDK installation. Follow System Requirements [here](https://github.com/CiscoDevNet/ydk-gen/tree/master/sdk/go#system-requirements).

First, install [C++ core](https://github.com/CiscoDevNet/ydk-gen#second-step-generate--install-the-core). Then execute the below steps to install the ydk go core and bundle packages.

```
$ go get gopkg.in/stretchr/testify.v1
Expand Down
Loading