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

AttributeError: 'Config' object has no attribute 'logger' #876

Closed
vipaoqun opened this issue Feb 11, 2019 · 1 comment
Closed

AttributeError: 'Config' object has no attribute 'logger' #876

vipaoqun opened this issue Feb 11, 2019 · 1 comment

Comments

@vipaoqun
Copy link

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

Expected Behavior

Scripts with Config/Filter in CRUD read/read_config should works well whether configuration exists or not.

Current Behavior

There may be a bug when using Config/Filter in CRUD read/read_config .

If I have both OSPF and BGP configuration in my netconf server(IOS-XRv 9000), the script works well,

but If I just have OSPF configuration in my netconf server, no BGP configuration, the script will raise a AttributeError.

Steps to Reproduce

Please refer to : https://community.cisco.com/t5/yang-development-kit-ydk/attributeerror-config-object-has-no-attribute-logger/m-p/3788454

Your Script

#!/usr/bin/env python

from argparse import ArgumentParser
from urlparse import urlparse

from ydk.services import CRUDService
from ydk.providers import NetconfServiceProvider
from ydk.services import CodecService
from ydk.providers import CodecServiceProvider
from ydk.types import Filter, Config
import logging
import json


if __name__ == "__main__":
    """Execute main program."""
    parser = ArgumentParser()
    parser.add_argument("-v", "--verbose", help="print debugging messages",
                        action="store_true")
    parser.add_argument("device",
                        help="NETCONF device (ssh://user:password@host:port)")
    args = parser.parse_args()
    device = urlparse(args.device)

    # 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 NETCONF provider
    provider = NetconfServiceProvider(address=device.hostname,
                                      port=device.port,
                                      username=device.username,
                                      password=device.password,
                                      protocol=device.scheme)
    json_provider = CodecServiceProvider(type=str("json"))

    # create CRUD service
    crud = CRUDService()
    codec = CodecService()

    entity = [
        {
            "Cisco-IOS-XR-ipv4-ospf-cfg:ospf": {}
        },
        {
            "Cisco-IOS-XR-ipv4-bgp-cfg:bgp": {}
        }
    ]

    entities = [codec.decode(json_provider, json.dumps(tree)) for tree in entity]

    crud.read(provider, Filter(entities))

Logs

Enable logging and post the logs below


System Information

ygorelik pushed a commit to ygorelik/ydk-gen that referenced this issue Feb 12, 2019
@ygorelik
Copy link
Collaborator

After the fix

yan@ubuntu-yan:~/ydk-workspace/ydk-gen$ python scripts/tests/test_attribute_error.py ssh://admin:admin@10.30.110.84:830 -v
2019-02-12 16:26:58,012 - ydk - INFO - Path where models are to be downloaded: /home/yan/.ydk/10.30.110.84
2019-02-12 16:26:58,033 - ydk - INFO - Connected to 10.30.110.84 on port 830 using ssh with timeout of -1
2019-02-12 16:26:58,358 - ydk - INFO - Executing CRUD read operation on [Cisco-IOS-XR-ipv4-ospf-cfg:ospf, Cisco-IOS-XR-ipv4-bgp-cfg:bgp]
2019-02-12 16:26:58,358 - ydk - INFO - Executing 'get' RPC on [Cisco-IOS-XR-ipv4-ospf-cfg:ospf, Cisco-IOS-XR-ipv4-bgp-cfg:bgp]
2019-02-12 16:26:58,420 - ydk - INFO - ============= Generated RPC to send to device =============
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"><get xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
  <filter><ospf xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ipv4-ospf-cfg"/><bgp xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ipv4-bgp-cfg"/></filter>
</get>
</rpc>

2019-02-12 16:26:58,681 - ydk - INFO - ============= Reply RPC received from device =============
<?xml version="1.0"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1">
  <data/>
</rpc-reply>

2019-02-12 16:26:58,681 - ydk - INFO - Found empty data tag
Entities in Config: []
2019-02-12 16:26:58,682 - ydk - INFO - Disconnected from device
yan@ubuntu-yan:~/ydk-workspace/ydk-gen$ 

In the test both configurations of OSPF and BGP is missing in the device. As a result the Config collection is empty.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants