Skip to content

sonic-cli 'show interface Ethernet' gets exception for ipv6 disabled subinterface #149

@jy5275

Description

@jy5275

The sonic-cli command 'show interface Ethernet' always gets exception for ipv6 disabled subinterface.

sonic# show interface Ethernet 
Traceback (most recent call last):
  File "/usr/sbin/cli/sonic-cli-if.py", line 119, in <module>
    run(func, sys.argv[2:])
  File "/usr/sbin/cli/sonic-cli-if.py", line 113, in run
    return getattr(Handlers, func)(*args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/sbin/cli/sonic-cli-if.py", line 97, in get_openconfig_interfaces_interfaces
    show_cli_output(template, resp.content)
  File "/usr/sbin/cli/scripts/render_cli.py", line 164, in show_cli_output
    t_str = (j2_env.get_template(template_file).render(json_output=response, **kwargs))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/jinja2/environment.py", line 1295, in render
    self.environment.handle_exception()
  File "/usr/local/lib/python3.11/dist-packages/jinja2/environment.py", line 942, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "/usr/sbin/cli/render-templates/show_interface.j2", line 80, in top-level template code
    {% set ip_list = subif["openconfig-if-ip:ipv6"]["addresses"]["address"] %}
^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/jinja2/environment.py", line 471, in getitem
    return obj[argument]
           ~~~^^^^^^^^^^
jinja2.exceptions.UndefinedError: 'collections.OrderedDict object' has no attribute 'addresses'

As indicated from the stack trace, I found the line 80 of CLI/render/templates/show_interface.j2 is: {% set ip_list = subif["openconfig-if-ip:ipv6"]["addresses"]["address"] %} -> it dones't check if addresses field exist in its parent json object.

I also queried the interfaces config from HTTPS endpoints curl https://localhost/restconf/data/openconfig-interfaces:interfaces --insecure:

...
                     "openconfig-if-ip:ipv6":{
                        "config":{
                           "enabled":false
                        },
                        "state":{
                           "enabled":false
                        }
                     },
...

The openconfig-if-ip:ipv6's value doesn't contain an addresses field. I think that's the reason of this exception

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions