py-junos-eznc: ignore_warnings causing "'str' object has no attribute '_root'"

Hello team,

We are encountering this issue when loading a configuration with ignore_warning feature enabled:

Traceback (most recent call last):
  File "/opt/salt/venv/lib64/python3.9/site-packages/salt/utils/napalm.py", line 169, in call
    out = getattr(napalm_device.get("DRIVER"), method)(*args, **kwargs)
  File "/opt/salt/venv/lib64/python3.9/site-packages/napalm/junos/junos.py", line 284, in load_merge_candidate
    self._load_candidate(filename, config, False)
  File "/opt/salt/venv/lib64/python3.9/site-packages/napalm/junos/junos.py", line 263, in _load_candidate
    self.device.cu.load(
  File "/opt/salt/venv/lib64/python3.9/site-packages/jnpr/junos/utils/config.py", line 589, in load
    return try_load(rpc_contents, rpc_xattrs, ignore_warning=ignore_warning)
  File "/opt/salt/venv/lib64/python3.9/site-packages/jnpr/junos/utils/config.py", line 500, in try_load
    got = self.rpc.load_config(
  File "/opt/salt/venv/lib64/python3.9/site-packages/jnpr/junos/rpcmeta.py", line 287, in load_config
    return self._junos.execute(rpc, ignore_warning=ignore_warning)
  File "/opt/salt/venv/lib64/python3.9/site-packages/jnpr/junos/decorators.py", line 76, in wrapper
    return function(*args, **kwargs)
  File "/opt/salt/venv/lib64/python3.9/site-packages/jnpr/junos/decorators.py", line 31, in wrapper
    return function(*args, **kwargs)
  File "/opt/salt/venv/lib64/python3.9/site-packages/jnpr/junos/device.py", line 834, in execute
    rpc_rsp_e = self._rpc_reply(
  File "/opt/salt/venv/lib64/python3.9/site-packages/jnpr/junos/decorators.py", line 155, in wrapper
    rsp = NCElement(
  File "/opt/salt/venv/lib64/python3.9/site-packages/ncclient/xml_.py", line 177, in __init__
    self.__doc = self.__transform_reply(result._root)
AttributeError: 'str' object has no attribute '_root'

This is causing an exception resulting, and the commit is discard.

The code in pyeznc is calling NCElement with an argument with the wrong type:

                rsp = NCElement(
                    etree.tostring(rsp, encoding=encode), self.transform()  <<< first arg is a string
                )._NCElement__doc
class NCElement(object):
    def __init__(self, result, transform_reply, huge_tree=False):
        self.__result = result                                   <<< a string
        self.__transform_reply = transform_reply
        self.__huge_tree = huge_tree
        if isinstance(transform_reply, types.FunctionType):
            self.__doc = self.__transform_reply(result._root)    <<< string does not have a _root argument
        else:
            self.__doc = self.remove_namespaces(self.__result)

Bypassing the error with a try except block confirms this is the root cause. I don’t know what can be passed to NCElement instead of a string. I am not familiar with ncclient.

Can you help please?

Tested versions: junos-eznc=2.6.5 and 2.6.7

About this issue

Commits related to this issue

Most upvoted comments

Hi @kpetremann when I try to load the provided config statements , ignore_warning looks to be not working . I am able to replicated the issue with ignore_warning .

Traceback (most recent call last):
  File "/root/pyez_release_268_test1/venv/lib/python3.9/site-packages/junos_eznc-2.6.8+0.g0745dd0e.dirty-py3.9.egg/jnpr/junos/device.py", line 834, in execute
    rpc_rsp_e = self._rpc_reply(
  File "/root/pyez_release_268_test1/venv/lib/python3.9/site-packages/junos_eznc-2.6.8+0.g0745dd0e.dirty-py3.9.egg/jnpr/junos/decorators.py", line 145, in wrapper
    raise ex
  File "/root/pyez_release_268_test1/venv/lib/python3.9/site-packages/junos_eznc-2.6.8+0.g0745dd0e.dirty-py3.9.egg/jnpr/junos/decorators.py", line 117, in wrapper
    rsp = function(self, *args, **kwargs)
  File "/root/pyez_release_268_test1/venv/lib/python3.9/site-packages/junos_eznc-2.6.8+0.g0745dd0e.dirty-py3.9.egg/jnpr/junos/device.py", line 1471, in _rpc_reply
    return self._conn.rpc(rpc_cmd_e, filter_xml)._NCElement__doc
  File "/root/pyez_release_268_test1/venv/lib/python3.9/site-packages/ncclient-0.6.13-py3.9.egg/ncclient/manager.py", line 246, in execute
  File "/root/pyez_release_268_test1/venv/lib/python3.9/site-packages/ncclient-0.6.13-py3.9.egg/ncclient/operations/third_party/juniper/rpc.py", line 52, in request
  File "/root/pyez_release_268_test1/venv/lib/python3.9/site-packages/ncclient-0.6.13-py3.9.egg/ncclient/operations/rpc.py", line 373, in _request
ncclient.operations.rpc.RPCError: warning: statement not found
warning: statement not found
warning: statement not found
warning: statement not found
warning: statement not found
warning: statement not found
warning: statement not found
warning: statement not found
warning: statement not found
warning: statement not found
warning: statement not found
warning: statement not found
warning: statement not found
error: syntax error
warning: statement not found
error: syntax error
warning: statement not found
warning: statement not found
warning: statement not found
warning: statement not found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/root/pyez_release_268_test1/venv/lib/python3.9/site-packages/junos_eznc-2.6.8+0.g0745dd0e.dirty-py3.9.egg/jnpr/junos/utils/config.py", line 500, in try_load
    got = self.rpc.load_config(
  File "/root/pyez_release_268_test1/venv/lib/python3.9/site-packages/junos_eznc-2.6.8+0.g0745dd0e.dirty-py3.9.egg/jnpr/junos/rpcmeta.py", line 287, in load_config
    return self._junos.execute(rpc, ignore_warning=ignore_warning)
  File "/root/pyez_release_268_test1/venv/lib/python3.9/site-packages/junos_eznc-2.6.8+0.g0745dd0e.dirty-py3.9.egg/jnpr/junos/decorators.py", line 76, in wrapper
    return function(*args, **kwargs)
  File "/root/pyez_release_268_test1/venv/lib/python3.9/site-packages/junos_eznc-2.6.8+0.g0745dd0e.dirty-py3.9.egg/jnpr/junos/decorators.py", line 31, in wrapper
    return function(*args, **kwargs)
  File "/root/pyez_release_268_test1/venv/lib/python3.9/site-packages/junos_eznc-2.6.8+0.g0745dd0e.dirty-py3.9.egg/jnpr/junos/device.py", line 854, in execute
    raise EzErrors.RpcError(cmd=rpc_cmd_e, rsp=rsp, errs=ex)
jnpr.junos.exception.RpcError: RpcError(severity: error, bad_element: 65000, message: warning: statement not found
warning: statement not found
warning: statement not found
warning: statement not found
warning: statement not found
warning: statement not found
warning: statement not found
warning: statement not found
warning: statement not found
warning: statement not found
warning: statement not found
warning: statement not found
warning: statement not found
error: syntax error
warning: statement not found
error: syntax error
warning: statement not found
warning: statement not found
warning: statement not found
warning: statement not found)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/root/pyez_release_268_test1/py-junos-eznc/tests/functional/issue_1245.py", line 9, in <module>
    cu.load(path='mx-config.conf', ignore_warning=True, format='set')
  File "/root/pyez_release_268_test1/venv/lib/python3.9/site-packages/junos_eznc-2.6.8+0.g0745dd0e.dirty-py3.9.egg/jnpr/junos/utils/config.py", line 589, in load
    return try_load(rpc_contents, rpc_xattrs, ignore_warning=ignore_warning)
  File "/root/pyez_release_268_test1/venv/lib/python3.9/site-packages/junos_eznc-2.6.8+0.g0745dd0e.dirty-py3.9.egg/jnpr/junos/utils/config.py", line 506, in try_load
    raise ConfigLoadError(cmd=err.cmd, rsp=err.rsp, errs=err.errs)
jnpr.junos.exception.ConfigLoadError: ConfigLoadError(severity: error, bad_element: 65000, message: warning: statement not found
warning: statement not found
warning: statement not found
warning: statement not found
warning: statement not found
warning: statement not found
warning: statement not found
warning: statement not found
warning: statement not found
warning: statement not found
warning: statement not found
warning: statement not found
warning: statement not found
error: syntax error
warning: statement not found
error: syntax error
warning: statement not found
warning: statement not found
warning: statement not found
warning: statement not found)

~/pyez_release_268_test1/py-junos-eznc/tests/functional# cat issue_1245.py 
from jnpr.junos import Device
from jnpr.junos.utils.config import Config
load_warnings = ['statement not found']

dev = Device(host='xx.xx.xx.xx', user='xyz', password='xyz')
dev.open()

with Config(dev, mode='exclusive') as cu:  
    cu.load(path='mx-config.conf', ignore_warning=True, format='set')
    
dev.close()

Thanks

Hi @kpetremann Thanks for sharing the config file , yeah correct , if we set the ignore_warning to (true or string or list of strings ) which are emitted as part of rpc response, will be ignored .

https://www.juniper.net/documentation/us/en/software/junos-pyez/junos-pyez-developer/topics/task/junos-pyez-warnings-ignoring.html

I will try to replicate the issue on local test setup .

Thanks

Hi @kpetremann Thanks for the information , I am yet to replicate this issue on our local setup. I will update you .

Thanks & Regards Chidanand