Exemple #1
0
def _get_endpoint_url(request, endpoint_type, catalog=None):
    if getattr(request.user, "service_catalog", None):
        return base.url_for(request,
                            service_type='identity',
                            endpoint_type=endpoint_type)
    return request.session.get('region_endpoint',
                               getattr(settings, 'OPENSTACK_KEYSTONE_URL'))
Exemple #2
0
    def test_url_for(self):
        url = api_base.url_for(self.request, 'image')
        self.assertEqual(url, 'http://public.glance.example.com:9292/v1')

        url = api_base.url_for(self.request, 'image', admin=False)
        self.assertEqual(url, 'http://public.glance.example.com:9292/v1')

        url = api_base.url_for(self.request, 'image', admin=True)
        self.assertEqual(url, 'http://admin.glance.example.com:9292/v1')

        url = api_base.url_for(self.request, 'compute')
        self.assertEqual(url, 'http://public.nova.example.com:8774/v2')

        url = api_base.url_for(self.request, 'compute', admin=False)
        self.assertEqual(url, 'http://public.nova.example.com:8774/v2')

        url = api_base.url_for(self.request, 'compute', admin=True)
        self.assertEqual(url, 'http://admin.nova.example.com:8774/v2')

        url = api_base.url_for(self.request, 'volume')
        self.assertEqual(url, 'http://public.nova.example.com:8776/v1')

        url = api_base.url_for(self.request,
                               'volume',
                               endpoint_type="internalURL")
        self.assertEqual(url, 'http://int.nova.example.com:8776/v1')

        url = api_base.url_for(self.request, 'volume', admin=False)
        self.assertEqual(url, 'http://public.nova.example.com:8776/v1')

        url = api_base.url_for(self.request, 'volume', admin=True)
        self.assertEqual(url, 'http://admin.nova.example.com:8776/v1')

        self.assertNotIn('notAnApi', self.request.user.service_catalog,
                         'Select a new nonexistent service catalog key')
        with self.assertRaises(exceptions.ServiceCatalogException):
            url = api_base.url_for(self.request, 'notAnApi')
    def test_url_for(self):
        url = api_base.url_for(self.request, 'image')
        self.assertEqual(url, 'http://public.glance.example.com:9292/v1')

        url = api_base.url_for(self.request, 'image', admin=False)
        self.assertEqual(url, 'http://public.glance.example.com:9292/v1')

        url = api_base.url_for(self.request, 'image', admin=True)
        self.assertEqual(url, 'http://admin.glance.example.com:9292/v1')

        url = api_base.url_for(self.request, 'compute')
        self.assertEqual(url, 'http://public.nova.example.com:8774/v2')

        url = api_base.url_for(self.request, 'compute', admin=False)
        self.assertEqual(url, 'http://public.nova.example.com:8774/v2')

        url = api_base.url_for(self.request, 'compute', admin=True)
        self.assertEqual(url, 'http://admin.nova.example.com:8774/v2')

        url = api_base.url_for(self.request, 'volume')
        self.assertEqual(url, 'http://public.nova.example.com:8776/v1')

        url = api_base.url_for(self.request, 'volume',
                               endpoint_type="internalURL")
        self.assertEqual(url, 'http://int.nova.example.com:8776/v1')

        url = api_base.url_for(self.request, 'volume', admin=False)
        self.assertEqual(url, 'http://public.nova.example.com:8776/v1')

        url = api_base.url_for(self.request, 'volume', admin=True)
        self.assertEqual(url, 'http://admin.nova.example.com:8776/v1')

        self.assertNotIn('notAnApi', self.request.user.service_catalog,
                         'Select a new nonexistent service catalog key')
        with self.assertRaises(exceptions.ServiceCatalogException):
            url = api_base.url_for(self.request, 'notAnApi')