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

Golang merge #747

Merged
3 commits merged into from
Apr 10, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
48 changes: 48 additions & 0 deletions sdk/cpp/tests/test_sanity_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,3 +655,51 @@ TEST_CASE("string_leaflist")
ydktest_sanity::Runner * r_2 = dynamic_cast<ydktest_sanity::Runner*>(r_read.get());
REQUIRE(r_1->ytypes->built_in_t->enum_llist == r_2->ytypes->built_in_t->enum_llist);
}

TEST_CASE("test_cascading_types")
{
ydk::path::Repository repo{TEST_HOME};
NetconfServiceProvider provider{repo, "127.0.0.1", "admin", "admin", 12022};
CrudService crud{};

// DELETE
auto ctypes = make_unique<ydktest_sanity::CascadingTypes>();
bool reply = crud.delete_(provider, *ctypes);
REQUIRE(reply);

// CREATE
SECTION ( "unknown" )
{
ctypes->comp_insttype = ydktest_sanity::CompInsttype::unknown;
ctypes->comp_nicinsttype = ydktest_sanity::CompInsttype_::unknown;
}

SECTION ( "phys" )
{
ctypes->comp_insttype = ydktest_sanity::CompInsttype::phys;
ctypes->comp_nicinsttype = ydktest_sanity::CompInsttype_::phys;
}

SECTION ( "virt" )
{
ctypes->comp_insttype = ydktest_sanity::CompInsttype::virt;
ctypes->comp_nicinsttype = ydktest_sanity::CompInsttype_::virt;
}

SECTION ( "hv" )
{
ctypes->comp_insttype = ydktest_sanity::CompInsttype::hv;
ctypes->comp_nicinsttype = ydktest_sanity::CompInsttype_::hv;
}
reply = crud.create(provider, *ctypes);
REQUIRE(reply);

// READ
auto filter = make_unique<ydktest_sanity::CascadingTypes>();
auto temp = crud.read(provider, *filter);
REQUIRE(temp!=nullptr);
ydktest_sanity::CascadingTypes * ctypesRead = dynamic_cast<ydktest_sanity::CascadingTypes*>(temp.get());
std::cout<<ctypes->comp_insttype<<std::endl;
std::cout<<ctypesRead->comp_nicinsttype<<std::endl;
REQUIRE(ctypes->comp_insttype == ctypesRead->comp_nicinsttype);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* ------------------------------------------------------------------
* YANG Development Kit
* Copyright 2017 Cisco Systems. All rights reserved
*
*----------------------------------------------
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http:www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*----------------------------------------------
*/
package main

import (
"flag"
"fmt"
"strconv"
"strings"
nativeModel "github.com/CiscoDevNet/ydk-go/ydk/models/cisco_ios_xe/native"
"github.com/CiscoDevNet/ydk-go/ydk/providers"
"github.com/CiscoDevNet/ydk-go/ydk/services"
"github.com/CiscoDevNet/ydk-go/ydk"
)

// configNative adds data to native object
func configNative(native *nativeModel.Native) {
native.Interface_.Loopback = make([]nativeModel.Native_Interface_Loopback, 1)
loopback := &native.Interface_.Loopback[0]
loopback.Name = 0
loopback.Description = "PRIMARY ROUTER LOOPBACK"
loopback.Ip.Address.Primary.Address = "172.16.255.1"
loopback.Ip.Address.Primary.Mask = "255.255.255.255"
}

// main execute main program.
func main() {
defer func() {
if r := recover(); r != nil {
fmt.Println("\nError occured!!\n ", r)
}
}()

// args
vPtr := flag.Bool("v", false, "Enable verbose")
devicePtr := flag.String(
"device",
"",
"NETCONF device (ssh://user:password@host:port)")
flag.Parse()

// log debug messages if verbose argument specified
if *vPtr {
ydk.EnableLogging(ydk.Info)
}

if (*devicePtr == "") {
panic("Missing device arg see --help for details")
}

ydk.YLogDebug(*devicePtr)

denominators := []string{"://", ":", "@", ":"}
keys := []string {"protocol", "username", "password", "address", "port"}
device := make(map[string]string)

var split []string
unprocessed := *devicePtr
for i := 0; i < 4; i++ {
if (!strings.Contains(unprocessed, denominators[i])) {
panic(fmt.Sprintln("Device arg: device must be entered in",
"ssh://user:password@host:port format"))
}
split = strings.SplitN(unprocessed, denominators[i], 2)

device[keys[i]] = split[0]
unprocessed = split[1]
}
device[keys[4]] = unprocessed

port, err := strconv.Atoi(device["port"])
if (err != nil) {
panic("Device arg: port must be an int")
}

// create NETCONF provider
provider := providers.NetconfServiceProvider{
Address: device["address"],
Username: device["username"],
Password: device["password"],
Port: port,
Protocol: device["protocol"]}
provider.Connect()

// create CRUD service
service := services.CrudService{}

// read data from NETCONF device
native := nativeModel.Native{} // create object
configNative(&native) // add object configuration

// create configuration on NETCONF device
service.Create(&provider, &native)
}
15 changes: 11 additions & 4 deletions sdk/go/core/tests/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,20 @@ func (suite *SanityTypesTestSuite) TestIdentityFromOtherModule() {
}

func (suite *SanityTypesTestSuite) TestCascadingTypes() {
cascadingTypesHelper(suite, ysanity.CompInsttype_unknown, ysanity.CompInsttype__unknown)
cascadingTypesHelper(suite, ysanity.CompInsttype_phys, ysanity.CompInsttype__phys)
cascadingTypesHelper(suite, ysanity.CompInsttype_virt, ysanity.CompInsttype__virt)
cascadingTypesHelper(suite, ysanity.CompInsttype_hv, ysanity.CompInsttype__hv)
}

func cascadingTypesHelper(suite *SanityTypesTestSuite, enum1 ysanity.CompInsttype, enum2 ysanity.CompInsttype_){
ctypes := ysanity.CascadingTypes{}
ctypes.CompInsttype = ysanity.CompInsttype_unknown
ctypes.CompNicinsttype = ysanity.CompInsttype__unknown
ctypes.CompInsttype = enum1
ctypes.CompNicinsttype = enum2
suite.CRUD.Create(&suite.Provider, &ctypes)

entityRead := suite.CRUD.Read(&suite.Provider, &ysanity.Runner{})
suite.Equal(types.EntityEqual(entityRead, &ctypes), true)
ctypesRead := suite.CRUD.Read(&suite.Provider, &ysanity.Runner{})
suite.Equal(types.EntityEqual(ctypesRead, &ctypes), true)
}

func TestSanityTypesTestSuite(t *testing.T) {
Expand Down
29 changes: 26 additions & 3 deletions sdk/python/core/tests/test_sanity_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
from ydk.providers import NetconfServiceProvider
from ydk.services import CRUDService
try:
from ydk.models.ydktest.ydktest_sanity import Runner, SubTest, ChildIdentity, ChildChildIdentity
from ydk.models.ydktest.ydktest_sanity import Runner, CascadingTypes, SubTest, ChildIdentity, ChildChildIdentity
from ydk.models.ydktest.ydktest_sanity_types import YdktestType
except:
from ydk.models.ydktest.ydktest_sanity.runner.runner import Runner
from ydk.models.ydktest.ydktest_sanity.cascading_types.cascading_types import CascadingTypes
from ydk.models.ydktest.ydktest_sanity.sub_test.sub_test import SubTest
from ydk.models.ydktest.ydktest_sanity.ydktest_sanity import ChildIdentity, ChildChildIdentity
from ydk.models.ydktest.ydktest_sanity_types.ydktest_sanity_types import YdktestType
Expand All @@ -36,9 +37,9 @@
from ydk.types import Empty, Decimal64, YLeaf, Bits
from ydk.errors import YPYModelError, YPYServiceProviderError
try:
from ydk.models.ydktest.ydktest_sanity import YdkEnumTest, YdkEnumIntTest
from ydk.models.ydktest.ydktest_sanity import YdkEnumTest, YdkEnumIntTest, CompInsttype, CompInsttype_
except:
from ydk.models.ydktest.ydktest_sanity.ydktest_sanity import YdkEnumTest, YdkEnumIntTest
from ydk.models.ydktest.ydktest_sanity.ydktest_sanity import YdkEnumTest, YdkEnumIntTest, CompInsttype, CompInsttype_

from test_utils import ParametrizedTestCase
from test_utils import get_device_info
Expand Down Expand Up @@ -67,6 +68,9 @@ def tearDown(self):
runner = Runner()
self.crud.delete(self.ncc, runner)

ctypes = CascadingTypes()
self.crud.delete(self.ncc, ctypes)

def _create_runner(self):
# runner = Runner()
# runner.ytypes = runner.Ytypes()
Expand Down Expand Up @@ -494,6 +498,25 @@ def test_boolean_update_read(self):
# def test_binary_invalid(self):
# pass

def test_cascading_types(self):
self._cascading_types_helper(CompInsttype.unknown, CompInsttype_.unknown)
self._cascading_types_helper(CompInsttype.phys, CompInsttype_.phys)
self._cascading_types_helper(CompInsttype.virt, CompInsttype_.virt)
self._cascading_types_helper(CompInsttype.hv, CompInsttype_.hv)

def _cascading_types_helper(self, enum1, enum2):
ctypes = CascadingTypes()
ctypes.comp_insttype = enum1
ctypes.comp_nicinsttype = enum2
self.crud.create(self.ncc, ctypes)

# Read into Runner1
ctypesRead = CascadingTypes()
ctypesRead = self.crud.read(self.ncc, ctypesRead)

# Compare runners
self.assertEqual(ctypes, ctypesRead)

if __name__ == '__main__':
device, non_demand, common_cache, timeout = get_device_info()

Expand Down
14 changes: 13 additions & 1 deletion ydkgen/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,23 @@ def iscppkeyword(word):

def isgokeyword(word):
return word in (
# keywords
'break', 'default', 'func', 'interface', 'select',
'case', 'defer', 'go', 'map', 'struct', 'chan',
'else', 'goto', 'package', 'switch', 'const',
'fallthrough', 'if', 'range', 'type', 'continue',
'for', 'import', 'return', 'var', 'string',)
'for', 'import', 'return', 'var',
# types
'bool', 'byte', 'complex64', 'complex128', 'error', 'float32', 'float64',
'int', 'int8', 'int16', 'int32', 'int64', 'rune', 'string',
'uint', 'uint8', 'uint16', 'uint32', 'uint64', 'uintptr',
# constants
'true', 'false', 'iota',
# zero value
'nil',
# functions
'append', 'cap', 'close', 'complex', 'copy', 'delete', 'imag', 'len',
'make', 'new', 'panic', 'print', 'println', 'real', 'recover',)

def get_sphinx_ref_label(named_element):
return named_element.fqn().replace('.', '_')
Expand Down