Skip to content

Commit

Permalink
Resolved issue CiscoDevNet#774
Browse files Browse the repository at this point in the history
  • Loading branch information
ygorelik committed Jul 17, 2019
1 parent f7cb634 commit 2036891
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 82 deletions.
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* Added utility function to compare two entities and build diff ([#925](https://github.com/CiscoDevNet/ydk-gen/issues/925))

#### Resolved GitHub issues
* NETCONF provider should raise more appropriate exceptions ([#774](https://github.com/CiscoDevNet/ydk-gen/issues/774))
* Go: When entity having children is built from model API the child entities parent is nil ([#938](https://github.com/CiscoDevNet/ydk-gen/issues/938))


### 2019-05-15 version 0.8.3

#### Bundle improvements
Expand Down
3 changes: 3 additions & 0 deletions sdk/cpp/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#### New features and enhancements
* Added utility function to compare two entities and build diff ([#925](https://github.com/CiscoDevNet/ydk-gen/issues/925))

#### Resolved GitHub issues
* NETCONF provider should raise more appropriate exceptions ([#774](https://github.com/CiscoDevNet/ydk-gen/issues/774))


### 2019-05-15 version 0.8.3

Expand Down
25 changes: 20 additions & 5 deletions sdk/cpp/core/src/netconf_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,19 @@ static string get_netconf_payload(path::DataNode & input, const string & data_t
return payload;
}

static string extract_rpc_error(const string & reply)
{
string msg = "RPC error occurred; check log file for details";
auto error_tag_pos = reply.find("<error-message");
auto error_tag_close_pos = reply.find("</error-message>");
if (error_tag_pos != string::npos && error_tag_close_pos != string::npos)
{
auto msg_start = reply.find(">", error_tag_pos) + 1;
msg = reply.substr(msg_start, error_tag_close_pos-msg_start);
}
return msg;
}

static shared_ptr<path::DataNode> handle_crud_edit_reply(string reply, NetconfClient & client, bool candidate_supported)
{
if(reply.find("<ok/>") == string::npos)
Expand All @@ -572,8 +585,9 @@ static shared_ptr<path::DataNode> handle_crud_edit_reply(string reply, NetconfCl
YLOG_INFO("============= RPC received from device =============\n{}", reply);
if(reply.find("<ok/>") == string::npos)
{
YLOG_ERROR("RPC error occurred: {}", reply);
throw(YServiceProviderError{reply});
YLOG_ERROR("RPC error occurred:\n{}", reply);
auto msg = extract_rpc_error(reply);
throw(YServiceProviderError(msg));
}
}

Expand Down Expand Up @@ -603,7 +617,7 @@ std::string get_netconf_output(const string & reply)
if (rpc_output.length() == reply.length())
{
YLOG_ERROR( "Cannot find 'data' tag in RPC reply from device\n{}", reply);
throw(YServiceProviderError{reply});
throw(YServiceProviderError{"Cannot find 'data' tag in RPC reply"});
}

return rpc_output;
Expand Down Expand Up @@ -741,8 +755,9 @@ static void check_rpc_reply_for_error(const string& reply)
{
if(reply.find("<rpc-error") != string::npos)
{
YLOG_ERROR("RPC error occurred: {}", reply);
throw(YServiceProviderError{reply});
YLOG_ERROR("RPC error occurred:\n{}", reply);
auto msg = extract_rpc_error(reply);
throw(YServiceProviderError(msg));
}
}

Expand Down
10 changes: 1 addition & 9 deletions sdk/cpp/core/tests/models/ydktest-sanity@2015-11-17.yang
Original file line number Diff line number Diff line change
Expand Up @@ -338,15 +338,7 @@ module ydktest-sanity {

leaf bits-value {
description "this is bits type value";
type bits {
bit disable-nagle {
position 0;
}

bit auto-sense-speed {
position 1;
}
}
type types:Ydk-bits-type;
default "auto-sense-speed";
}

Expand Down
12 changes: 12 additions & 0 deletions sdk/cpp/core/tests/models/ydktest-types@2016-05-23.yang
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ module ydktest-types {
description "Identityref type";
}

typedef Ydk-bits-type {
description "this is bits type value";
type bits {
bit disable-nagle {
position 0;
}
bit auto-sense-speed {
position 1;
}
}
}

feature crypto {
description
"crypto feature";
Expand Down
1 change: 1 addition & 0 deletions sdk/go/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Added utility function to compare two entities and build diff ([#925](https://github.com/CiscoDevNet/ydk-gen/issues/925))

#### Resolved GitHub issues
* NETCONF provider should raise more appropriate exceptions ([#774](https://github.com/CiscoDevNet/ydk-gen/issues/774))
* Go: When entity having children is built from model API the child entities parent is nil ([#938](https://github.com/CiscoDevNet/ydk-gen/issues/938))


Expand Down
2 changes: 1 addition & 1 deletion sdk/go/core/tests/service_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (suite *ExecutorServiceTestSuite) TestLockUnlockFail() {
suite.ExecutorService.ExecuteRpc(&suite.NetconfProvider, &lockRpc, nil) })
suite.Equal(funcDidPanic, true)
suite.Regexp("YServiceProviderError:", panicValue)
suite.Regexp("<error-tag>lock-denied</error-tag>", panicValue)
suite.Regexp("the configuration database is locked", panicValue)
}

func (suite *ExecutorServiceTestSuite) TestValidate() {
Expand Down
10 changes: 5 additions & 5 deletions sdk/go/core/tests/service_netconf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ func (suite *NetconfServiceTestSuite) TestLockUnlockFail() {
funcDidPanic, panicValue := didPanic(func() { suite.NS.Unlock(&suite.Provider, datastore.Running) })
suite.Equal(funcDidPanic, true)
suite.Regexp("YServiceProviderError:", panicValue)
errMsg := `<rpc-error>
<error-type>application</error-type>
<error-tag>operation-failed</error-tag>
<error-severity>error</error-severity>
</rpc-error>`
errMsg := "RPC error occurred; check log file for details"
// `<rpc-error>
// <error-type>application</error-type>
// <error-tag>operation-failed</error-tag>
// </rpc-error>`
suite.Regexp(errMsg, panicValue)
}

Expand Down
3 changes: 3 additions & 0 deletions sdk/python/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
* Expanded meta data in Python bundles by adding flags `has_must` and `has_when` ([#927](https://github.com/CiscoDevNet/ydk-gen/issues/927))
* Added utility function to compare two entities and build diff ([#925](https://github.com/CiscoDevNet/ydk-gen/issues/925))

#### Resolved GitHub issues
* NETCONF provider should raise more appropriate exceptions ([#774](https://github.com/CiscoDevNet/ydk-gen/issues/774))


### 2019-05-15 version 0.8.3

Expand Down
123 changes: 62 additions & 61 deletions sdk/python/core/tests/test_netconf_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,63 +32,64 @@
from test_utils import ParametrizedTestCase
from test_utils import get_device_info


test_create_pattern = """<\?xml version="1.0" encoding="UTF-8"\?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="[0-9]+">
<rpc-error>
<error-type>application</error-type>
<error-tag>data-exists</error-tag>
<error-severity>error</error-severity>
<error-path xmlns:ydkut="http://cisco.com/ns/yang/ydktest-sanity" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
/nc:rpc/nc:edit-config/nc:config/ydkut:runner/ydkut:one-list/ydkut:ldata\[ydkut:number='1'\]
</error-path>
<error-info>
<bad-element>ldata</bad-element>
</error-info>
</rpc-error>
</rpc-reply>"""
test_delete_pattern = """<\?xml version="1.0" encoding="UTF-8"\?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="[0-9]+">
<rpc-error>
<error-type>application</error-type>
<error-tag>data-missing</error-tag>
<error-severity>error</error-severity>
<error-path xmlns:ydkut="http://cisco.com/ns/yang/ydktest-sanity" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
/nc:rpc/nc:edit-config/nc:config/ydkut:runner/ydkut:one-list/ydkut:ldata\[ydkut:number='1'\]
</error-path>
<error-info>
<bad-element>ldata</bad-element>
</error-info>
</rpc-error>
</rpc-reply>"""
test_delete_leaf_pattern = """<\?xml version="1.0" encoding="UTF-8"\?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="[0-9]+">
<rpc-error>
<error-type>application</error-type>
<error-tag>data-missing</error-tag>
<error-severity>error</error-severity>
<error-path xmlns:ydkut="http://cisco.com/ns/yang/ydktest-sanity" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
/nc:rpc/nc:edit-config/nc:config/ydkut:runner/ydkut:ytypes/ydkut:built-in-t/ydkut:number8
</error-path>
<error-info>
<bad-element>number8</bad-element>
</error-info>
</rpc-error>
</rpc-reply>"""
test_delete_leaflist_pattern = """<\?xml version="1.0" encoding="UTF-8"\?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="[0-9]+">
<rpc-error>
<error-type>application</error-type>
<error-tag>data-missing</error-tag>
<error-severity>error</error-severity>
<error-path xmlns:ydkut="http://cisco.com/ns/yang/ydktest-sanity" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
/nc:rpc/nc:edit-config/nc:config/ydkut:runner/ydkut:ytypes/ydkut:built-in-t/ydkut:enum-llist\[.="local"\]
</error-path>
<error-info>
<bad-element>enum-llist</bad-element>
</error-info>
</rpc-error>
</rpc-reply>"""
netconf_default_error_pattern = "RPC error occurred; check log file for details"

# test_create_pattern = """<\?xml version="1.0" encoding="UTF-8"\?>
# <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="[0-9]+">
# <rpc-error>
# <error-type>application</error-type>
# <error-tag>data-exists</error-tag>
# <error-severity>error</error-severity>
# <error-path xmlns:ydkut="http://cisco.com/ns/yang/ydktest-sanity" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
# /nc:rpc/nc:edit-config/nc:config/ydkut:runner/ydkut:one-list/ydkut:ldata\[ydkut:number='1'\]
# </error-path>
# <error-info>
# <bad-element>ldata</bad-element>
# </error-info>
# </rpc-error>
# </rpc-reply>"""
# test_delete_pattern = """<\?xml version="1.0" encoding="UTF-8"\?>
# <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="[0-9]+">
# <rpc-error>
# <error-type>application</error-type>
# <error-tag>data-missing</error-tag>
# <error-severity>error</error-severity>
# <error-path xmlns:ydkut="http://cisco.com/ns/yang/ydktest-sanity" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
# /nc:rpc/nc:edit-config/nc:config/ydkut:runner/ydkut:one-list/ydkut:ldata\[ydkut:number='1'\]
# </error-path>
# <error-info>
# <bad-element>ldata</bad-element>
# </error-info>
# </rpc-error>
# </rpc-reply>"""
# test_delete_leaf_pattern = """<\?xml version="1.0" encoding="UTF-8"\?>
# <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="[0-9]+">
# <rpc-error>
# <error-type>application</error-type>
# <error-tag>data-missing</error-tag>
# <error-severity>error</error-severity>
# <error-path xmlns:ydkut="http://cisco.com/ns/yang/ydktest-sanity" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
# /nc:rpc/nc:edit-config/nc:config/ydkut:runner/ydkut:ytypes/ydkut:built-in-t/ydkut:number8
# </error-path>
# <error-info>
# <bad-element>number8</bad-element>
# </error-info>
# </rpc-error>
# </rpc-reply>"""
# test_delete_leaflist_pattern = """<\?xml version="1.0" encoding="UTF-8"\?>
# <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="[0-9]+">
# <rpc-error>
# <error-type>application</error-type>
# <error-tag>data-missing</error-tag>
# <error-severity>error</error-severity>
# <error-path xmlns:ydkut="http://cisco.com/ns/yang/ydktest-sanity" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
# /nc:rpc/nc:edit-config/nc:config/ydkut:runner/ydkut:ytypes/ydkut:built-in-t/ydkut:enum-llist\[.="local"\]
# </error-path>
# <error-info>
# <bad-element>enum-llist</bad-element>
# </error-info>
# </rpc-error>
# </rpc-reply>"""


class SanityTest(unittest.TestCase):
Expand Down Expand Up @@ -130,7 +131,7 @@ def test_replace(self):
runner_read = self.crud.read(self.ncc, runner_empty)
self.assertEqual(runner, runner_read)

@assert_with_error(test_create_pattern, YServiceProviderError)
@assert_with_error(netconf_default_error_pattern, YServiceProviderError)
def test_create(self):
runner = ysanity.Runner()
e_1 = ysanity.Runner.OneList.Ldata()
Expand All @@ -147,7 +148,7 @@ def test_create(self):
# CREATE AGAIN WITH ERROR
self.crud.update(self.ncc, runner)

@assert_with_error(test_delete_pattern, YServiceProviderError)
@assert_with_error(netconf_default_error_pattern, YServiceProviderError)
def test_delete(self):
runner = ysanity.Runner()
e_1 = ysanity.Runner.OneList.Ldata()
Expand Down Expand Up @@ -200,7 +201,7 @@ def test_merge(self):
runner_read = self.crud.read(self.ncc, runner_empty)
self.assertEqual(runner, runner_read)

@assert_with_error(test_delete_leaf_pattern, YServiceProviderError)
@assert_with_error(netconf_default_error_pattern, YServiceProviderError)
def test_delete_leaf(self):
runner = ysanity.Runner()
runner.ytypes.built_in_t.number8 = 10
Expand All @@ -213,7 +214,7 @@ def test_delete_leaf(self):
# DELETE AGAIN WITH ERROR
self.crud.update(self.ncc, runner)

@assert_with_error(test_delete_leaflist_pattern, YServiceProviderError)
@assert_with_error(netconf_default_error_pattern, YServiceProviderError)
def test_delete_leaflist(self):
runner = ysanity.Runner()
runner.ytypes.built_in_t.enum_llist.append(ysanity.YdkEnumTest.local)
Expand Down

0 comments on commit 2036891

Please sign in to comment.