Browse Source

Merge "Refactor app response for api request '/api/keystone/svc-catalog'"

Zuul 6 months ago
parent
commit
11fe92baf0

+ 10
- 1
openstack_dashboard/api/rest/keystone.py View File

@@ -13,6 +13,8 @@
13 13
 # limitations under the License.
14 14
 """API over the keystone service."""
15 15
 
16
+import copy
17
+
16 18
 from django.conf import settings
17 19
 import django.http
18 20
 from django.views import generic
@@ -542,7 +544,14 @@ class ServiceCatalog(generic.View):
542 544
     @rest_utils.ajax()
543 545
     def get(self, request):
544 546
         """Return the service catalog associated with the current user."""
545
-        return request.user.service_catalog
547
+        catalog = copy.deepcopy(request.user.service_catalog)
548
+        for record in catalog:
549
+            for endpoint in record['endpoints']:
550
+                if endpoint['interface'] != 'public':
551
+                    record['endpoints'].remove(endpoint)
552
+            if not record['endpoints']:
553
+                catalog.remove(record)
554
+        return catalog
546 555
 
547 556
 
548 557
 @urls.register

+ 62
- 6
openstack_dashboard/test/unit/api/rest/test_keystone.py View File

@@ -15,7 +15,6 @@
15 15
 from django.conf import settings
16 16
 import mock
17 17
 from oslo_serialization import jsonutils
18
-import six
19 18
 
20 19
 from openstack_dashboard import api
21 20
 from openstack_dashboard.api.rest import keystone
@@ -688,13 +687,70 @@ class KeystoneRestTestCase(test.TestCase):
688 687
     #
689 688
     def test_service_catalog_get(self):
690 689
         request = self.mock_rest_request()
690
+        request.user = mock.MagicMock(**{'service_catalog': [
691
+                {'endpoints': [
692
+                    {'url': 'http://cool_url/image',
693
+                     'interface': 'admin',
694
+                     'region': 'RegionOne',
695
+                     'region_id': 'RegionOne',
696
+                     'id': 'test'},
697
+                    {'url': 'http://cool_url/image',
698
+                     'interface': 'public',
699
+                     'region': 'RegionOne',
700
+                     'region_id': 'RegionOne',
701
+                     'id': 'test'},
702
+                    {'url': 'http://cool_url/image',
703
+                     'interface': 'internal',
704
+                     'region': 'RegionOne',
705
+                     'region_id': 'RegionOne',
706
+                     'id': 'test'}],
707
+                    'type': 'image',
708
+                    'id': '2b5bc2e59b094f898a43f5e8ce446240',
709
+                    'name': 'glance'},
710
+                {'endpoints': [
711
+                    {'url': 'http://cool_url/volume/v2/test',
712
+                     'interface': 'public',
713
+                     'region': 'RegionOne',
714
+                     'region_id': 'RegionOne',
715
+                     'id': '29a629afb80547ea9baa4266e97b4cb5'},
716
+                    {'url': 'http://cool_url/volume/v2/test',
717
+                     'interface': 'admin',
718
+                     'region': 'RegionOne',
719
+                     'region_id': 'RegionOne',
720
+                     'id': '29a629afb80547ea9baa4266e97b4cb5'}],
721
+                    'type': 'volumev2',
722
+                    'id': '55ef272cfa714e54b8f2046c157b027d',
723
+                    'name': 'cinderv2'},
724
+                {'endpoints': [
725
+                    {'url': 'http://cool_url/compute/v2/check',
726
+                     'interface': 'internal',
727
+                     'region': 'RegionOne',
728
+                     'region_id': 'RegionOne',
729
+                     'id': 'e8c440e025d94355ab82c78cc2062129'}],
730
+                    'type': 'compute_legacy',
731
+                    'id': 'b7f1d3f4119643508d5ca2325eb8af87',
732
+                    'name': 'nova_legacy'}]})
691 733
         response = keystone.ServiceCatalog().get(request)
692 734
         self.assertStatusCode(response, 200)
693
-        content = jsonutils.dumps(request.user.service_catalog,
694
-                                  sort_keys=settings.DEBUG)
695
-        if six.PY3:
696
-            content = content.encode('utf-8')
697
-        self.assertEqual(content, response.content)
735
+        content = [{'endpoints': [
736
+                    {'url': 'http://cool_url/image',
737
+                     'interface': 'public',
738
+                     'region': 'RegionOne',
739
+                     'region_id': 'RegionOne',
740
+                     'id': 'test'}],
741
+                    'type': 'image',
742
+                    'id': '2b5bc2e59b094f898a43f5e8ce446240',
743
+                    'name': 'glance'},
744
+                   {'endpoints': [
745
+                    {'url': 'http://cool_url/volume/v2/test',
746
+                     'interface': 'public',
747
+                     'region': 'RegionOne',
748
+                     'region_id': 'RegionOne',
749
+                     'id': '29a629afb80547ea9baa4266e97b4cb5'}],
750
+                    'type': 'volumev2',
751
+                    'id': '55ef272cfa714e54b8f2046c157b027d',
752
+                    'name': 'cinderv2'}]
753
+        self.assertEqual(content, jsonutils.loads(response.content))
698 754
 
699 755
     #
700 756
     # User Session

Loading…
Cancel
Save