Use non-versioned auth_url for keystone

keystoneclient discover can't get v3 auth_url using v2 auth_url. It
accepts an url without version number. This patch fixes this issue.

Change-Id: I45b4c016bd91afc39d39620920951043bb71df05
Closes-Bug: #1398254
This commit is contained in:
Yanyan Hu 2014-12-02 11:34:30 +08:00 committed by Thomas Herve
parent 450188d52e
commit f6ca7618c4
2 changed files with 13 additions and 1 deletions

View File

@ -56,7 +56,8 @@ class Keystone(object):
self.project_id = project_id
self._client = None
try:
discover = ks_discover.Discover(auth_url=auth_url)
auth_url_noneversion = auth_url.replace('/v2.0', '/')
discover = ks_discover.Discover(auth_url=auth_url_noneversion)
v3_auth_url = discover.url_for('3.0')
if v3_auth_url:
self.auth_url = v3_auth_url

View File

@ -62,6 +62,17 @@ class KeystoneTest(testtools.TestCase):
test_heat.FakeKeystoneClient(self))
self.assertEqual(ks.auth_url, 'http://server.test:5000/v3')
@mock.patch.object(ks_discover.Discover, '__init__')
@mock.patch.object(ks_discover.Discover, 'url_for')
def test_discover_v3_unsupported(self, mock_url_for, mock___init__):
mock___init__.return_value = None
mock_url_for.return_value = None
ks = keystone.Keystone(
'http://server.test:5000/v2.0', 'auser', 'apassword', 'aproject',
test_heat.FakeKeystoneClient(self))
self.assertEqual(ks.auth_url, 'http://server.test:5000/v2.0')
mock___init__.assert_called_with(auth_url='http://server.test:5000/')
@mock.patch.object(ks_discover.Discover, '__init__')
@mock.patch.object(ks_discover.Discover, 'url_for')
def test_cache_is_created(self, mock_url_for, mock___init__):