Use same environment for Neutron calls

We need to use the same environment (with the token, etc.) for making
the neutron calls, instead of just trying to obtain the token from the
headers (whose key lookup in the dictionary, by the way, was wrong). We
need to remove some keys from the environ, so that the new request is
created properly.

Change-Id: I86bedab940449a07780e288c03d4de789b8e695a
This commit is contained in:
Alvaro Lopez Garcia 2017-06-22 11:10:47 +02:00
parent b3d479729a
commit 4923182db3
1 changed files with 8 additions and 8 deletions

View File

@ -146,16 +146,16 @@ class BaseHelper(object):
if hasattr(self, 'neutron_endpoint'):
server = self.neutron_endpoint
environ = copy.copy(req.environ)
try:
if "HTTP_X-Auth-Token" not in environ:
env_token = req.environ["keystone.token_auth"]
token = env_token.get_auth_ref(None)['auth_token']
environ = {"HTTP_X-Auth-Token": token}
except Exception:
raise webob.exc.HTTPUnauthorized
# NOTE(aloga): remove things from environment that will cause the
# resquest not to be build properly, see
# https://github.com/Pylons/webob/blob/master/src/webob/request.py
for k in ("PATH_INFO", "SCRIPT_NAME", "SERVER_NAME", "SERVER_PORT",
"HTTP_HOST"):
environ.pop(k, None)
new_req = webob.Request.blank(path=path,
environ=environ, base_url=server)
environ=environ,
base_url=server)
else:
new_req = webob.Request(copy.copy(req.environ))
new_req.script_name = self.openstack_version