From 01f12316b08360e5f1c156f7f8c64bdda01cce19 Mon Sep 17 00:00:00 2001 From: Yan Gorelik Date: Thu, 8 Feb 2018 12:11:09 -0800 Subject: [PATCH 1/6] Fixed issue 632 --- .gitignore | 1 + sdk/cpp/core/src/path/data_node.cpp | 26 +++++++++++++------------- sdk/cpp/core/src/path/schema_node.cpp | 8 ++++---- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index b3cfcdc7e..d0609c06b 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,4 @@ gen-api/ *.sublime-project *.sublime-workspace *.idea +scripts diff --git a/sdk/cpp/core/src/path/data_node.cpp b/sdk/cpp/core/src/path/data_node.cpp index 8eaf36274..2e1241b8e 100644 --- a/sdk/cpp/core/src/path/data_node.cpp +++ b/sdk/cpp/core/src/path/data_node.cpp @@ -27,19 +27,17 @@ namespace ydk { -namespace path -{ - -static void check_ly_schema_node_for_path(lyd_node* node, const std::string & path) -{ - if(node == nullptr || node->schema == nullptr || node->schema->priv == nullptr) - { - YLOG_ERROR("Couldn't fetch schema node {}!", path); - throw(YCoreError{"Couldn't fetch schema node " + path}); - } -} - -} + namespace path + { + static void check_ly_schema_node_for_path(lyd_node* node, const std::string & path) + { + if(node == nullptr || node->schema == nullptr || node->schema->priv == nullptr) + { + YLOG_ERROR("Could not fetch schema node '{}'", path); + throw(YCoreError{"Could not fetch schema node: " + path}); + } + } + } } //////////////////////////////////////////////////////////////////////// @@ -86,6 +84,7 @@ ydk::path::DataNodeImpl::~DataNodeImpl() const ydk::path::SchemaNode& ydk::path::DataNodeImpl::get_schema_node() const { + YLOG_DEBUG("get_schema_node: Getting schema node for '{}'", m_node->schema->name); check_ly_schema_node_for_path(m_node, get_path()); auto schema_ptr = reinterpret_cast(m_node->schema->priv); return *schema_ptr; @@ -106,6 +105,7 @@ ydk::path::DataNodeImpl::get_path() const void ydk::path::DataNodeImpl::populate_new_schemas_from_path(const std::string& path) { + YLOG_DEBUG("populate_new_schemas_from_path: Getting schema node for '{}'", m_node->schema->name); check_ly_schema_node_for_path(m_node, path); auto snode = reinterpret_cast(m_node->schema->priv); snode->populate_new_schemas_from_path(path); diff --git a/sdk/cpp/core/src/path/schema_node.cpp b/sdk/cpp/core/src/path/schema_node.cpp index 23e07b86f..16e53ee3e 100644 --- a/sdk/cpp/core/src/path/schema_node.cpp +++ b/sdk/cpp/core/src/path/schema_node.cpp @@ -65,16 +65,16 @@ ydk::path::SchemaNodeImpl::populate_augmented_schema_node(vector& anc } } else { - while(node) { - auto p = node; - while(p && (p->nodetype == LYS_USES)) { + const struct lys_node *last = nullptr; + while (auto p = lys_getnext(last, node->parent, nullptr, 0)) { + last = p; + while (p->nodetype == LYS_USES) { p = p->child; } if (p) { YLOG_DEBUG("Populating new schema node '{}'", string(p->name)); m_children.emplace_back(make_unique(this, const_cast(p))); } - node = node->next; } } } From 014037da07aedd7b7b2d454a726ce1fd3f47583a Mon Sep 17 00:00:00 2001 From: Yan Gorelik Date: Fri, 9 Feb 2018 14:10:03 -0800 Subject: [PATCH 2/6] Added test cases for Issue 632 --- .../tests/models/ydktest-sanity-augm.yang | 71 ++++++++++++++++- .../ydktest-sanity-augm@2015-11-17.yang | 72 +++++++++++++++++- .../ydktest-sanity-submodule@2015-11-17.yang | 76 ++++++++++++++++++- .../ydktest-sanity-submodule@2016-04-25.yang | 76 ++++++++++++++++++- sdk/cpp/core/tests/models/ydktest-sanity.yang | 75 +++++++++++++++--- .../models/ydktest-sanity@2015-11-17.yang | 17 +++++ sdk/cpp/tests/test_on_demand_loading.cpp | 23 ++++++ sdk/go/core/README.md | 27 ++++--- sdk/python/core/tests/test_sanity_path.py | 40 ++++++++++ .../ydktest-sanity-augm@2015-11-17.yang | 71 ++++++++++++++++- .../ydktest-sanity-submodule@2016-04-25.yang | 70 +++++++++++++++++ yang/ydktest/ydktest-sanity@2015-11-17.yang | 19 ++++- 12 files changed, 601 insertions(+), 36 deletions(-) diff --git a/sdk/cpp/core/tests/models/ydktest-sanity-augm.yang b/sdk/cpp/core/tests/models/ydktest-sanity-augm.yang index 64cdc7d9c..0cb35b5af 100644 --- a/sdk/cpp/core/tests/models/ydktest-sanity-augm.yang +++ b/sdk/cpp/core/tests/models/ydktest-sanity-augm.yang @@ -12,6 +12,7 @@ module ydktest-sanity-augm { //import ietf-inet-types { prefix "inet"; } //import Cisco-IOS-XR-types { prefix "xr"; } + import ydktest-sanity { prefix "ysanity"; } @@ -97,7 +98,71 @@ module ydktest-sanity-augm { } } + ///////////////////////////////////////////////////////// + // native / interface / Tunnel + ///////////////////////////////////////////////////////// + grouping config-interface-tunnel-grouping { + container nhrp { + description + "NHRP Interface commands"; + container event-publisher { + description + "Enable NHRP smart spoke feature"; + leaf max-event-timeout { + description + "Number of seconds"; + type uint8 { + range "1..22"; + } + } + } + leaf group { + description + "group name string"; + type string; + } + } + + container tunnel { + description + "protocol-over-protocol tunneling"; + + // interface * / tunnel bandwidth + container bandwidth { + description + "Set tunnel bandwidth informational parameter"; + leaf receive { + description + "Receive bandwidth"; + type uint32; + } + leaf transmit { + description + "Transmit bandwidth"; + type uint32; + } + } + + // interface * / tunnel source + leaf source { + description + "source of tunnel packets"; + type string; + } + + // interface * / tunnel destination + leaf destination { + description + "destination of tunnel"; + type string; + } + } + } + + ///////////////////////////////////////////////////////// + // augmentation + ///////////////////////////////////////////////////////// augment "/ysanity:runner" { description "augment to one"; uses one-twin-aug; @@ -108,7 +173,7 @@ module ydktest-sanity-augm { uses one-aug-level; } - augment "/ysanity:runner/ysanity:one" { + augment "/ysanity:runner/ysanity:one" { description "augment leaf to one"; uses leaf-aug; } @@ -127,4 +192,8 @@ module ydktest-sanity-augm { } } + augment "/ysanity:native/ysanity:interface/ysanity:Tunnel" { + uses config-interface-tunnel-grouping; + } + } diff --git a/sdk/cpp/core/tests/models/ydktest-sanity-augm@2015-11-17.yang b/sdk/cpp/core/tests/models/ydktest-sanity-augm@2015-11-17.yang index 89b67f284..0cb35b5af 100644 --- a/sdk/cpp/core/tests/models/ydktest-sanity-augm@2015-11-17.yang +++ b/sdk/cpp/core/tests/models/ydktest-sanity-augm@2015-11-17.yang @@ -12,6 +12,7 @@ module ydktest-sanity-augm { //import ietf-inet-types { prefix "inet"; } //import Cisco-IOS-XR-types { prefix "xr"; } + import ydktest-sanity { prefix "ysanity"; } @@ -86,7 +87,6 @@ module ydktest-sanity-augm { } } - grouping one-twin-aug { description "augment runner with same name container but different namespace"; container one { @@ -98,7 +98,71 @@ module ydktest-sanity-augm { } } + ///////////////////////////////////////////////////////// + // native / interface / Tunnel + ///////////////////////////////////////////////////////// + grouping config-interface-tunnel-grouping { + container nhrp { + description + "NHRP Interface commands"; + container event-publisher { + description + "Enable NHRP smart spoke feature"; + leaf max-event-timeout { + description + "Number of seconds"; + type uint8 { + range "1..22"; + } + } + } + leaf group { + description + "group name string"; + type string; + } + } + + container tunnel { + description + "protocol-over-protocol tunneling"; + + // interface * / tunnel bandwidth + container bandwidth { + description + "Set tunnel bandwidth informational parameter"; + leaf receive { + description + "Receive bandwidth"; + type uint32; + } + leaf transmit { + description + "Transmit bandwidth"; + type uint32; + } + } + // interface * / tunnel source + leaf source { + description + "source of tunnel packets"; + type string; + } + + // interface * / tunnel destination + leaf destination { + description + "destination of tunnel"; + type string; + } + } + } + + + ///////////////////////////////////////////////////////// + // augmentation + ///////////////////////////////////////////////////////// augment "/ysanity:runner" { description "augment to one"; uses one-twin-aug; @@ -109,7 +173,7 @@ module ydktest-sanity-augm { uses one-aug-level; } - augment "/ysanity:runner/ysanity:one" { + augment "/ysanity:runner/ysanity:one" { description "augment leaf to one"; uses leaf-aug; } @@ -128,4 +192,8 @@ module ydktest-sanity-augm { } } + augment "/ysanity:native/ysanity:interface/ysanity:Tunnel" { + uses config-interface-tunnel-grouping; + } + } diff --git a/sdk/cpp/core/tests/models/ydktest-sanity-submodule@2015-11-17.yang b/sdk/cpp/core/tests/models/ydktest-sanity-submodule@2015-11-17.yang index 861e81189..d955d180f 100644 --- a/sdk/cpp/core/tests/models/ydktest-sanity-submodule@2015-11-17.yang +++ b/sdk/cpp/core/tests/models/ydktest-sanity-submodule@2015-11-17.yang @@ -25,13 +25,13 @@ submodule ydktest-sanity-submodule { E-mail: cs-yang@cisco.com"; - description + description "This module contains a collection of YANG definitions for sanity package. This module contains LIST definitions for the following management objects: - + Copyright (c) 2013-2014 by Cisco Systems, Inc. All rights reserved."; @@ -56,8 +56,78 @@ submodule ydktest-sanity-submodule { } } } - + container sub-test { uses one-sub-level; } + + grouping interface-common-grouping { + // interface * / description + leaf description { + description + "Interface specific description"; + type string { + length "0..240"; + } + } + + // interface * / mtu + leaf mtu { + description + "Set the interface Maximum Transmission Unit (MTU)"; + type uint16 { + range "64..18000"; + } + } + } + + grouping config-interface-grouping { + container interface { + description + "Configure Interfaces"; + + // interface GigabitEthernet + list Gigabitethernet { + description + "GigabitEthernet IEEE 802.3z"; + key "name"; + leaf name { + type string; + } + leaf media-type { + description + "Media type"; + type enumeration { + enum "auto-select"; + enum "rj45"; + enum "sfp"; + } + } + uses interface-common-grouping; + } + + // interface Loopback + list Loopback { + description + "Loopback interface"; + key "name"; + leaf name { + type uint32; + } + uses interface-common-grouping; + } + + // interface Tunnel # + list Tunnel { + description + "Tunnel interface"; + key "name"; + leaf name { + type uint32; + } + uses interface-common-grouping; + } + } + } + } diff --git a/sdk/cpp/core/tests/models/ydktest-sanity-submodule@2016-04-25.yang b/sdk/cpp/core/tests/models/ydktest-sanity-submodule@2016-04-25.yang index 861e81189..d955d180f 100644 --- a/sdk/cpp/core/tests/models/ydktest-sanity-submodule@2016-04-25.yang +++ b/sdk/cpp/core/tests/models/ydktest-sanity-submodule@2016-04-25.yang @@ -25,13 +25,13 @@ submodule ydktest-sanity-submodule { E-mail: cs-yang@cisco.com"; - description + description "This module contains a collection of YANG definitions for sanity package. This module contains LIST definitions for the following management objects: - + Copyright (c) 2013-2014 by Cisco Systems, Inc. All rights reserved."; @@ -56,8 +56,78 @@ submodule ydktest-sanity-submodule { } } } - + container sub-test { uses one-sub-level; } + + grouping interface-common-grouping { + // interface * / description + leaf description { + description + "Interface specific description"; + type string { + length "0..240"; + } + } + + // interface * / mtu + leaf mtu { + description + "Set the interface Maximum Transmission Unit (MTU)"; + type uint16 { + range "64..18000"; + } + } + } + + grouping config-interface-grouping { + container interface { + description + "Configure Interfaces"; + + // interface GigabitEthernet + list Gigabitethernet { + description + "GigabitEthernet IEEE 802.3z"; + key "name"; + leaf name { + type string; + } + leaf media-type { + description + "Media type"; + type enumeration { + enum "auto-select"; + enum "rj45"; + enum "sfp"; + } + } + uses interface-common-grouping; + } + + // interface Loopback + list Loopback { + description + "Loopback interface"; + key "name"; + leaf name { + type uint32; + } + uses interface-common-grouping; + } + + // interface Tunnel # + list Tunnel { + description + "Tunnel interface"; + key "name"; + leaf name { + type uint32; + } + uses interface-common-grouping; + } + } + } + } diff --git a/sdk/cpp/core/tests/models/ydktest-sanity.yang b/sdk/cpp/core/tests/models/ydktest-sanity.yang index 549f72909..8e655ad88 100644 --- a/sdk/cpp/core/tests/models/ydktest-sanity.yang +++ b/sdk/cpp/core/tests/models/ydktest-sanity.yang @@ -119,7 +119,9 @@ module ydktest-sanity { } container one { leaf name-of-one { - type string; + type string { + pattern '(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(%[\p{N}\p{L}]+)?'; + } } container two { @@ -146,10 +148,12 @@ module ydktest-sanity { description "this is string value"; type string; } + anyxml config { + description "test"; + } } } - grouping two-level { description "testing for couple of leaves"; container two { @@ -174,7 +178,6 @@ module ydktest-sanity { } } - grouping three-level { description "testing for couple of leaves"; container three { @@ -207,7 +210,6 @@ module ydktest-sanity { } } - grouping all-ytypes-class { description "testing for couple of leaves"; container ytypes { @@ -346,8 +348,8 @@ module ydktest-sanity { } default "auto-sense-speed"; } - -//TODO + + //TODO /*leaf-list bits-list { description "this is bits type list"; type bits { @@ -358,7 +360,7 @@ module ydktest-sanity { bit val2 { position 1; } - } + } }*/ leaf younion { @@ -473,7 +475,7 @@ module ydktest-sanity { type string; } } - + list identity-list { description "one list data"; key "id-ref"; @@ -495,10 +497,8 @@ module ydktest-sanity { } } } - } - grouping two-level-w-list { container two-list { description "config for one_level list data"; @@ -579,7 +579,7 @@ module ydktest-sanity { } } - grouping three-level-w-list-at-two { + grouping three-level-w-list-at-two { container inbtw-list { description "config for one_level list data"; list ldata { @@ -645,8 +645,42 @@ module ydktest-sanity { } } + grouping nested-naming { + container nested-naming { + container nested-naming { + container nested-naming { + leaf nested-naming { + type int32; + } + } + } + } + } + + grouping one-read-only { + description "testing for couple of leaves"; + container one-read-only { + config false; + description "one_read_only data"; + leaf number { + description "integer value type"; + type int32; + } + + leaf name { + description "this is string value"; + type string; + } + anyxml config { + description "test"; + } + } + } + container runner { + uses nested-naming; + //container at 1,2,3 nested level uses one-level; uses two-level; @@ -666,6 +700,8 @@ module ydktest-sanity { uses not-supported; + uses one-read-only; + container runner-2 { presence "Runner-2 is presence controlled"; @@ -681,4 +717,21 @@ module ydktest-sanity { } } } + + container native { + + leaf version { + description "Version"; + type string; + } + + leaf hostname { + description "Set system's network name"; + type string; + } + + uses config-interface-grouping; + + } // native + } diff --git a/sdk/cpp/core/tests/models/ydktest-sanity@2015-11-17.yang b/sdk/cpp/core/tests/models/ydktest-sanity@2015-11-17.yang index e24d92f98..8e655ad88 100644 --- a/sdk/cpp/core/tests/models/ydktest-sanity@2015-11-17.yang +++ b/sdk/cpp/core/tests/models/ydktest-sanity@2015-11-17.yang @@ -717,4 +717,21 @@ module ydktest-sanity { } } } + + container native { + + leaf version { + description "Version"; + type string; + } + + leaf hostname { + description "Set system's network name"; + type string; + } + + uses config-interface-grouping; + + } // native + } diff --git a/sdk/cpp/tests/test_on_demand_loading.cpp b/sdk/cpp/tests/test_on_demand_loading.cpp index 400207a8d..578a31061 100644 --- a/sdk/cpp/tests/test_on_demand_loading.cpp +++ b/sdk/cpp/tests/test_on_demand_loading.cpp @@ -137,3 +137,26 @@ TEST_CASE("on_demand_provider_loading_xml") auto cpython = std::make_shared(); codec_service.decode(codec_provider, AUGMENTED_XML_PAYLOAD, cpython); } + +TEST_CASE( "native_tunnel_create" ) +{ + ydk::path::Repository repo{TEST_HOME}; + ydk::path::NetconfSession session{repo, "127.0.0.1", "admin", "admin", 12022}; + ydk::path::RootSchemaNode& schema = session.get_root_schema(); + + auto & native = schema.create_datanode("ydktest-sanity:native"); + + auto & tunnelInt = native.create_datanode("interface/Tunnel[name='521']"); + + auto & tunnel = tunnelInt.create_datanode("ydktest-sanity-augm:tunnel"); + + auto & source = tunnel.create_datanode("source", "Lo222"); + + auto & destination = tunnel.create_datanode("destination", "2.3.4.5"); + + ydk::path::Codec s{}; + + auto xml = s.encode(native, ydk::EncodingFormat::XML, false); + + std::cout << xml << std::endl; +} diff --git a/sdk/go/core/README.md b/sdk/go/core/README.md index 1cb7d3cc5..759818995 100644 --- a/sdk/go/core/README.md +++ b/sdk/go/core/README.md @@ -1,34 +1,33 @@ ### YDK GO -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 (until we have the YDK go repository on github, this is a little unusal way to install go packages). +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. ``` +$ go get gopkg.in/stretchr/testify.v1 +$ cd /your/path/to/ydk-gen $ export GOPATH=/your/path/to/install/go/packages $ mkdir -p $GOPATH/src/github.com/CiscoDevNet/ydk-go/ydk -$ cp -r ydk/* $GOPATH/src/github.com/CiscoDevNet/ydk-go/ydk -$ cd ../../.. +$ cp -r sdk/go/core/ydk/* $GOPATH/src/github.com/CiscoDevNet/ydk-go/ydk $ ./generate.py --bundle profiles/test/ydktest-cpp.json --go $ cp -r gen-api/go/ydktest-bundle/ydk/models/* $GOPATH/src/github.com/CiscoDevNet/ydk-go/ydk/models -$ cd - ``` -Then execute the below to run the samples +Then execute the below to run sample tests ``` $ go run samples/cgo_path/cgo_path.go -``` -``` + $ go run samples/bgp_create/bgp_create.go -``` -``` + $ go run samples/bgp_read/bgp_read.go ``` To run tests: -```bash -$ cd ../../.. -$ ./generate.py --bundle profiles/test/ydktest-cpp.json --go -$ cp -r gen-api/go/ydktest-bundle/ydk/models/* $GOPATH/src/github.com/CiscoDevNet/ydk-go/ydk/models -$ go get gopkg.in/stretchr/testify.v1 +``` +$ cd /your/path/to/ydk-gen +$ cd sdk/cpp/core/tests/confd/ydktest +$ make clean +$ make all start +$ cd - $ cd sdk/go/core/tests $ go test ``` diff --git a/sdk/python/core/tests/test_sanity_path.py b/sdk/python/core/tests/test_sanity_path.py index 91ccb881d..6ecf86d7d 100644 --- a/sdk/python/core/tests/test_sanity_path.py +++ b/sdk/python/core/tests/test_sanity_path.py @@ -129,6 +129,46 @@ def test_get_schema(self): self.assertNotEqual( len(xml), 0 ) + def enable_logging(self): + import logging + log = logging.getLogger('ydk') + log.setLevel(logging.DEBUG) + handler = logging.StreamHandler() + formatter = logging.Formatter(("%(asctime)s - %(name)s - %(levelname)s - %(message)s")) + handler.setFormatter(formatter) + log.addHandler(handler) + + def test_create_gre_tunnel_on_demand(self): + #self.enable_logging() + + from ydk.models.ydktest import ydktest_sanity as ysanity + from ydk.providers import NetconfServiceProvider + from ydk.services import NetconfService, Datastore + from ydk.services import CRUDService + + provider = NetconfServiceProvider( + "127.0.0.1", + "admin", + "admin", + 12022) + + native = ysanity.Native() + + tunnel = native.interface.Tunnel() + tunnel.name = 521 + tunnel.description = "test tunnel" + + # Configure protocol-over-protocol tunneling + tunnel.tunnel.source = "1.2.3.4" + tunnel.tunnel.destination = "4.3.2.1" + tunnel.tunnel.bandwidth.receive = 100000 + tunnel.tunnel.bandwidth.transmit = 100000 + + native.interface.tunnel.append(tunnel) + + crud_service = CRUDService(); + crud_service.create(provider, native) + if __name__ == '__main__': device, non_demand, common_cache, timeout = get_device_info() diff --git a/yang/ydktest/ydktest-sanity-augm@2015-11-17.yang b/yang/ydktest/ydktest-sanity-augm@2015-11-17.yang index 64cdc7d9c..0cb35b5af 100644 --- a/yang/ydktest/ydktest-sanity-augm@2015-11-17.yang +++ b/yang/ydktest/ydktest-sanity-augm@2015-11-17.yang @@ -12,6 +12,7 @@ module ydktest-sanity-augm { //import ietf-inet-types { prefix "inet"; } //import Cisco-IOS-XR-types { prefix "xr"; } + import ydktest-sanity { prefix "ysanity"; } @@ -97,7 +98,71 @@ module ydktest-sanity-augm { } } + ///////////////////////////////////////////////////////// + // native / interface / Tunnel + ///////////////////////////////////////////////////////// + grouping config-interface-tunnel-grouping { + container nhrp { + description + "NHRP Interface commands"; + container event-publisher { + description + "Enable NHRP smart spoke feature"; + leaf max-event-timeout { + description + "Number of seconds"; + type uint8 { + range "1..22"; + } + } + } + leaf group { + description + "group name string"; + type string; + } + } + + container tunnel { + description + "protocol-over-protocol tunneling"; + + // interface * / tunnel bandwidth + container bandwidth { + description + "Set tunnel bandwidth informational parameter"; + leaf receive { + description + "Receive bandwidth"; + type uint32; + } + leaf transmit { + description + "Transmit bandwidth"; + type uint32; + } + } + + // interface * / tunnel source + leaf source { + description + "source of tunnel packets"; + type string; + } + + // interface * / tunnel destination + leaf destination { + description + "destination of tunnel"; + type string; + } + } + } + + ///////////////////////////////////////////////////////// + // augmentation + ///////////////////////////////////////////////////////// augment "/ysanity:runner" { description "augment to one"; uses one-twin-aug; @@ -108,7 +173,7 @@ module ydktest-sanity-augm { uses one-aug-level; } - augment "/ysanity:runner/ysanity:one" { + augment "/ysanity:runner/ysanity:one" { description "augment leaf to one"; uses leaf-aug; } @@ -127,4 +192,8 @@ module ydktest-sanity-augm { } } + augment "/ysanity:native/ysanity:interface/ysanity:Tunnel" { + uses config-interface-tunnel-grouping; + } + } diff --git a/yang/ydktest/ydktest-sanity-submodule@2016-04-25.yang b/yang/ydktest/ydktest-sanity-submodule@2016-04-25.yang index a17bfef4b..d955d180f 100644 --- a/yang/ydktest/ydktest-sanity-submodule@2016-04-25.yang +++ b/yang/ydktest/ydktest-sanity-submodule@2016-04-25.yang @@ -60,4 +60,74 @@ submodule ydktest-sanity-submodule { container sub-test { uses one-sub-level; } + + grouping interface-common-grouping { + // interface * / description + leaf description { + description + "Interface specific description"; + type string { + length "0..240"; + } + } + + // interface * / mtu + leaf mtu { + description + "Set the interface Maximum Transmission Unit (MTU)"; + type uint16 { + range "64..18000"; + } + } + } + + grouping config-interface-grouping { + container interface { + description + "Configure Interfaces"; + + // interface GigabitEthernet + list Gigabitethernet { + description + "GigabitEthernet IEEE 802.3z"; + key "name"; + leaf name { + type string; + } + leaf media-type { + description + "Media type"; + type enumeration { + enum "auto-select"; + enum "rj45"; + enum "sfp"; + } + } + uses interface-common-grouping; + } + + // interface Loopback + list Loopback { + description + "Loopback interface"; + key "name"; + leaf name { + type uint32; + } + uses interface-common-grouping; + } + + // interface Tunnel # + list Tunnel { + description + "Tunnel interface"; + key "name"; + leaf name { + type uint32; + } + uses interface-common-grouping; + } + } + } + } diff --git a/yang/ydktest/ydktest-sanity@2015-11-17.yang b/yang/ydktest/ydktest-sanity@2015-11-17.yang index eed658f98..8e655ad88 100644 --- a/yang/ydktest/ydktest-sanity@2015-11-17.yang +++ b/yang/ydktest/ydktest-sanity@2015-11-17.yang @@ -679,7 +679,7 @@ module ydktest-sanity { container runner { - //uses nested-naming; + uses nested-naming; //container at 1,2,3 nested level uses one-level; @@ -717,4 +717,21 @@ module ydktest-sanity { } } } + + container native { + + leaf version { + description "Version"; + type string; + } + + leaf hostname { + description "Set system's network name"; + type string; + } + + uses config-interface-grouping; + + } // native + } From 5ba5badf7ad227e3f259d9966a47e05d2f63f5ae Mon Sep 17 00:00:00 2001 From: Yan Gorelik Date: Tue, 13 Feb 2018 15:31:20 -0800 Subject: [PATCH 3/6] Fixed issue 627 --- sdk/cpp/core/src/path/netconf_session.cpp | 6 ++-- sdk/cpp/core/src/path/path_private.hpp | 3 ++ sdk/cpp/core/src/path/repository.cpp | 35 +++++++++++++++++++---- sdk/cpp/core/src/path_api.hpp | 1 + sdk/python/core/tests/test_sanity_path.py | 24 +++++++--------- 5 files changed, 48 insertions(+), 21 deletions(-) diff --git a/sdk/cpp/core/src/path/netconf_session.cpp b/sdk/cpp/core/src/path/netconf_session.cpp index e1874bb2e..e45e60fc9 100644 --- a/sdk/cpp/core/src/path/netconf_session.cpp +++ b/sdk/cpp/core/src/path/netconf_session.cpp @@ -194,19 +194,19 @@ void NetconfSession::initialize_repo(path::Repository & repo, bool on_demand) std::vector yang_caps; std::vector empty_caps; - + std::vector all_caps = capabilities_parser.parse(server_capabilities); if (on_demand) yang_caps = capabilities_parser.parse(empty_caps); else - yang_caps = capabilities_parser.parse(server_capabilities); + yang_caps = all_caps; root_schema = repo.create_root_schema(lookup_table, yang_caps); - if(root_schema.get() == nullptr) { YLOG_ERROR("Root schema cannot be obtained"); throw(YIllegalStateError{"Root schema cannot be obtained"}); } + repo.set_server_capabilities(all_caps); } NetconfSession::~NetconfSession() diff --git a/sdk/cpp/core/src/path/path_private.hpp b/sdk/cpp/core/src/path/path_private.hpp index 46cfbbd40..e7847efe5 100644 --- a/sdk/cpp/core/src/path/path_private.hpp +++ b/sdk/cpp/core/src/path/path_private.hpp @@ -69,6 +69,7 @@ namespace ydk { public: std::string path; + std::vector server_caps; private: ly_ctx* create_ly_context(); @@ -82,6 +83,8 @@ namespace ydk { const lys_module* load_module(ly_ctx* ctx, const std::string& module_name, const std::string& revision); const lys_module* load_module(ly_ctx* ctx, const std::string& module_name, const std::string& revision, const std::vector& features, bool& new_module); + void get_module_capabilities(ydk::path::Capability& capability); + private: std::vector model_providers; bool using_temp_directory; diff --git a/sdk/cpp/core/src/path/repository.cpp b/sdk/cpp/core/src/path/repository.cpp index 0c0d75e90..b460dd045 100644 --- a/sdk/cpp/core/src/path/repository.cpp +++ b/sdk/cpp/core/src/path/repository.cpp @@ -111,7 +111,7 @@ void libyang_log_callback(LY_LOG_LEVEL level, const char *msg, const char *path) } ydk::path::RepositoryPtr::RepositoryPtr (path::ModelCachingOption caching_option) - : using_temp_directory(true), caching_option(caching_option) + : using_temp_directory(true), caching_option(caching_option), server_caps() { path = get_models_download_path(); ly_set_log_clb(libyang_log_callback, 1); @@ -119,7 +119,7 @@ ydk::path::RepositoryPtr::RepositoryPtr (path::ModelCachingOption caching_option ydk::path::RepositoryPtr::RepositoryPtr(const std::string& search_dir, path::ModelCachingOption caching_option) - : path{search_dir}, using_temp_directory(false), caching_option(caching_option) + : path{search_dir}, using_temp_directory(false), caching_option(caching_option), server_caps() { if (!file_exists(path)) @@ -428,13 +428,19 @@ const lys_module* ydk::path::RepositoryPtr::load_module(ly_ctx* ctx, const std::string& module_name) { bool new_module = true; - return load_module(ctx, module_name, "", {}, new_module); + std::string revision = ""; + ydk::path::Capability mod_cap = ydk::path::Capability{module_name, revision}; + get_module_capabilities(mod_cap); + return load_module(ctx, mod_cap, new_module); } const lys_module* ydk::path::RepositoryPtr::load_module(ly_ctx* ctx, const std::string& module_name, bool& new_module) { - return load_module(ctx, module_name, "", {}, new_module); + std::string revision = ""; + ydk::path::Capability mod_cap = ydk::path::Capability{module_name, revision}; + get_module_capabilities(mod_cap); + return load_module(ctx, mod_cap, new_module); } const lys_module* @@ -454,7 +460,9 @@ const lys_module* ydk::path::RepositoryPtr::load_module(ly_ctx* ctx, const std::string& module_name, const std::string& revision) { bool new_module = true; - return load_module(ctx, module_name, revision, {}, new_module); + ydk::path::Capability mod_cap = ydk::path::Capability{module_name, revision}; + get_module_capabilities(mod_cap); + return load_module(ctx, mod_cap, new_module); } const lys_module* @@ -483,6 +491,19 @@ ydk::path::RepositoryPtr::load_module(ly_ctx* ctx, const std::string& module, co return p; } +void +ydk::path::RepositoryPtr::get_module_capabilities(ydk::path::Capability & mod_cap) +{ + for (auto & cap: server_caps) { + if (cap.module == mod_cap.module && + (mod_cap.revision == "" || cap.revision == mod_cap.revision)) + { + mod_cap.features = cap.features; + mod_cap.deviations = cap.deviations; + } + } +} + /// /// @brief Adds a model provider. /// @@ -568,5 +589,9 @@ std::vector ydk::path::Repository::get_model_provider return m_priv_repo->get_model_providers(); } +void +ydk::path::Repository::set_server_capabilities(std::vector & serv_caps) { + m_priv_repo->server_caps = serv_caps; +} //////////////////////////////////////////////////////////////////////// diff --git a/sdk/cpp/core/src/path_api.hpp b/sdk/cpp/core/src/path_api.hpp index fe51ff325..0953c38d5 100644 --- a/sdk/cpp/core/src/path_api.hpp +++ b/sdk/cpp/core/src/path_api.hpp @@ -969,6 +969,7 @@ class Repository { /// std::vector get_model_providers() const; + void set_server_capabilities(std::vector & serv_caps); std::string path; private: diff --git a/sdk/python/core/tests/test_sanity_path.py b/sdk/python/core/tests/test_sanity_path.py index 6ecf86d7d..0e623906c 100644 --- a/sdk/python/core/tests/test_sanity_path.py +++ b/sdk/python/core/tests/test_sanity_path.py @@ -128,22 +128,11 @@ def test_get_schema(self): xml = self.codec.encode(res, EncodingFormat.XML, False) self.assertNotEqual( len(xml), 0 ) - - def enable_logging(self): - import logging - log = logging.getLogger('ydk') - log.setLevel(logging.DEBUG) - handler = logging.StreamHandler() - formatter = logging.Formatter(("%(asctime)s - %(name)s - %(levelname)s - %(message)s")) - handler.setFormatter(formatter) - log.addHandler(handler) - def test_create_gre_tunnel_on_demand(self): - #self.enable_logging() + #enable_logging() from ydk.models.ydktest import ydktest_sanity as ysanity from ydk.providers import NetconfServiceProvider - from ydk.services import NetconfService, Datastore from ydk.services import CRUDService provider = NetconfServiceProvider( @@ -153,7 +142,7 @@ def test_create_gre_tunnel_on_demand(self): 12022) native = ysanity.Native() - + tunnel = native.interface.Tunnel() tunnel.name = 521 tunnel.description = "test tunnel" @@ -169,6 +158,15 @@ def test_create_gre_tunnel_on_demand(self): crud_service = CRUDService(); crud_service.create(provider, native) +def enable_logging(): + import logging + log = logging.getLogger('ydk') + log.setLevel(logging.DEBUG) + handler = logging.StreamHandler() + formatter = logging.Formatter(("%(asctime)s - %(name)s - %(levelname)s - %(message)s")) + handler.setFormatter(formatter) + log.addHandler(handler) + if __name__ == '__main__': device, non_demand, common_cache, timeout = get_device_info() From d5c2fe9c6bbf59e5edb61a21cd5e06d0ca3bd8d4 Mon Sep 17 00:00:00 2001 From: Yan Gorelik Date: Tue, 20 Feb 2018 17:25:00 -0800 Subject: [PATCH 4/6] Added C++ sanity test for issue 627 --- sdk/cpp/core/src/path/repository.cpp | 8 +-- .../ydktest-sanity-submodule@2015-11-17.yang | 54 ++++++++++++++++++- .../ydktest-sanity-submodule@2016-04-25.yang | 54 ++++++++++++++++++- sdk/cpp/tests/test_core_netconf.cpp | 40 ++++++++++++-- .../ydktest-sanity-submodule@2016-04-25.yang | 52 ++++++++++++++++++ 5 files changed, 200 insertions(+), 8 deletions(-) diff --git a/sdk/cpp/core/src/path/repository.cpp b/sdk/cpp/core/src/path/repository.cpp index b460dd045..123154043 100644 --- a/sdk/cpp/core/src/path/repository.cpp +++ b/sdk/cpp/core/src/path/repository.cpp @@ -469,7 +469,7 @@ const lys_module* ydk::path::RepositoryPtr::load_module(ly_ctx* ctx, const std::string& module, const std::string& revision, const std::vector& features, bool& new_module) { - YLOG_DEBUG("Module '{}' Revision '{}'", module.c_str(), revision.c_str()); + YLOG_DEBUG("Loading Module '{}' Revision '{}'", module.c_str(), revision.c_str()); auto p = ly_ctx_get_module(ctx, module.c_str(), revision.empty() ? NULL : revision.c_str(), 1); @@ -485,9 +485,10 @@ ydk::path::RepositoryPtr::load_module(ly_ctx* ctx, const std::string& module, co YLOG_WARN("Unable to parse module: '{}'. This model cannot be used with YDK", module); } - for (auto f : features) + for (auto f : features) { + YLOG_DEBUG("Adding feature '{}'", f.c_str()); lys_features_enable(p, f.c_str()); - + } return p; } @@ -500,6 +501,7 @@ ydk::path::RepositoryPtr::get_module_capabilities(ydk::path::Capability & mod_ca { mod_cap.features = cap.features; mod_cap.deviations = cap.deviations; + break; } } } diff --git a/sdk/cpp/core/tests/models/ydktest-sanity-submodule@2015-11-17.yang b/sdk/cpp/core/tests/models/ydktest-sanity-submodule@2015-11-17.yang index d955d180f..56c4db5b2 100644 --- a/sdk/cpp/core/tests/models/ydktest-sanity-submodule@2015-11-17.yang +++ b/sdk/cpp/core/tests/models/ydktest-sanity-submodule@2015-11-17.yang @@ -1,5 +1,5 @@ submodule ydktest-sanity-submodule { - belongs-to ydktest-sanity { + belongs-to ydktest-sanity { prefix ydkut; } @@ -11,6 +11,9 @@ submodule ydktest-sanity-submodule { //import Cisco-IOS-XR-types { prefix "xr"; } + import ietf-yang-types { + prefix yang; + } organization "Cisco Systems, Inc."; @@ -41,6 +44,21 @@ submodule ydktest-sanity-submodule { "Initial revision."; } + // Features + feature ipv4-non-contiguous-netmasks { + description + "Indicates support for configuring non-contiguous + subnet masks."; + } + feature ipv6-privacy-autoconf { + description + "Indicates support for Privacy Extensions for Stateless Address + Autoconfiguration in IPv6."; + reference + "RFC 4941: Privacy Extensions for Stateless Address + Autoconfiguration in IPv6"; + } + grouping one-sub-level { description "testing for couple of leaves"; container one-aug { @@ -79,6 +97,40 @@ submodule ydktest-sanity-submodule { range "64..18000"; } } + + // interface * / ipv4 + container ipv4 { + list address { + key "ip"; + description + "The list of configured IPv4 addresses on the interface."; + leaf ip { + type yang:dotted-quad; + description + "The IPv4 address on the interface."; + } + choice subnet { + mandatory true; + description + "The subnet can be specified as a prefix-length, or, + if the server supports non-contiguous netmasks, as + a netmask."; + leaf prefix-length { + type uint8 { + range "0..32"; + } + description + "The length of the subnet prefix."; + } + leaf netmask { + if-feature ipv4-non-contiguous-netmasks; + type yang:dotted-quad; + description + "The subnet specified as a netmask."; + } + } + } + } } grouping config-interface-grouping { diff --git a/sdk/cpp/core/tests/models/ydktest-sanity-submodule@2016-04-25.yang b/sdk/cpp/core/tests/models/ydktest-sanity-submodule@2016-04-25.yang index d955d180f..56c4db5b2 100644 --- a/sdk/cpp/core/tests/models/ydktest-sanity-submodule@2016-04-25.yang +++ b/sdk/cpp/core/tests/models/ydktest-sanity-submodule@2016-04-25.yang @@ -1,5 +1,5 @@ submodule ydktest-sanity-submodule { - belongs-to ydktest-sanity { + belongs-to ydktest-sanity { prefix ydkut; } @@ -11,6 +11,9 @@ submodule ydktest-sanity-submodule { //import Cisco-IOS-XR-types { prefix "xr"; } + import ietf-yang-types { + prefix yang; + } organization "Cisco Systems, Inc."; @@ -41,6 +44,21 @@ submodule ydktest-sanity-submodule { "Initial revision."; } + // Features + feature ipv4-non-contiguous-netmasks { + description + "Indicates support for configuring non-contiguous + subnet masks."; + } + feature ipv6-privacy-autoconf { + description + "Indicates support for Privacy Extensions for Stateless Address + Autoconfiguration in IPv6."; + reference + "RFC 4941: Privacy Extensions for Stateless Address + Autoconfiguration in IPv6"; + } + grouping one-sub-level { description "testing for couple of leaves"; container one-aug { @@ -79,6 +97,40 @@ submodule ydktest-sanity-submodule { range "64..18000"; } } + + // interface * / ipv4 + container ipv4 { + list address { + key "ip"; + description + "The list of configured IPv4 addresses on the interface."; + leaf ip { + type yang:dotted-quad; + description + "The IPv4 address on the interface."; + } + choice subnet { + mandatory true; + description + "The subnet can be specified as a prefix-length, or, + if the server supports non-contiguous netmasks, as + a netmask."; + leaf prefix-length { + type uint8 { + range "0..32"; + } + description + "The length of the subnet prefix."; + } + leaf netmask { + if-feature ipv4-non-contiguous-netmasks; + type yang:dotted-quad; + description + "The subnet specified as a netmask."; + } + } + } + } } grouping config-interface-grouping { diff --git a/sdk/cpp/tests/test_core_netconf.cpp b/sdk/cpp/tests/test_core_netconf.cpp index 46a8f8c73..091b2ea58 100644 --- a/sdk/cpp/tests/test_core_netconf.cpp +++ b/sdk/cpp/tests/test_core_netconf.cpp @@ -27,6 +27,11 @@ #include "path_api.hpp" #include "config.hpp" #include "catch.hpp" +#include "entity_data_node_walker.hpp" + +#include "ydk/crud_service.hpp" +#include "ydk/netconf_provider.hpp" +#include "ydk_ydktest/ydktest_sanity.hpp" const char* expected_bgp_output ="\ \ @@ -67,6 +72,24 @@ const char* expected_bgp_output ="\ const char* expected_bgp_read ="65172falsefalse11falsefalsetruefalsefalsefalseoc-bgp-types:L3VPN_IPV4_UNICASToc-bgp-types:L3VPN_IPV4_UNICASTtruefalsefalsefalsefalsetruefalsefalsefalsefalsefalse11REJECT_ROUTEREJECT_ROUTEREJECT_ROUTEREJECT_ROUTE172.16.255.2172.16.255.265172truefalseNONE30.090.030.030.0falsefalsefalsetruefalsefalse0falsefalsefalsefalseREJECT_ROUTEREJECT_ROUTEoc-bgp-types:L3VPN_IPV4_UNICASToc-bgp-types:L3VPN_IPV4_UNICASTtruefalsefalseREJECT_ROUTEREJECT_ROUTEfalsefalse"; +std::string xml_payload_ip = +R"( + + + + 2449 + Interface Loopback2449 + +
+ 10.10.10.10 + 255.255.255.255 +
+
+
+
+
+)"; + void print_tree(ydk::path::DataNode* dn, const std::string& indent) { ydk::path::Statement s = dn->get_schema_node().get_statement(); @@ -78,13 +101,24 @@ void print_tree(ydk::path::DataNode* dn, const std::string& indent) child_indent+=" "; std::cout << indent << "<" << s.arg << ">" << std::endl; for(auto c : dn->get_children()) - print_tree(c.get(), child_indent); + print_tree(c.get(), child_indent); std::cout << indent << "" << std::endl; - } } +TEST_CASE( "decode_encode_interfaces" ) +{ + ydk::path::NetconfSession session{"127.0.0.1", "admin", "admin", 12022}; + ydk::path::RootSchemaNode& root = session.get_root_schema(); + ydk::path::Codec s{}; + + auto data_node = s.decode(root, xml_payload_ip, ydk::EncodingFormat::XML); + REQUIRE(data_node != nullptr); + + auto xml = s.encode( *data_node, ydk::EncodingFormat::XML, true); + std::cout<get_input_node().create_datanode("entity", xml); (*create_rpc)(session); } -*/ \ No newline at end of file +*/ diff --git a/yang/ydktest/ydktest-sanity-submodule@2016-04-25.yang b/yang/ydktest/ydktest-sanity-submodule@2016-04-25.yang index d955d180f..85bc21b1f 100644 --- a/yang/ydktest/ydktest-sanity-submodule@2016-04-25.yang +++ b/yang/ydktest/ydktest-sanity-submodule@2016-04-25.yang @@ -11,6 +11,9 @@ submodule ydktest-sanity-submodule { //import Cisco-IOS-XR-types { prefix "xr"; } + import ietf-yang-types { + prefix yang; + } organization "Cisco Systems, Inc."; @@ -41,6 +44,21 @@ submodule ydktest-sanity-submodule { "Initial revision."; } + // Features + feature ipv4-non-contiguous-netmasks { + description + "Indicates support for configuring non-contiguous + subnet masks."; + } + feature ipv6-privacy-autoconf { + description + "Indicates support for Privacy Extensions for Stateless Address + Autoconfiguration in IPv6."; + reference + "RFC 4941: Privacy Extensions for Stateless Address + Autoconfiguration in IPv6"; + } + grouping one-sub-level { description "testing for couple of leaves"; container one-aug { @@ -79,6 +97,40 @@ submodule ydktest-sanity-submodule { range "64..18000"; } } + + // interface * / ipv4 + container ipv4 { + list address { + key "ip"; + description + "The list of configured IPv4 addresses on the interface."; + leaf ip { + type yang:dotted-quad; + description + "The IPv4 address on the interface."; + } + choice subnet { + mandatory true; + description + "The subnet can be specified as a prefix-length, or, + if the server supports non-contiguous netmasks, as + a netmask."; + leaf prefix-length { + type uint8 { + range "0..32"; + } + description + "The length of the subnet prefix."; + } + leaf netmask { + if-feature ipv4-non-contiguous-netmasks; + type yang:dotted-quad; + description + "The subnet specified as a netmask."; + } + } + } + } } grouping config-interface-grouping { From eba403e9bb78774c78a60466e5c770b026908499 Mon Sep 17 00:00:00 2001 From: Yan Gorelik Date: Wed, 21 Feb 2018 09:35:40 -0800 Subject: [PATCH 5/6] Added Python test for Issue 627 --- sdk/python/core/tests/test_sanity_netconf.py | 45 ++++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/sdk/python/core/tests/test_sanity_netconf.py b/sdk/python/core/tests/test_sanity_netconf.py index 6e3a83fd5..80ba674f8 100644 --- a/sdk/python/core/tests/test_sanity_netconf.py +++ b/sdk/python/core/tests/test_sanity_netconf.py @@ -14,18 +14,23 @@ # limitations under the License. # ------------------------------------------------------------------ -"""test_sanity_rpc.py -sanity test for netconf +"""test_sanity_netconf.py +sanity tests for netconf """ from __future__ import absolute_import import sys import unittest +import logging from ydk.errors import YPYModelError, YPYError, YPYServiceError from ydk.models.ydktest import ydktest_sanity as ysanity from ydk.providers import NetconfServiceProvider -from ydk.services import NetconfService, Datastore +from ydk.services import NetconfService, Datastore +from ydk.services import CRUDService +from ydk.services import CodecService +from ydk.providers import CodecServiceProvider +from ydk.ext.types import EncodingFormat from test_utils import ParametrizedTestCase from test_utils import get_device_info @@ -225,6 +230,40 @@ def test_unlock_fail(self): self.ncc, "invalid-input") + def test_sanity_crud_read_interface(self): + enable_logging(logging.ERROR) + + address = ysanity.Native.Interface.Loopback.Ipv4.Address(); + address.ip = "2.2.2.2" + address.netmask = "255.255.255.255" + + loopback = ysanity.Native.Interface.Loopback() + loopback.name = 2222 + loopback.ipv4.address.append(address) + + native = ysanity.Native() + native.interface.loopback.append(loopback) + + crud = CRUDService() + result = crud.create(self.ncc, native) + + native_read = ysanity.Native() + interfaces = crud.read(self.ncc, native_read) + + codec_service = CodecService() + codec_provider = CodecServiceProvider() + codec_provider.encoding = EncodingFormat.XML + xml_encode = codec_service.encode(codec_provider, interfaces) + # print(xml_encode) + # enable_logging(logging.ERROR) + +def enable_logging(level): + log = logging.getLogger('ydk') + log.setLevel(level) + handler = logging.StreamHandler() + formatter = logging.Formatter(("%(asctime)s - %(name)s - %(levelname)s - %(message)s")) + handler.setFormatter(formatter) + log.addHandler(handler) if __name__ == '__main__': device, non_demand, common_cache, timeout = get_device_info() From 6d0b83c8ff80cdc81f24d93c252b797203449a22 Mon Sep 17 00:00:00 2001 From: Yan Gorelik Date: Wed, 21 Feb 2018 12:34:00 -0800 Subject: [PATCH 6/6] Fixed issue 682 --- .gitignore | 2 ++ .../core/docsgen/api/path/netconf_session.rst | 8 ++++---- .../docsgen/api/services/netconf_service.rst | 6 +++--- .../core/ydk/path/sessions/netconf_session.py | 2 +- .../core/ydk/services/netconf_service.py | 20 +++++++++++++++---- 5 files changed, 26 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index d0609c06b..33437fe0d 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,5 @@ gen-api/ *.sublime-workspace *.idea scripts +sdk/cpp/core/tests/confd/ydktest/cli-history +sdk/python/core/ydk/models/ydktest diff --git a/sdk/python/core/docsgen/api/path/netconf_session.rst b/sdk/python/core/docsgen/api/path/netconf_session.rst index 9a3387a74..8dcea941b 100644 --- a/sdk/python/core/docsgen/api/path/netconf_session.rst +++ b/sdk/python/core/docsgen/api/path/netconf_session.rst @@ -5,7 +5,7 @@ NetconfSession :synopsis: NetconfSession -.. py:class:: NetconfSession(address, usename, password, port=830, on_demand=True, common_cache=False, int timeout=-1, repo=None, private_key_path="", public_key_path="") +.. py:class:: NetconfSession(address, usename, password, port=830, on_demand=True, common_cache=False, int timeout=None, repo=None, private_key_path="", public_key_path="") :param address: (``str``) IP address of the device supporting a netconf interface. :param username: (``str``) Username to log in to the device. @@ -13,10 +13,10 @@ NetconfSession :param port: (``int``) Device port used to access the netconf interface. Default value is 830. :param on_demand: (``bool``) On demand model downloading by default. :param common_cache: (``bool``) Use common cache directory if enabled. - :param timeout: (``int``) The timeout in microseconds, -1 for infinite timeout, 0 for non-blocking + :param timeout: (``int``) The timeout in microseconds: None or -1 for infinite timeout, 0 - for non-blocking :param repo: (:py:class:`Repository`) User customized repository. - :param private_key_path: (``str``) Path to private key file. Requires public_key_path field. Doesn't allow password field. - :param public_key_path: (``str``) Path to public key file. Requires private_key_path field. Doesn't allow password field. + :param private_key_path: (``str``) Path to private key file. Requires public_key_path field. Does not allow password field. + :param public_key_path: (``str``) Path to public key file. Requires private_key_path field. Does not allow password field. .. py:method:: get_root_schema() diff --git a/sdk/python/core/docsgen/api/services/netconf_service.rst b/sdk/python/core/docsgen/api/services/netconf_service.rst index 17019b317..0e50d5d72 100644 --- a/sdk/python/core/docsgen/api/services/netconf_service.rst +++ b/sdk/python/core/docsgen/api/services/netconf_service.rst @@ -3,9 +3,9 @@ NETCONF service .. py:class:: ydk.services.NetconfService - .. py:method:: cancel_commit(provider, persist_id=-1) + .. py:method:: cancel_commit(provider, persist_id=None) - Cancels an ongoing confirmed commit. If the ``persist_id`` parameter is not given, the operation **MUST** be issued on the same session that issued the confirmed commit. + Cancels an ongoing confirmed commit. If the ``persist_id`` parameter is None, the operation **MUST** be issued on the same session that issued the confirmed commit. :param provider: (:py:class:`NetconfServiceProvider`) NETCONF provider instance. :param persist_id: (``int``) An ``int`` that cancels a persistent confirmed commit. @@ -20,7 +20,7 @@ NETCONF service :return: ``True`` if the operation succeeds, else ``False`` :raises: :py:exc:`YPYError` If error has occurred - .. py:method:: commit(provider, confirmed=False, confirm_timeout=-1, persist=-1, persist_id=-1) + .. py:method:: commit(provider, confirmed=False, confirm_timeout=None, persist=None, persist_id=None) Instructs the device to implement the configuration data contained in the candidate configuration. diff --git a/sdk/python/core/ydk/path/sessions/netconf_session.py b/sdk/python/core/ydk/path/sessions/netconf_session.py index 7b480a041..01ec0e54d 100644 --- a/sdk/python/core/ydk/path/sessions/netconf_session.py +++ b/sdk/python/core/ydk/path/sessions/netconf_session.py @@ -26,7 +26,7 @@ class NetconfSession(_NetconfSession): """ def __init__(self, address, username, password, port=830, protocol="ssh", - on_demand=True, common_cache=False, timeout=-1, repo=None): + on_demand=True, common_cache=False, timeout=None, repo=None): if repo is None: super(NetconfSession, self).__init__(address, username, password, port, protocol, on_demand, diff --git a/sdk/python/core/ydk/services/netconf_service.py b/sdk/python/core/ydk/services/netconf_service.py index edb6bb8c1..10221e615 100644 --- a/sdk/python/core/ydk/services/netconf_service.py +++ b/sdk/python/core/ydk/services/netconf_service.py @@ -23,9 +23,12 @@ class NetconfService(_NetconfService): def __init__(self): self._ns = _NetconfService() - def cancel_commit(self, provider, persist_id=-1): - if None in (provider, persist_id): - raise _YPYServiceError("provider and persist_id cannot be None") + def cancel_commit(self, provider, persist_id=None): + if provider is None: + raise _YPYServiceError("provider cannot be None") + + if persist_id is None: + persist_id = -1 with _handle_error(): return self._ns.cancel_commit(provider, persist_id) @@ -37,10 +40,19 @@ def close_session(self, provider): with _handle_error(): return self._ns.close_session(provider) - def commit(self, provider, confirmed=False, confirm_timeout=-1, persist=-1, persist_id=-1): + def commit(self, provider, confirmed=False, confirm_timeout=None, persist=None, persist_id=None): if provider is None: raise _YPYServiceError("provider cannot be None") + if confirm_timeout is None: + confirm_timeout = -1 + + if persist is None: + persist = -1 + + if persist_id is None: + persist_id = -1 + with _handle_error(): return self._ns.commit(provider, confirmed, confirm_timeout, persist, persist_id)