Merge "Get auth_uri from [clients_keystone] section for ec2tokens"

This commit is contained in:
Jenkins 2015-08-13 04:02:58 +00:00 committed by Gerrit Code Review
commit 89966d6e37
2 changed files with 29 additions and 4 deletions

View File

@ -13,6 +13,7 @@
import hashlib
from keystoneclient import discover as ks_discover
from oslo_config import cfg
from oslo_log import log as logging
from oslo_serialization import jsonutils as json
@ -78,10 +79,17 @@ class EC2Token(wsgi.Middleware):
if auth_uri:
return auth_uri
else:
# Import auth_token to have keystone_authtoken settings setup.
# We can use the auth_uri from the keystone_authtoken section
importutils.import_module('keystonemiddleware.auth_token')
return cfg.CONF.keystone_authtoken['auth_uri']
# First we check the [clients_keystone] section, and if it is not
# set we look in [keystone_authtoken]
if cfg.CONF.clients_keystone.auth_uri:
discover = ks_discover.Discover(
auth_url=cfg.CONF.clients_keystone.auth_uri)
return discover.url_for('3.0')
else:
# Import auth_token to have keystone_authtoken settings setup.
# We can use the auth_uri from the keystone_authtoken section
importutils.import_module('keystonemiddleware.auth_token')
return cfg.CONF.keystone_authtoken['auth_uri']
@staticmethod
def _conf_get_keystone_ec2_uri(auth_uri):

View File

@ -13,6 +13,7 @@
import json
import mock
from oslo_config import cfg
from oslo_utils import importutils
@ -54,12 +55,28 @@ class Ec2TokenTest(common.HeatTestCase):
def test_conf_get_opts(self):
cfg.CONF.set_default('auth_uri', 'http://192.0.2.9/v2.0/',
group='ec2authtoken')
cfg.CONF.set_default('auth_uri', 'this-should-be-ignored',
group='clients_keystone')
ec2 = ec2token.EC2Token(app=None, conf={})
self.assertEqual('http://192.0.2.9/v2.0/', ec2._conf_get('auth_uri'))
self.assertEqual(
'http://192.0.2.9/v2.0/ec2tokens',
ec2._conf_get_keystone_ec2_uri('http://192.0.2.9/v2.0/'))
def test_conf_get_clients_keystone_opts(self):
cfg.CONF.set_default('auth_uri', None, group='ec2authtoken')
cfg.CONF.set_default('auth_uri', 'http://192.0.2.9',
group='clients_keystone')
with mock.patch('keystoneclient.discover.Discover') as discover:
class MockDiscover(object):
def url_for(self, endpoint):
return 'http://192.0.2.9/v3/'
discover.return_value = MockDiscover()
ec2 = ec2token.EC2Token(app=None, conf={})
self.assertEqual(
'http://192.0.2.9/v3/ec2tokens',
ec2._conf_get_keystone_ec2_uri('http://192.0.2.9/v3/'))
def test_conf_get_ssl_default_options(self):
ec2 = ec2token.EC2Token(app=None, conf={})
self.assertTrue(ec2.ssl_options['verify'],