[openstack-dev] [Nova] python 3 tests hate my exception handling

Michael Still mikal at stillhq.com
Wed Jan 4 02:48:13 UTC 2017


So...

Our python3 tests hate [1] my exception handling for continued vendordata
implementation [2].

Basically, it goes a bit like this -- I need to move from using requests to
keystoneauth1 for external vendordata requests. This is because we're
adding support for sending keystone headers with the request so that the
external service can verify that it is nova talking. That bit isn't too
hard.

However, keystoneauth1 uses different exceptions to report errors.
Conveniently, it has variables which list all of the connection and http
exceptions which it might raise. Inconveniently, they're listed as strings,
so I have to construct a list of them like this:

# NOTE(mikal): keystoneauth makes me jump through hoops to get these
# exceptions, which are listed as strings. Mutter.
KEYSTONEAUTH_EXCEPTIONS = [TypeError, ValueError]
for excname in ks_exceptions.connection.__all__ +
ks_exceptions.http.__all__:
    KEYSTONEAUTH_EXCEPTIONS.append(getattr(ks_exceptions, excname))

Then when it comes time to catch exceptions from keystoneauth1, we can just
do this thing:

        except tuple(KEYSTONEAUTH_EXCEPTIONS) as e:
            LOG.warning(_LW('Error from dynamic vendordata service '
                            '%(service_name)s at %(url)s: %(error)s'),
                        {'service_name': service_name,
                         'url': url,
                         'error': e},
                        instance=self.instance)
            return {}

Which might be a bit horrible, but is nice in that if keystoneauth1 adds
new connection or http exceptions, we get to catch them for free.

This all works and is tested. However, it causes the py3 tests to fail with
this exception:

'TypeError: catching classes that do not inherit from BaseException is not
allowed'

Which is bemusing to me because I'm not very smart.

So, could someone smarter than me please look at [1] and tell me why I get
[2] and how to not get that thing? Answers involving manually listing many
exceptions will result in me making a sad face and sarcastic comment in the
code, so something more elegant than that would be nice.

Discuss.

Thanks,
Michael


1:
http://logs.openstack.org/91/416391/1/check/gate-nova-python35-db/7835df3/console.html#_2017-01-04_01_10_35_520409
2:
https://review.openstack.org/#/c/415597/3/nova/api/metadata/vendordata_dynamic.py

-- 
Rackspace Australia
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstack.org/pipermail/openstack-dev/attachments/20170104/76d5f6ef/attachment.html>


More information about the OpenStack-dev mailing list