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
- Original URL
- State: open
- Created a year ago
- Comments: 19
Commits related to this issue
- Fix for issue #1245 — committed to chidanandpujar/py-junos-eznc by chidanandpujar 7 months ago
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 .
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