From 1efe2cef2cfc6709bb00aa5daf4aec0980b01aa0 Mon Sep 17 00:00:00 2001 From: Lennart Regebro Date: Tue, 26 Aug 2014 12:23:35 +0200 Subject: [PATCH] Use Tuskar endpoint from Keystone Change-Id: Ie8b87b8f62a8efafb4a6fe4947aaa312bfa326f2 Closes-bug: #1288261 --- tuskar_ui/api/tuskar.py | 25 ++++++++++++++----- tuskar_ui/test/helpers.py | 18 ++++++++++++++ tuskar_ui/test/test_data/keystone_data.py | 30 +++++++++++++++++++++++ tuskar_ui/test/test_data/utils.py | 2 ++ 4 files changed, 69 insertions(+), 6 deletions(-) create mode 100644 tuskar_ui/test/test_data/keystone_data.py diff --git a/tuskar_ui/api/tuskar.py b/tuskar_ui/api/tuskar.py index 7ef7d4f0c..d6ed98566 100644 --- a/tuskar_ui/api/tuskar.py +++ b/tuskar_ui/api/tuskar.py @@ -10,9 +10,9 @@ # License for the specific language governing permissions and limitations # under the License. -import django.conf import logging +from django.conf import settings from django.utils.translation import ugettext_lazy as _ from openstack_dashboard.api import base from openstack_dashboard.api import glance @@ -23,17 +23,30 @@ from tuskar_ui.cached_property import cached_property # noqa from tuskar_ui.handle_errors import handle_errors # noqa LOG = logging.getLogger(__name__) -TUSKAR_ENDPOINT_URL = getattr(django.conf.settings, 'TUSKAR_ENDPOINT_URL') MASTER_TEMPLATE_NAME = 'plan.yaml' ENVIRONMENT_NAME = 'environment.yaml' +TUSKAR_SERVICE = 'management' # FIXME: request isn't used right in the tuskar client right now, # but looking at other clients, it seems like it will be in the future -def tuskarclient(request): - c = tuskar_client.get_client('2', tuskar_url=TUSKAR_ENDPOINT_URL, - os_auth_token=request.user.token.id) - return c +def tuskarclient(request, password=None): + api_version = "2" + insecure = getattr(settings, 'OPENSTACK_SSL_NO_VERIFY', False) + ca_file = getattr(settings, 'OPENSTACK_SSL_CACERT', None) + endpoint = base.url_for(request, TUSKAR_SERVICE) + + LOG.debug('tuskarclient connection created using token "%s" and url "%s"' % + (request.user.token.id, endpoint)) + + client = tuskar_client.get_client(api_version, + tuskar_url=endpoint, + insecure=insecure, + ca_file=ca_file, + username=request.user.username, + password=password, + os_auth_token=request.user.token.id) + return client class OvercloudPlan(base.APIResourceWrapper): diff --git a/tuskar_ui/test/helpers.py b/tuskar_ui/test/helpers.py index 87be6f0d1..002a42853 100644 --- a/tuskar_ui/test/helpers.py +++ b/tuskar_ui/test/helpers.py @@ -58,6 +58,15 @@ class TestCase(openstack_dashboard_helpers.TestCase): # load tuskar-specific test data test_data_utils.load_test_data(self) + # Reload the service catalog + tenants = self.context['authorized_tenants'] + self.setActiveUser(id=self.user.id, + token=self.token, + username=self.user.name, + tenant_id=self.tenant.id, + service_catalog=self.service_catalog, + authorized_tenants=tenants) + class BaseAdminViewTests(openstack_dashboard_helpers.BaseAdminViewTests): """A ``TestCase`` subclass which sets an active user with the "admin" role @@ -80,3 +89,12 @@ class APITestCase(openstack_dashboard_helpers.APITestCase): # load tuskar-specfic test data test_data_utils.load_test_data(self) + + # Reload the service catalog + tenants = self.context['authorized_tenants'] + self.setActiveUser(id=self.user.id, + token=self.token, + username=self.user.name, + tenant_id=self.tenant.id, + service_catalog=self.service_catalog, + authorized_tenants=tenants) diff --git a/tuskar_ui/test/test_data/keystone_data.py b/tuskar_ui/test/test_data/keystone_data.py new file mode 100644 index 000000000..356c2d6f6 --- /dev/null +++ b/tuskar_ui/test/test_data/keystone_data.py @@ -0,0 +1,30 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +def data(TEST): + + # Add tuskar to the keystone data + TEST.service_catalog.append( + {"type": "management", + "name": "tuskar", + "endpoints_links": [], + "endpoints": [ + {"region": "RegionOne", + "adminURL": "http://admin.tuskar.example.com:8585/v2", + "internalURL": "http://int.tuskar.example.com:8585/v2", + "publicURL": "http://public.tuskar.example.com:8585/v2"}, + {"region": "RegionTwo", + "adminURL": "http://admin.tuskar2.example.com:8585/v2", + "internalURL": "http://int.tuskar2.example.com:8585/v2", + "publicURL": "http://public.tuskar2.example.com:8585/v2"}]}, + ) diff --git a/tuskar_ui/test/test_data/utils.py b/tuskar_ui/test/test_data/utils.py index f7481685c..267242580 100644 --- a/tuskar_ui/test/test_data/utils.py +++ b/tuskar_ui/test/test_data/utils.py @@ -25,6 +25,7 @@ def load_test_data(load_onto=None): from tuskar_ui.test.test_data import exceptions from tuskar_ui.test.test_data import flavor_data from tuskar_ui.test.test_data import heat_data as tuskar_heat_data + from tuskar_ui.test.test_data import keystone_data as tuskar_keystone_data from tuskar_ui.test.test_data import node_data from tuskar_ui.test.test_data import tuskar_data @@ -40,6 +41,7 @@ def load_test_data(load_onto=None): flavor_data.data, node_data.data, tuskar_heat_data.data, + tuskar_keystone_data.data, tuskar_data.data) if load_onto: for data_func in loaders: