CiscoDevNet / ydk-gen

Generate model-driven APIs from YANG models
http://ciscodevnet.github.io/ydk-gen/
Apache License 2.0
136 stars 74 forks source link

YDK0.8.5 vrf route-target leaf stitching(bool) fails as invalid #1059

Closed hahamedp closed 2 years ago

hahamedp commented 2 years ago

Issue tracker is ONLY used for reporting bugs. Please use the YDK Community for any support issues.

In YDK0.8.5 - configuring vrf route-target stitching leaf (sending value as boolean) is considered as invalid value due to its converting this to string in infra setting as leaf

*** ydk.errors.YModelError: Invalid value "False" in "stitching" element. Path: /Cisco-IOS-XR-um-vrf-cfg:vrfs/vrf[vrf-name='vrf_l3vpn']/address-family/ipv4/unicast/Cisco-IOS-XR-um-router-bgp-cfg:import/route-target/four-byte-as-rts/four-byte-as-rt[as-number='65600'][index='100'][stitching='False']/stitching

(Pdb) rote_target.stitching *** NameError: name 'rote_target' is not defined (Pdb) route_target.stitching False (Pdb) type(route_target.stitching). >>>>set as boolean <class 'bool'> (Pdb) ascfg.import.route_target.four_byte_as_rts.four_byte_as_rt.append(route_target) (Pdb) vrf_cfg.address_family.ipv4.unicast = as_cfg

https://community.cisco.com/t5/yang-tools/ydk0-8-5-vrf-route-target-leaf-stitching-bool-fails-as-invalid/m-p/4569021#M2250

Expected Behavior

stitching value to be used as Boolean

Current Behavior

its converting to string

Steps to Reproduce

Your Script

route_target = ascfg.import.route_target.four_byte_as_rts.FourByteAsRt() as_or_addr = as_or_addr_nn.split(':') route_target.as_number = int(as_or_addr[0]) route_target.index = int(as_or_addr[1]) route_target.stitching = False ascfg.import.route_target.four_byte_as_rts.four_byte_as_rt.append(route_target)

Logs

Enable logging and post the logs below

System Information

ygorelik commented 2 years ago

Resolved to release 0.8.6.2 (see above notes). Test YANG model was included to the unit test suite:

module ydktest-sanity {
  namespace "http://cisco.com/ns/yang/ydktest-sanity";
  prefix "ydkut";

  container runner {
...
        leaf-list bool-leaf-list {
          type boolean;
        }

        list bool-list {
          key "bool-leaf";
          leaf bool-leaf {
            type boolean;
          }
        }
      }
...
  }
}

Unit test:

import logging
from test_utils import enable_logging
from ydk.providers import CodecServiceProvider
from ydk.services  import CodecService
from ydk.models.ydktest import ydktest_sanity as ysanity

class SanityTest(unittest.TestCase):

    def setUp(self):
        self.codec_service = CodecService()
        self.codec_provider = CodecServiceProvider(type='xml')
        enable_logging(logging.DEBUG)

    def test_bool_lists(self):
        r = ysanity.Runner()
        r.ytypes.built_in_t.bool_leaf_list.append(True)
        r.ytypes.built_in_t.bool_leaf_list.append(False)

        bool_list_elem = ysanity.Runner.Ytypes.BuiltInT.BoolList()
        bool_list_elem.bool_leaf = True
        r.ytypes.built_in_t.bool_list.append(bool_list_elem)

        xml = self.codec_service.encode(self.codec_provider, r)
        expected = '''<runner xmlns="http://cisco.com/ns/yang/ydktest-sanity">
  <ytypes>
    <built-in-t>
      <bool-leaf-list>true</bool-leaf-list>
      <bool-leaf-list>false</bool-leaf-list>
      <bool-list>
        <bool-leaf>true</bool-leaf>
      </bool-list>
    </built-in-t>
  </ytypes>
</runner>
'''
        self.assertEqual(expected, xml)

        entity = self.codec_service.decode(self.codec_provider, xml)
        self.assertEqual(entity, r)

if __name__ == '__main__':
    suite = unittest.TestSuite()
    testloader = unittest.TestLoader()
    testnames = testloader.getTestCaseNames(SanityTest)
    for name in testnames:
        suite.addTest(SanityTest(name))
    ret = not unittest.TextTestRunner(verbosity=2).run(suite).wasSuccessful()