napalm-automation / napalm-junos

Apache License 2.0
22 stars 42 forks source link

ntp.stats borked due to unicode string literals #152

Closed mirceaulinic closed 7 years ago

mirceaulinic commented 7 years ago

Description of Issue/Question

It looks like our unicode literals together with recent changes in the junos-eznc library, triggered a bug. This has been raised during my tutorial at RIPE 74 (although unfortunately not recorded):

Setup

As in https://ripe74.ripe.net/presentations/18-RIPE-74-Network-automation-at-scale-up-and-running-in-60-minutes.pdf

napalm-junos version

$ pip freeze | grep napalm-junos
napalm-junos==0.6.6

JunOS version

$ sudo salt device1 grains.get version
device1:
    15.1F6-S1.4

Steps to Reproduce the Issue

Error Traceback

(Paste the complete traceback of the exception between quotes below)

$ sudo salt device1 ntp.stats
device1:
    ----------
    comment:
        Cannot execute "get_ntp_stats" on ip-172-31-9-153.us-east-2.compute.internal as napalm. Reason: 'unicode' object has no attribute 'tag'!
    out:
        ----------
    result:
        False
    traceback:
        Traceback (most recent call last):
          File "/usr/lib/python2.7/dist-packages/salt/proxy/napalm.py", line 294, in call
            out = getattr(NETWORK_DEVICE.get('DRIVER'), method)(**params)  # calls the method with the specified parameters
          File "/usr/local/lib/python2.7/dist-packages/napalm_junos/junos.py", line 888, in get_ntp_stats
            ntp_assoc_output = self.device.cli('show ntp associations no-resolve')
          File "/usr/local/lib/python2.7/dist-packages/jnpr/junos/device.py", line 600, in cli
            rpc_string = self.cli_to_rpc_string(command)
          File "/usr/local/lib/python2.7/dist-packages/jnpr/junos/device.py", line 548, in cli_to_rpc_string
            rpc_string = "rpc.%s(" % (rpc.tag.replace('-', '_'))
        AttributeError: 'unicode' object has no attribute 'tag'
mirceaulinic commented 7 years ago

Easy to reproduce:

>>> d.cli('show ntp associations no-resolve')
'\n   remote         refid           st t when poll reach   delay   offset  jitter\n===============================================================================\n 1.2.3.4          .INIT.          16 -    - 1024    0    0.000    0.000 4000.00\n'
>>> j.get_ntp_stats()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/napalm_junos/junos.py", line 888, in get_ntp_stats
    ntp_assoc_output = self.device.cli('show ntp associations no-resolve')
  File "/usr/local/lib/python2.7/dist-packages/jnpr/junos/device.py", line 600, in cli
    rpc_string = self.cli_to_rpc_string(command)
  File "/usr/local/lib/python2.7/dist-packages/jnpr/junos/device.py", line 548, in cli_to_rpc_string
    rpc_string = "rpc.%s(" % (rpc.tag.replace('-', '_'))
AttributeError: 'unicode' object has no attribute 'tag'
>>> from __future__ import unicode_literals
>>> d.cli('show ntp associations no-resolve')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/jnpr/junos/device.py", line 600, in cli
    rpc_string = self.cli_to_rpc_string(command)
  File "/usr/local/lib/python2.7/dist-packages/jnpr/junos/device.py", line 548, in cli_to_rpc_string
    rpc_string = "rpc.%s(" % (rpc.tag.replace('-', '_'))
AttributeError: 'unicode' object has no attribute 'tag'
mirceaulinic commented 7 years ago

This will be tracked under https://github.com/Juniper/py-junos-eznc/pull/721

mirceaulinic commented 7 years ago

Closed via https://github.com/Juniper/py-junos-eznc/commit/b0928145e2f1fb7b922720185a07206d225b6e8f