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

CodecService fails correctly encode multiple entries in keyless list #854

Closed
ygorelik opened this issue Jan 14, 2019 · 2 comments
Closed

Comments

@ygorelik
Copy link
Collaborator

Expected Behavior

The CodecService must correctly encode keyless list with multiple entries.

Current Behavior

The CodecService fails encode keyless list of leafs when the list contains multiple entries. The encoded string (JSON or XML) contains only one list entry.

Your Script

from argparse import ArgumentParser

from ydk.filters import YFilter  
from ydk.providers import NetconfServiceProvider, CodecServiceProvider
from ydk.services import CodecService

from ydk.models.cisco_ios_xr import Cisco_IOS_XR_mpls_vpn_oper

class l3vpn_ydk_oper_object():
    def __init__(self):
        self.l3vpn = Cisco_IOS_XR_mpls_vpn_oper.L3vpn()
        self.vrfs = Cisco_IOS_XR_mpls_vpn_oper.L3vpn.Vrfs()

    def l3vpn_fun(self, vrf_name, RD, interfaces):
        vrf = Cisco_IOS_XR_mpls_vpn_oper.L3vpn.Vrfs.Vrf()
        vrf.vrf_name = vrf_name

        af = Cisco_IOS_XR_mpls_vpn_oper.L3vpn.Vrfs.Vrf.Af()
        af.af_name = Cisco_IOS_XR_mpls_vpn_oper.MplsVpnAfi.ipv4 #MplsVpnAfiEnum.ipv4
        af.export_route_policy = 'y'
        af.import_route_policy = 'x'
        af.saf_name = Cisco_IOS_XR_mpls_vpn_oper.MplsVpnSafi.unicast #MplsVpnSafiEnum.unicast
        vrf.af.append(af)

        interface1 = Cisco_IOS_XR_mpls_vpn_oper.L3vpn.Vrfs.Vrf.Interface()
        interface1.interface_name = interfaces[0]
        interface2 = Cisco_IOS_XR_mpls_vpn_oper.L3vpn.Vrfs.Vrf.Interface()
        interface2.interface_name = interfaces[1]
        vrf.interface.extend([interface2, interface1])

        vrf.route_distinguisher = RD
        vrf.vrf_name_xr = vrf_name
        self.vrfs.vrf.append(vrf)

    def return_l3vpn(self):
        self.l3vpn.vrfs = self.vrfs
        return self.l3vpn

if __name__ == "__main__":
    """Execute main program."""
    parser = ArgumentParser()
    parser.add_argument("-v", "--verbose", help="print debugging messages",
                        action="store_true")
    args = parser.parse_args()

    # log debug messages if verbose argument specified
    if args.verbose:
        logger = logging.getLogger("ydk")
        logger.setLevel(logging.INFO)
        handler = logging.StreamHandler()
        formatter = logging.Formatter(("%(asctime)s - %(name)s - "
                                      "%(levelname)s - %(message)s"))
        handler.setFormatter(formatter)
        logger.addHandler(handler)

    # create codec provider
    provider = CodecServiceProvider(type="json")

    # create codec service
    codec = CodecService()

    l3vpn_info = l3vpn_ydk_oper_object()  # create object
    l3vpn_list = ['vrf_red',"192.168.111.117:41",['gi1/1','gi1/2']]
    l3vpn_info.l3vpn_fun(l3vpn_list[0],l3vpn_list[1],l3vpn_list[2])

    # encode and print object
    print(codec.encode(provider, l3vpn_info.return_l3vpn()))

Logs

{
  "Cisco-IOS-XR-mpls-vpn-oper:l3vpn": {
    "vrfs": {
      "vrf": [
        {
          "vrf-name": "vrf_red",
          "vrf-name-xr": "vrf_red",
          "route-distinguisher": "192.168.111.117:41",
          "interface": [
            {
              "interface-name": "gi1/2"
            }
          ],
          "af": [
            {
              "af-name": "ipv4",
              "saf-name": "unicast",
              "import-route-policy": "x",
              "export-route-policy": "y"
            }
          ]
        }
      ]
    }
  }
}

Note: The list 'interface' contains only one entry. Expected two entries.

System Information

YDK-0.8.0

@magedelmalah
Copy link

@ygorelik Could you please help by providing code fix on a branch?

@ygorelik
Copy link
Collaborator Author

Resolved to YDK-0.8.1.

Run Results:

{
  "Cisco-IOS-XR-mpls-vpn-oper:l3vpn": {
    "vrfs": {
      "vrf": [
        {
          "vrf-name": "vrf_red",
          "vrf-name-xr": "vrf_red",
          "route-distinguisher": "192.168.111.117:41",
          "interface": [
            {
              "interface-name": "gi1/2"
            },
            {
              "interface-name": "gi1/1"
            }
          ],
          "af": [
            {
              "af-name": "ipv4",
              "saf-name": "unicast",
              "import-route-policy": "x",
              "export-route-policy": "y"
            }
          ]
        }
      ]
    }
  }
}

ygorelik pushed a commit to ygorelik/ydk-gen that referenced this issue Jan 16, 2019
ygorelik pushed a commit to ygorelik/ydk-gen that referenced this issue Jan 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants