← Back to team overview

yahoo-eng-team team mailing list archive

[Bug 1859068] [NEW] Exception message in neutronclient missing "reason"

 

Public bug reported:

When a ConnectionFailed exception raised from here:
https://opendev.org/openstack/python-
neutronclient/src/commit/9f4a8a9a2db57f9de0a526c75634f8942b41a564/neutronclient/common/exceptions.py#L220-L221
is caught by calling code, the `reason` field is not properly populated,
giving exception messages that do not adequately describe the source of
failure.

The lines above that, which are logged by neutronclient directly,
convert the exception to a message and print the log properly.

2020-01-07 15:24:24,871 DEBUG [neutronclient.client] [redacted] throwing ConnectionFailed : HTTPSConnectionPool(host='redacted', port=redacted): Read timed out. (read timeout=30)
2020-01-07 15:24:24,872 ERROR [redacted] Failed: Connection to neutron failed: %(reason)s
Traceback (most recent call last):
[redacted]
  File "redacted/site-packages/neutronclient/v2_0/client.py", line 366, in post headers=headers, params=params)
  File "redacted/site-packages/neutronclient/v2_0/client.py", line 289, in do_request resp, replybody = self.httpclient.do_request(action, method, body=body)
  File "redacted/site-packages/neutronclient/client.py", line 175, in do_request **kwargs)
  File "redacted/site-packages/neutronclient/client.py", line 111, in _cs_request raise exceptions.ConnectionFailed(reason=e)
ConnectionFailed: Connection to neutron failed: %(reason)s


Upon investigation, it appears the root cause for this bug is related to
the exception object itself being passed to the exception constructor
rather than a string. The constructor tries to populate reason here:
https://opendev.org/openstack/python-
neutronclient/src/branch/master/neutronclient/common/exceptions.py#L57,
but because we pass in an object for reason, instead of a string,
_safe_decode_dict()'s call to encodeutils.safe_decode raises, leaving us
with the unpopulated message on the exception object.

This could be fixed by either:
- Forcefully converting any exception object passed into _safe_decode_dict() to a string.
- Changing the one case, in client.py, to stringify the upstream exception object before passing it in as a reason.

** Affects: neutron
     Importance: Undecided
         Status: New


** Tags: client

-- 
You received this bug notification because you are a member of Yahoo!
Engineering Team, which is subscribed to neutron.
https://bugs.launchpad.net/bugs/1859068

Title:
  Exception message in neutronclient missing "reason"

Status in neutron:
  New

Bug description:
  When a ConnectionFailed exception raised from here:
  https://opendev.org/openstack/python-
  neutronclient/src/commit/9f4a8a9a2db57f9de0a526c75634f8942b41a564/neutronclient/common/exceptions.py#L220-L221
  is caught by calling code, the `reason` field is not properly
  populated, giving exception messages that do not adequately describe
  the source of failure.

  The lines above that, which are logged by neutronclient directly,
  convert the exception to a message and print the log properly.

  2020-01-07 15:24:24,871 DEBUG [neutronclient.client] [redacted] throwing ConnectionFailed : HTTPSConnectionPool(host='redacted', port=redacted): Read timed out. (read timeout=30)
  2020-01-07 15:24:24,872 ERROR [redacted] Failed: Connection to neutron failed: %(reason)s
  Traceback (most recent call last):
  [redacted]
    File "redacted/site-packages/neutronclient/v2_0/client.py", line 366, in post headers=headers, params=params)
    File "redacted/site-packages/neutronclient/v2_0/client.py", line 289, in do_request resp, replybody = self.httpclient.do_request(action, method, body=body)
    File "redacted/site-packages/neutronclient/client.py", line 175, in do_request **kwargs)
    File "redacted/site-packages/neutronclient/client.py", line 111, in _cs_request raise exceptions.ConnectionFailed(reason=e)
  ConnectionFailed: Connection to neutron failed: %(reason)s


  Upon investigation, it appears the root cause for this bug is related
  to the exception object itself being passed to the exception
  constructor rather than a string. The constructor tries to populate
  reason here: https://opendev.org/openstack/python-
  neutronclient/src/branch/master/neutronclient/common/exceptions.py#L57,
  but because we pass in an object for reason, instead of a string,
  _safe_decode_dict()'s call to encodeutils.safe_decode raises, leaving
  us with the unpopulated message on the exception object.

  This could be fixed by either:
  - Forcefully converting any exception object passed into _safe_decode_dict() to a string.
  - Changing the one case, in client.py, to stringify the upstream exception object before passing it in as a reason.

To manage notifications about this bug go to:
https://bugs.launchpad.net/neutron/+bug/1859068/+subscriptions


Follow ups