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

Bug #1849449 reported by Rodolfo Alonso on 2019-10-23
This bug affects 1 person
Affects Status Importance Assigned to Milestone
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/", 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/", line 449, in _process_cmd
    ret = func(*f_args, **f_kwargs)
  File "/usr/lib/python3.6/site-packages/neutron/privileged/agent/linux/", line 53, in sync_inner
    return input_func(*args, **kwargs)
  File "/usr/lib/python3.6/site-packages/oslo_privsep/", line 247, in _wrap
    return func(*args, **kwargs)
  File "/usr/lib/python3.6/site-packages/neutron/privileged/agent/linux/", 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/", line 254, in _run_iproute_link
    idx = get_link_id(device, namespace)
  File "/usr/lib/python3.6/site-packages/neutron/privileged/agent/linux/", 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

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

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