get_link_id() traceback in case of non-existing interface is misleading

Bug #1849449 reported by Rodolfo Alonso on 2019-10-23
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
neutron
Medium
Rodolfo Alonso

Bug Description

When privileged.agent.linux.ip_lib.get_link_id() method does not find the interface, the traceback thrown is misleading: first the index error is logged and then NetworkInterfaceNotFound traceback. We can reduce this traceback to the main one avoiding the index error exception.

Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/neutron/privileged/agent/linux/ip_lib.py", line 246, in get_link_id
    return ip.link_lookup(ifname=device)[0]
IndexError: list index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/oslo_privsep/daemon.py", line 449, in _process_cmd
    ret = func(*f_args, **f_kwargs)
  File "/usr/lib/python3.6/site-packages/neutron/privileged/agent/linux/ip_lib.py", line 53, in sync_inner
    return input_func(*args, **kwargs)
  File "/usr/lib/python3.6/site-packages/oslo_privsep/priv_context.py", line 247, in _wrap
    return func(*args, **kwargs)
  File "/usr/lib/python3.6/site-packages/neutron/privileged/agent/linux/ip_lib.py", line 406, in get_link_attributes
    link = _run_iproute_link("get", device, namespace)[0]
  File "/usr/lib/python3.6/site-packages/neutron/privileged/agent/linux/ip_lib.py", line 254, in _run_iproute_link
    idx = get_link_id(device, namespace)
  File "/usr/lib/python3.6/site-packages/neutron/privileged/agent/linux/ip_lib.py", line 248, in get_link_id
    raise NetworkInterfaceNotFound(device=device, namespace=namespace)
neutron.privileged.agent.linux.ip_lib.NetworkInterfaceNotFound: Network interface tap46dac0f2-cb not found in namespace qdhcp-8c9e6c68-86ef-4bb0-b3fa-9a36a71d0ccb.

Changed in neutron:
assignee: nobody → Rodolfo Alonso (rodolfo-alonso-hernandez)

Fix proposed to branch: master
Review: https://review.opendev.org/690514

Changed in neutron:
status: New → In Progress
Changed in neutron:
importance: Undecided → Medium

Reviewed: https://review.opendev.org/690514
Committed: https://git.openstack.org/cgit/openstack/neutron/commit/?id=ecef65b9b51fc1bd684ca9eb72a024ee44ca9347
Submitter: Zuul
Branch: master

commit ecef65b9b51fc1bd684ca9eb72a024ee44ca9347
Author: Rodolfo Alonso Hernandez <email address hidden>
Date: Wed Oct 23 08:31:59 2019 +0000

    Do not use exceptions in get_link_id() to control the code flow

    Instead of using exceptions as control flow, check the Pyroute2 command
    result and only raise the Neutron exception if needed. This will also
    reduce the traceback log in case of raising NetworkInterfaceNotFound.

    Although in Python the use of exception for this is common, this is
    usually considered an antipattern.

    Change-Id: I0e8bb3b0f6a46f2bac75e38c6ac6cdd094247f89
    Closes-Bug: #1849449

Changed in neutron:
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers