Merge "Refactor app response for api request '/api/keystone/svc-catalog'"
This commit is contained in:
commit
11fe92baf0
|
@ -13,6 +13,8 @@
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
"""API over the keystone service."""
|
"""API over the keystone service."""
|
||||||
|
|
||||||
|
import copy
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
import django.http
|
import django.http
|
||||||
from django.views import generic
|
from django.views import generic
|
||||||
|
@ -542,7 +544,14 @@ class ServiceCatalog(generic.View):
|
||||||
@rest_utils.ajax()
|
@rest_utils.ajax()
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
"""Return the service catalog associated with the current user."""
|
"""Return the service catalog associated with the current user."""
|
||||||
return request.user.service_catalog
|
catalog = copy.deepcopy(request.user.service_catalog)
|
||||||
|
for record in catalog:
|
||||||
|
for endpoint in record['endpoints']:
|
||||||
|
if endpoint['interface'] != 'public':
|
||||||
|
record['endpoints'].remove(endpoint)
|
||||||
|
if not record['endpoints']:
|
||||||
|
catalog.remove(record)
|
||||||
|
return catalog
|
||||||
|
|
||||||
|
|
||||||
@urls.register
|
@urls.register
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
import mock
|
import mock
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
import six
|
|
||||||
|
|
||||||
from openstack_dashboard import api
|
from openstack_dashboard import api
|
||||||
from openstack_dashboard.api.rest import keystone
|
from openstack_dashboard.api.rest import keystone
|
||||||
|
@ -688,13 +687,70 @@ class KeystoneRestTestCase(test.TestCase):
|
||||||
#
|
#
|
||||||
def test_service_catalog_get(self):
|
def test_service_catalog_get(self):
|
||||||
request = self.mock_rest_request()
|
request = self.mock_rest_request()
|
||||||
|
request.user = mock.MagicMock(**{'service_catalog': [
|
||||||
|
{'endpoints': [
|
||||||
|
{'url': 'http://cool_url/image',
|
||||||
|
'interface': 'admin',
|
||||||
|
'region': 'RegionOne',
|
||||||
|
'region_id': 'RegionOne',
|
||||||
|
'id': 'test'},
|
||||||
|
{'url': 'http://cool_url/image',
|
||||||
|
'interface': 'public',
|
||||||
|
'region': 'RegionOne',
|
||||||
|
'region_id': 'RegionOne',
|
||||||
|
'id': 'test'},
|
||||||
|
{'url': 'http://cool_url/image',
|
||||||
|
'interface': 'internal',
|
||||||
|
'region': 'RegionOne',
|
||||||
|
'region_id': 'RegionOne',
|
||||||
|
'id': 'test'}],
|
||||||
|
'type': 'image',
|
||||||
|
'id': '2b5bc2e59b094f898a43f5e8ce446240',
|
||||||
|
'name': 'glance'},
|
||||||
|
{'endpoints': [
|
||||||
|
{'url': 'http://cool_url/volume/v2/test',
|
||||||
|
'interface': 'public',
|
||||||
|
'region': 'RegionOne',
|
||||||
|
'region_id': 'RegionOne',
|
||||||
|
'id': '29a629afb80547ea9baa4266e97b4cb5'},
|
||||||
|
{'url': 'http://cool_url/volume/v2/test',
|
||||||
|
'interface': 'admin',
|
||||||
|
'region': 'RegionOne',
|
||||||
|
'region_id': 'RegionOne',
|
||||||
|
'id': '29a629afb80547ea9baa4266e97b4cb5'}],
|
||||||
|
'type': 'volumev2',
|
||||||
|
'id': '55ef272cfa714e54b8f2046c157b027d',
|
||||||
|
'name': 'cinderv2'},
|
||||||
|
{'endpoints': [
|
||||||
|
{'url': 'http://cool_url/compute/v2/check',
|
||||||
|
'interface': 'internal',
|
||||||
|
'region': 'RegionOne',
|
||||||
|
'region_id': 'RegionOne',
|
||||||
|
'id': 'e8c440e025d94355ab82c78cc2062129'}],
|
||||||
|
'type': 'compute_legacy',
|
||||||
|
'id': 'b7f1d3f4119643508d5ca2325eb8af87',
|
||||||
|
'name': 'nova_legacy'}]})
|
||||||
response = keystone.ServiceCatalog().get(request)
|
response = keystone.ServiceCatalog().get(request)
|
||||||
self.assertStatusCode(response, 200)
|
self.assertStatusCode(response, 200)
|
||||||
content = jsonutils.dumps(request.user.service_catalog,
|
content = [{'endpoints': [
|
||||||
sort_keys=settings.DEBUG)
|
{'url': 'http://cool_url/image',
|
||||||
if six.PY3:
|
'interface': 'public',
|
||||||
content = content.encode('utf-8')
|
'region': 'RegionOne',
|
||||||
self.assertEqual(content, response.content)
|
'region_id': 'RegionOne',
|
||||||
|
'id': 'test'}],
|
||||||
|
'type': 'image',
|
||||||
|
'id': '2b5bc2e59b094f898a43f5e8ce446240',
|
||||||
|
'name': 'glance'},
|
||||||
|
{'endpoints': [
|
||||||
|
{'url': 'http://cool_url/volume/v2/test',
|
||||||
|
'interface': 'public',
|
||||||
|
'region': 'RegionOne',
|
||||||
|
'region_id': 'RegionOne',
|
||||||
|
'id': '29a629afb80547ea9baa4266e97b4cb5'}],
|
||||||
|
'type': 'volumev2',
|
||||||
|
'id': '55ef272cfa714e54b8f2046c157b027d',
|
||||||
|
'name': 'cinderv2'}]
|
||||||
|
self.assertEqual(content, jsonutils.loads(response.content))
|
||||||
|
|
||||||
#
|
#
|
||||||
# User Session
|
# User Session
|
||||||
|
|
Loading…
Reference in New Issue