Using keystone discover to find V3 auth_url
This patch uses keystone client discover to find correct V3 auth_url which is expected by heat collector. Change-Id: I2b8b5a768bdeb1cd1d20fab3b4234306c1429d6d Closes-Bug: #1341936
This commit is contained in:
parent
7d61ca940c
commit
47bb4bddb2
@ -16,6 +16,7 @@ import hashlib
|
||||
import os
|
||||
|
||||
from dogpile import cache
|
||||
from keystoneclient import discover as ks_discover
|
||||
from keystoneclient import exceptions as ks_exc
|
||||
from keystoneclient.v3 import client as ks_keystoneclient
|
||||
from oslo.config import cfg
|
||||
@ -50,11 +51,19 @@ class Keystone(object):
|
||||
Uses keystoneclient.v3 if unspecified.
|
||||
'''
|
||||
self.keystoneclient = keystoneclient or ks_keystoneclient
|
||||
self.auth_url = auth_url
|
||||
self.user_id = user_id
|
||||
self.password = password
|
||||
self.project_id = project_id
|
||||
self._client = None
|
||||
try:
|
||||
discover = ks_discover.Discover(auth_url=auth_url)
|
||||
v3_auth_url = discover.url_for('3.0')
|
||||
if v3_auth_url:
|
||||
self.auth_url = v3_auth_url
|
||||
else:
|
||||
self.auth_url = auth_url
|
||||
except ks_exc.ClientException:
|
||||
self.auth_url = auth_url.replace('/v2.0', '/v3')
|
||||
if CONF.keystone.cache_dir:
|
||||
if not os.path.isdir(CONF.keystone.cache_dir):
|
||||
os.makedirs(CONF.keystone.cache_dir, mode=0o700)
|
||||
|
@ -17,11 +17,13 @@ import copy
|
||||
import extras
|
||||
import fixtures
|
||||
import json
|
||||
import mock
|
||||
import os
|
||||
import signal
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
from keystoneclient import discover as ks_discover
|
||||
from oslo.config import cfg
|
||||
import testtools
|
||||
from testtools import matchers
|
||||
@ -335,8 +337,12 @@ class TestCollectAll(testtools.TestCase):
|
||||
cfg.CONF.heat.stack_id = 'a/c482680f-7238-403d-8f76-36acf0c8e0aa'
|
||||
cfg.CONF.heat.resource_name = 'server'
|
||||
|
||||
def _call_collect_all(
|
||||
self, store, collector_kwargs_map=None, collectors=None):
|
||||
@mock.patch.object(ks_discover.Discover, '__init__')
|
||||
@mock.patch.object(ks_discover.Discover, 'url_for')
|
||||
def _call_collect_all(self, mock_url_for, mock___init__, store,
|
||||
collector_kwargs_map=None, collectors=None):
|
||||
mock___init__.return_value = None
|
||||
mock_url_for.return_value = cfg.CONF.heat.auth_url
|
||||
if collector_kwargs_map is None:
|
||||
collector_kwargs_map = {
|
||||
'ec2': {'requests_impl': test_ec2.FakeRequests},
|
||||
|
@ -12,7 +12,10 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import mock
|
||||
|
||||
import fixtures
|
||||
from keystoneclient import discover as ks_discover
|
||||
from keystoneclient import exceptions as ks_exc
|
||||
from oslo.config import cfg
|
||||
import testtools
|
||||
@ -126,7 +129,11 @@ class TestHeatBase(testtools.TestCase):
|
||||
|
||||
|
||||
class TestHeat(TestHeatBase):
|
||||
def test_collect_heat(self):
|
||||
@mock.patch.object(ks_discover.Discover, '__init__')
|
||||
@mock.patch.object(ks_discover.Discover, 'url_for')
|
||||
def test_collect_heat(self, mock_url_for, mock___init__):
|
||||
mock___init__.return_value = None
|
||||
mock_url_for.return_value = cfg.CONF.heat.auth_url
|
||||
heat_md = heat.Collector(keystoneclient=FakeKeystoneClient(self),
|
||||
heatclient=FakeHeatClient(self)).collect()
|
||||
self.assertThat(heat_md, matchers.IsInstance(list))
|
||||
@ -137,9 +144,17 @@ class TestHeat(TestHeatBase):
|
||||
self.assertIn(k, heat_md)
|
||||
self.assertEqual(heat_md[k], META_DATA[k])
|
||||
|
||||
self.assertEqual('', self.log.output)
|
||||
# FIXME(yanyanhu): Temporary hack to deal with possible log
|
||||
# level setting for urllib3.connectionpool.
|
||||
self.assertTrue(
|
||||
self.log.output == '' or
|
||||
self.log.output == 'Starting new HTTP connection (1): 127.0.0.1\n')
|
||||
|
||||
def test_collect_heat_fail(self):
|
||||
@mock.patch.object(ks_discover.Discover, '__init__')
|
||||
@mock.patch.object(ks_discover.Discover, 'url_for')
|
||||
def test_collect_heat_fail(self, mock_url_for, mock___init__):
|
||||
mock___init__.return_value = None
|
||||
mock_url_for.return_value = cfg.CONF.heat.auth_url
|
||||
heat_collect = heat.Collector(
|
||||
keystoneclient=FakeFailKeystoneClient(self),
|
||||
heatclient=FakeHeatClient(self))
|
||||
|
@ -12,9 +12,11 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import mock
|
||||
import tempfile
|
||||
|
||||
import fixtures
|
||||
from keystoneclient import discover as ks_discover
|
||||
from keystoneclient import exceptions as ks_exc
|
||||
from oslo.config import cfg
|
||||
import testtools
|
||||
@ -50,19 +52,37 @@ class KeystoneTest(testtools.TestCase):
|
||||
self.cachedir = tempfile.mkdtemp()
|
||||
cfg.CONF.set_override('cache_dir', self.cachedir, group='keystone')
|
||||
|
||||
def test_cache_is_created(self):
|
||||
@mock.patch.object(ks_discover.Discover, '__init__')
|
||||
@mock.patch.object(ks_discover.Discover, 'url_for')
|
||||
def test_discover_fail(self, mock_url_for, mock___init__):
|
||||
mock___init__.return_value = None
|
||||
mock_url_for.side_effect = ks_exc.DiscoveryFailure()
|
||||
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/v3')
|
||||
|
||||
@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__):
|
||||
mock___init__.return_value = None
|
||||
mock_url_for.return_value = 'http://server.test:5000/'
|
||||
ks = keystone.Keystone(
|
||||
'http://server.test:5000/', 'auser', 'apassword', 'aproject',
|
||||
test_heat.FakeKeystoneClient(self))
|
||||
self.assertIsNotNone(ks.cache)
|
||||
|
||||
def _make_ks(self, client):
|
||||
@mock.patch.object(ks_discover.Discover, '__init__')
|
||||
@mock.patch.object(ks_discover.Discover, 'url_for')
|
||||
def _make_ks(self, client, mock_url_for, mock___init__):
|
||||
class Configs(object):
|
||||
auth_url = 'http://server.test:5000/'
|
||||
user_id = 'auser'
|
||||
password = 'apassword'
|
||||
project_id = 'aproject'
|
||||
|
||||
mock___init__.return_value = None
|
||||
mock_url_for.return_value = Configs.auth_url
|
||||
return keystone.Keystone(
|
||||
'http://server.test:5000/', 'auser', 'apassword', 'aproject',
|
||||
client(self, Configs))
|
||||
|
@ -2,6 +2,7 @@ coverage>=3.6
|
||||
discover
|
||||
fixtures>=0.3.14
|
||||
hacking>=0.8.0,<0.9
|
||||
mock>=1.0
|
||||
python-subunit>=0.0.18
|
||||
sphinx>=1.1.2,!=1.2.0,<1.3
|
||||
testrepository>=0.0.18
|
||||
|
Loading…
Reference in New Issue
Block a user