CiscoTestAutomation / pyats

Cisco DevNet pyATS Test Framework Bug Tracker
Apache License 2.0
149 stars 31 forks source link

"missing" description on show interfaces #191

Open tgraham2 opened 1 year ago

tgraham2 commented 1 year ago

When a "description" does not exist, pyATS does not return the key. In my use case I want to display the statistics of only the interfaces with a certain keyword in the interface description. The loop fails in the case there is no description.

- name: get interface status
  ansible.utils.cli_parse:
    command: show interfaces
    parser:
      name: ansible.netcommon.pyats
  register: intf_output

- name: Display Interface status
  debug:
    msg: 
      - "Interface {{item.key}}    Description: {{ item.description }}"
      - "Rate In: {{item.value.counters.rate.in_rate}} Out: {{item.value.counters.rate.out_rate}}"
      - "Counters: Cleared - {{item.value.counters.last_clear}}"
      - "          Errors: Input - {{item.value.counters.in_errors}}  Output - {{item.value.counters.out_errors}}"
  loop: "{{ query('dict', intf_output['parsed']|default({})) }}"
  when: item.description == "XXX"

"The conditional check 'item.description == \"XXX\"' failed. The error was: error while evaluating conditional (item.description == \"XXX\"): 'dict object' has no attribute 'description'

Could we consider making the change that the description is always returned - with a null string in the case of no description being configured (instead of no key-value pair at all).

ketulsuthar commented 1 year ago

Can you provide the logs as well as steps for reproducing it?