Fix for getting auth url for hadoop-swift

Changes:
* use service catalog for getting auth url
* changes in unit tests

Change-Id: Ifa4767a14515709d602c6dcded3716980a1d47ef
Closes-bug: #1393758
This commit is contained in:
Sergey Reshetnyak 2014-11-18 16:09:08 +03:00
parent 17e4f4dac5
commit 15d5933b5d
4 changed files with 28 additions and 15 deletions

View File

@ -17,6 +17,7 @@ from oslo.config import cfg
from six.moves.urllib import parse as urlparse
from sahara import context
from sahara.utils.openstack import base as clients_base
from sahara.utils.openstack import keystone as k
@ -32,7 +33,9 @@ def retrieve_auth_url():
Hadoop Swift library doesn't support keystone v3 api.
"""
info = urlparse.urlparse(context.current().auth_uri)
auth_url = clients_base.url_for(context.current().service_catalog,
'identity')
info = urlparse.urlparse(auth_url)
if CONF.use_domain_for_proxy_users:
url = 'v3/auth'

View File

@ -36,10 +36,12 @@ class BaseClusterConfigurerTest(b.SaharaTestCase):
for a in actual:
self.assertIn(a, expected)
@m.patch('sahara.utils.openstack.base.url_for')
@m.patch('sahara.context.ctx')
@m.patch('sahara.plugins.mapr.util.config.is_data_locality_enabled')
@m.patch('sahara.plugins.mapr.util.config_file_utils.to_file_content')
def test_configure_wo_generals(self, tfc_mock, gtm_mock, cc_mock):
def test_configure_wo_generals(self, tfc_mock, gtm_mock, cc_mock,
url_for_mock):
def to_file_content(*args, **kargs):
data = args[0]
if isinstance(data, dict):
@ -49,9 +51,10 @@ class BaseClusterConfigurerTest(b.SaharaTestCase):
return {None: data}
tfc_mock.side_effect = to_file_content
gtm_mock.return_value = False
cc_mock.return_value = s.AttrDict(auth_uri='http://auth',
tenant_name='tenant_0',
tenant_id='tenant_id')
url_for_mock.return_value = 'http://auth'
cc_mock.return_value = s.AttrDict(tenant_name='tenant_0',
tenant_id='tenant_id',
service_catalog=None)
i0 = s.Instance(instance_name='i0',
management_ip='192.168.1.10',
@ -111,12 +114,13 @@ class BaseClusterConfigurerTest(b.SaharaTestCase):
self.assertItemsEqual(i2.remote().fs, [core_site, cldb,
hadoop_v])
@m.patch('sahara.utils.openstack.base.url_for')
@m.patch('sahara.context.ctx')
@m.patch('sahara.plugins.mapr.util.config.is_data_locality_enabled')
@m.patch('sahara.topology.topology_helper.generate_topology_map')
@m.patch('sahara.plugins.mapr.util.config_file_utils.to_file_content')
def test_configure_with_topology(self, tfc_mock, gtm_mock,
dle_mock, cc_mock):
dle_mock, cc_mock, url_for_mock):
def to_file_content(*args, **kargs):
data = args[0]
if isinstance(data, dict):
@ -132,9 +136,10 @@ class BaseClusterConfigurerTest(b.SaharaTestCase):
'10.10.1.11': 'r',
'i2': 'r', '192.168.1.12': 'r',
'10.10.1.12': 'r'}
cc_mock.return_value = s.AttrDict(auth_uri='http://auth',
tenant_name='tenant_0',
tenant_id='tenant_id')
url_for_mock.return_value = 'http://auth'
cc_mock.return_value = s.AttrDict(tenant_name='tenant_0',
tenant_id='tenant_id',
service_catalog=None)
i0 = s.Instance(instance_name='i0',
management_ip='192.168.1.10',

View File

@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import mock
from sahara.swift import swift_helper as h
from sahara.tests.unit import base
@ -31,10 +33,10 @@ SERVICE_SPECIFIC = ["auth.url", "tenant",
class SwiftIntegrationTestCase(base.SaharaTestCase):
def test_get_swift_configs(self):
self.setup_context(tenant_name='test_tenant',
auth_uri='http://localhost:8080/v2.0/')
@mock.patch('sahara.utils.openstack.base.url_for')
def test_get_swift_configs(self, url_for_mock):
url_for_mock.return_value = 'http://localhost:5000/v2.0'
self.setup_context(tenant_name='test_tenant')
self.override_config("os_region_name", 'regionOne')
result = h.get_swift_configs()

View File

@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import mock
from sahara.swift import utils
from sahara.tests.unit import base as testbase
@ -23,11 +25,12 @@ class SwiftUtilsTest(testbase.SaharaTestCase):
super(SwiftUtilsTest, self).setUp()
self.override_config('use_identity_api_v3', True)
def test_retrieve_auth_url(self):
@mock.patch('sahara.utils.openstack.base.url_for')
def test_retrieve_auth_url(self, url_for_mock):
correct = "https://127.0.0.1:8080/v2.0/"
def _assert(uri):
self.setup_context(auth_uri=uri)
url_for_mock.return_value = uri
self.assertEqual(correct, utils.retrieve_auth_url())
_assert("%s/" % correct)