Comment 4 for bug 1628316

Revision history for this message
Matthew Edmonds (edmondsw) wrote :

I see the problem... The exception that's being raised is:

Traceback (most recent call last):
  File "./test", line 26, in <module>
    f = conn.compute.find_flavor('test')
  File "/usr/lib/python2.7/site-packages/openstack/compute/v2/_proxy.py", line 66, in find_flavor
    ignore_missing=ignore_missing)
  File "/usr/lib/python2.7/site-packages/openstack/proxy2.py", line 105, in _find
    **attrs)
  File "/usr/lib/python2.7/site-packages/openstack/resource2.py", line 790, in find
    return match.get(session)
  File "/usr/lib/python2.7/site-packages/openstack/resource2.py", line 590, in get
    response = session.get(request.uri, endpoint_filter=self.service)
  File "/usr/lib/python2.7/site-packages/keystoneauth1/session.py", line 667, in get
    return self.request(url, 'GET', **kwargs)
  File "/usr/lib/python2.7/site-packages/positional/__init__.py", line 94, in inner
    return func(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/keystoneauth1/session.py", line 570, in request
    raise exceptions.from_response(resp, method, url)
keystoneauth1.exceptions.http.NotFound: Not Found (HTTP 404)

but the exception that's being expected and handled (realizing it's not an id, and moving on to find it by name) in openstack.resource2.find is openstack.exceptions.NotFoundException... similar name, but not the same thing.

I threw a breakpoint in openstack.session.map_exceptions, which appears to be the only place that raises NotFoundException, and it never triggered in this flow. Instead of using openstack.session, it appears to be using keystoneauth1.session... and then it hit me... This is how I created my session:

import argparse
import sys
from keystoneauth1 import loading as ks_loading
from openstack import connection
parser = argparse.ArgumentParser()
ks_loading.register_auth_argparse_arguments(parser, sys.argv[1:],default='v3password')
ks_loading.register_session_argparse_arguments(parser)
args = parser.parse_args()
auth = ks_loading.load_auth_from_argparse_arguments(args)
sess = ks_loading.load_session_from_argparse_arguments(args, auth=auth)
conn = connection.Connection(session=sess, authenticator=auth)

And that works for other things... but not here, because of the apparent expectation that the session is an instance of openstack.session.Session. But I don't think I can do what I've been doing (creating a session based on OS_* environment variables or --os-* CLI arguments) if I switch to an openstack.session.Session. And I expect this will trip up others who don't realize there are two different types of sessions and they can't use the very widely used keystoneauth1 version. Even though it actually seems to work for a while.