Ejemplo n.º 1
0
    def test_delete_region_with_endpoint(self):
        # create a region
        region = unit.new_region_ref()
        self.catalog_api.create_region(region)

        # create a child region
        child_region = unit.new_region_ref(parent_region_id=region['id'])
        self.catalog_api.create_region(child_region)
        # create a service
        service = unit.new_service_ref()
        self.catalog_api.create_service(service['id'], service)

        # create an endpoint attached to the service and child region
        child_endpoint = unit.new_endpoint_ref(region_id=child_region['id'],
                                               service_id=service['id'])

        self.catalog_api.create_endpoint(child_endpoint['id'], child_endpoint)
        self.assertRaises(exception.RegionDeletionError,
                          self.catalog_api.delete_region,
                          child_region['id'])

        # create an endpoint attached to the service and parent region
        endpoint = unit.new_endpoint_ref(region_id=region['id'],
                                         service_id=service['id'])

        self.catalog_api.create_endpoint(endpoint['id'], endpoint)
        self.assertRaises(exception.RegionDeletionError,
                          self.catalog_api.delete_region,
                          region['id'])
Ejemplo n.º 2
0
    def test_v3_catalog_domain_scoped_token(self):
        # test the case that tenant_id is None.
        srv_1 = unit.new_service_ref()
        PROVIDERS.catalog_api.create_service(srv_1['id'], srv_1)
        endpoint_1 = unit.new_endpoint_ref(service_id=srv_1['id'],
                                           region_id=None)
        PROVIDERS.catalog_api.create_endpoint(endpoint_1['id'], endpoint_1)

        srv_2 = unit.new_service_ref()
        PROVIDERS.catalog_api.create_service(srv_2['id'], srv_2)
        endpoint_2 = unit.new_endpoint_ref(service_id=srv_2['id'],
                                           region_id=None)
        PROVIDERS.catalog_api.create_endpoint(endpoint_2['id'], endpoint_2)

        self.config_fixture.config(group='endpoint_filter',
                                   return_all_endpoints_if_no_filter=True)
        catalog_ref = PROVIDERS.catalog_api.get_v3_catalog(
            uuid.uuid4().hex, None
        )
        self.assertThat(catalog_ref, matchers.HasLength(2))
        self.config_fixture.config(group='endpoint_filter',
                                   return_all_endpoints_if_no_filter=False)
        catalog_ref = PROVIDERS.catalog_api.get_v3_catalog(
            uuid.uuid4().hex, None
        )
        self.assertThat(catalog_ref, matchers.HasLength(0))
Ejemplo n.º 3
0
    def test_delete_region_with_endpoint(self):
        # create a region
        region = {"id": uuid.uuid4().hex, "description": uuid.uuid4().hex}
        self.catalog_api.create_region(region)

        # create a child region
        child_region = {"id": uuid.uuid4().hex, "description": uuid.uuid4().hex, "parent_id": region["id"]}
        self.catalog_api.create_region(child_region)
        # create a service
        service = {
            "id": uuid.uuid4().hex,
            "type": uuid.uuid4().hex,
            "name": uuid.uuid4().hex,
            "description": uuid.uuid4().hex,
        }
        self.catalog_api.create_service(service["id"], service)

        # create an endpoint attached to the service and child region
        child_endpoint = unit.new_endpoint_ref(region_id=child_region["id"], service_id=service["id"])

        self.catalog_api.create_endpoint(child_endpoint["id"], child_endpoint)
        self.assertRaises(exception.RegionDeletionError, self.catalog_api.delete_region, child_region["id"])

        # create an endpoint attached to the service and parent region
        endpoint = unit.new_endpoint_ref(region_id=region["id"], service_id=service["id"])

        self.catalog_api.create_endpoint(endpoint["id"], endpoint)
        self.assertRaises(exception.RegionDeletionError, self.catalog_api.delete_region, region["id"])
Ejemplo n.º 4
0
    def test_v3_catalog_domain_scoped_token(self):
        # test the case that tenant_id is None.
        srv_1 = unit.new_service_ref()
        PROVIDERS.catalog_api.create_service(srv_1['id'], srv_1)
        endpoint_1 = unit.new_endpoint_ref(service_id=srv_1['id'],
                                           region_id=None)
        PROVIDERS.catalog_api.create_endpoint(endpoint_1['id'], endpoint_1)

        srv_2 = unit.new_service_ref()
        PROVIDERS.catalog_api.create_service(srv_2['id'], srv_2)
        endpoint_2 = unit.new_endpoint_ref(service_id=srv_2['id'],
                                           region_id=None)
        PROVIDERS.catalog_api.create_endpoint(endpoint_2['id'], endpoint_2)

        self.config_fixture.config(group='endpoint_filter',
                                   return_all_endpoints_if_no_filter=True)
        catalog_ref = PROVIDERS.catalog_api.get_v3_catalog(
            uuid.uuid4().hex, None
        )
        self.assertThat(catalog_ref, matchers.HasLength(2))
        self.config_fixture.config(group='endpoint_filter',
                                   return_all_endpoints_if_no_filter=False)
        catalog_ref = PROVIDERS.catalog_api.get_v3_catalog(
            uuid.uuid4().hex, None
        )
        self.assertThat(catalog_ref, matchers.HasLength(0))
Ejemplo n.º 5
0
    def test_cache_layer_delete_service_with_endpoint(self):
        service = unit.new_service_ref()
        PROVIDERS.catalog_api.create_service(service['id'], service)

        # create an endpoint attached to the service
        endpoint = unit.new_endpoint_ref(service_id=service['id'],
                                         region_id=None)
        PROVIDERS.catalog_api.create_endpoint(endpoint['id'], endpoint)
        # cache the result
        PROVIDERS.catalog_api.get_service(service['id'])
        PROVIDERS.catalog_api.get_endpoint(endpoint['id'])
        # delete the service bypassing catalog api
        PROVIDERS.catalog_api.driver.delete_service(service['id'])
        self.assertDictContainsSubset(endpoint,
                                      PROVIDERS.catalog_api.
                                      get_endpoint(endpoint['id']))
        self.assertDictContainsSubset(service,
                                      PROVIDERS.catalog_api.
                                      get_service(service['id']))
        PROVIDERS.catalog_api.get_endpoint.invalidate(
            PROVIDERS.catalog_api, endpoint['id']
        )
        self.assertRaises(exception.EndpointNotFound,
                          PROVIDERS.catalog_api.get_endpoint,
                          endpoint['id'])
        self.assertRaises(exception.EndpointNotFound,
                          PROVIDERS.catalog_api.delete_endpoint,
                          endpoint['id'])
        # multiple endpoints associated with a service
        second_endpoint = unit.new_endpoint_ref(service_id=service['id'],
                                                region_id=None)
        PROVIDERS.catalog_api.create_service(service['id'], service)
        PROVIDERS.catalog_api.create_endpoint(endpoint['id'], endpoint)
        PROVIDERS.catalog_api.create_endpoint(
            second_endpoint['id'], second_endpoint
        )
        PROVIDERS.catalog_api.delete_service(service['id'])
        self.assertRaises(exception.EndpointNotFound,
                          PROVIDERS.catalog_api.get_endpoint,
                          endpoint['id'])
        self.assertRaises(exception.EndpointNotFound,
                          PROVIDERS.catalog_api.delete_endpoint,
                          endpoint['id'])
        self.assertRaises(exception.EndpointNotFound,
                          PROVIDERS.catalog_api.get_endpoint,
                          second_endpoint['id'])
        self.assertRaises(exception.EndpointNotFound,
                          PROVIDERS.catalog_api.delete_endpoint,
                          second_endpoint['id'])
Ejemplo n.º 6
0
 def new_endpoint(region_id, service_id):
     endpoint = unit.new_endpoint_ref(interface='test',
                                      region_id=region_id,
                                      service_id=service_id,
                                      url='/url')
     self.endpoint.append(
         self.catalog_api.create_endpoint(endpoint['id'], endpoint))
Ejemplo n.º 7
0
    def test_endpoint_create_with_valid_url(self):
        """Create endpoint with valid url should be tested,too."""
        # list one valid url is enough, no need to list too much
        valid_url = "http://127.0.0.1:8774/v1.1/$(tenant_id)s"

        ref = unit.new_endpoint_ref(self.service_id, interface="public", region_id=self.region_id, url=valid_url)
        self.post("/endpoints", body={"endpoint": ref})
Ejemplo n.º 8
0
 def test_update_endpoint(self):
     """Call ``PATCH /endpoints/{endpoint_id}``."""
     ref = unit.new_endpoint_ref(service_id=self.service_id, interface="public", region_id=self.region_id)
     del ref["id"]
     r = self.patch("/endpoints/%(endpoint_id)s" % {"endpoint_id": self.endpoint_id}, body={"endpoint": ref})
     ref["enabled"] = True
     self.assertValidEndpointResponse(r, ref)
Ejemplo n.º 9
0
 def test_create_endpoint_enabled_false(self):
     """Call ``POST /endpoints`` with enabled: false."""
     ref = unit.new_endpoint_ref(
         service_id=self.service_id, interface="public", region_id=self.region_id, enabled=False
     )
     r = self.post("/endpoints", body={"endpoint": ref})
     self.assertValidEndpointResponse(r, ref)
Ejemplo n.º 10
0
    def test_pure_v3_endpoint_without_publicurl_invisible_from_v2(self):
        """Test pure v3 endpoint without public url can't be fetched via v2 API.

        V2 API will return endpoints created by v3 API, but because public url
        is required for v2 API, so v3 endpoints without public url will be
        ignored.
        """
        region_id = self._region_create()
        service_id = self._service_create()
        # create a v3 endpoint without public interface
        body = {
            'endpoint':
            unit.new_endpoint_ref(service_id, default_region_id=region_id)
        }
        for interface in catalog.controllers.INTERFACES:
            if interface == 'public':
                continue
            body['endpoint']['interface'] = interface
            self.admin_request(method='POST',
                               token=self.get_scoped_token(),
                               path='/v3/endpoints',
                               expected_status=http_client.CREATED,
                               body=body)

        r = self.admin_request(token=self.get_scoped_token(),
                               path='/v2.0/endpoints')
        # v3 endpoints without public url won't be fetched via v2.0 API
        self.assertEqual(0, len(r.result['endpoints']))
Ejemplo n.º 11
0
    def test_create_endpoint(self):
        service = unit.new_service_ref()
        self.catalog_api.create_service(service['id'], service)

        endpoint = unit.new_endpoint_ref(service_id=service['id'],
                                         region_id=None)
        self.catalog_api.create_endpoint(endpoint['id'], endpoint.copy())
Ejemplo n.º 12
0
    def test_pure_v3_endpoint_without_publicurl_invisible_from_v2(self):
        """Test pure v3 endpoint without public url can't be fetched via v2 API.

        V2 API will return endpoints created by v3 API, but because public url
        is required for v2 API, so v3 endpoints without public url will be
        ignored.
        """
        region_id = self._region_create()
        service_id = self._service_create()
        # create a v3 endpoint without public interface
        body = {
            'endpoint': unit.new_endpoint_ref(service_id, region_id=region_id)
        }
        for interface in catalog.controllers.INTERFACES:
            if interface == 'public':
                continue
            body['endpoint']['interface'] = interface
            self.admin_request(method='POST',
                               token=self.get_scoped_token(),
                               path='/v3/endpoints',
                               expected_status=http_client.CREATED,
                               body=body)

        r = self.admin_request(token=self.get_scoped_token(),
                               path='/v2.0/endpoints')
        # v3 endpoints without public url won't be fetched via v2.0 API
        self.assertEqual(0, len(r.result['endpoints']))
Ejemplo n.º 13
0
 def test_update_endpoint_nonexistent_region(self):
     dummy_service, enabled_endpoint, dummy_disabled_endpoint = (
         self._create_endpoints())
     new_endpoint = unit.new_endpoint_ref(service_id=uuid.uuid4().hex)
     self.assertRaises(exception.ValidationError,
                       self.catalog_api.update_endpoint,
                       enabled_endpoint['id'], new_endpoint)
Ejemplo n.º 14
0
    def create_endpoint(self, service_id, **kwargs):
        endpoint = unit.new_endpoint_ref(service_id=service_id,
                                         region_id=None,
                                         **kwargs)

        self.catalog_api.create_endpoint(endpoint['id'], endpoint)
        return endpoint
 def new_endpoint(region_id, service_id):
     endpoint = unit.new_endpoint_ref(interface='test',
                                      region_id=region_id,
                                      service_id=service_id,
                                      url='/url')
     self.endpoint.append(PROVIDERS.catalog_api.create_endpoint(
         endpoint['id'], endpoint))
Ejemplo n.º 16
0
 def test_create_endpoint_nonexistent_service(self):
     endpoint = unit.new_endpoint_ref(service_id=uuid.uuid4().hex,
                                      region_id=None)
     self.assertRaises(exception.ValidationError,
                       self.catalog_api.create_endpoint,
                       endpoint['id'],
                       endpoint)
Ejemplo n.º 17
0
 def test_create_endpoint_no_enabled(self):
     """Call ``POST /endpoints``."""
     ref = unit.new_endpoint_ref(service_id=self.service_id,
                                 interface='public',
                                 region_id=self.region_id)
     r = self.post('/endpoints', body={'endpoint': ref})
     ref['enabled'] = True
     self.assertValidEndpointResponse(r, ref)
Ejemplo n.º 18
0
    def test_create_endpoint_nonexistent_region(self):
        service = unit.new_service_ref()
        self.catalog_api.create_service(service['id'], service)

        endpoint = unit.new_endpoint_ref(service_id=service['id'])
        self.assertRaises(exception.ValidationError,
                          self.catalog_api.create_endpoint, endpoint['id'],
                          endpoint)
Ejemplo n.º 19
0
 def test_create_endpoint_enabled_str_random(self):
     """Call ``POST /endpoints`` with enabled: 'puppies'."""
     ref = unit.new_endpoint_ref(service_id=self.service_id,
                                 interface='public',
                                 region_id=self.region_id,
                                 enabled='puppies')
     self.post('/endpoints', body={'endpoint': ref},
               expected_status=http_client.BAD_REQUEST)
Ejemplo n.º 20
0
 def test_create_endpoint_enabled_true(self):
     """Call ``POST /endpoints`` with enabled: true."""
     ref = unit.new_endpoint_ref(service_id=self.service_id,
                                 interface='public',
                                 region_id=self.region_id,
                                 enabled=True)
     r = self.post('/endpoints', body={'endpoint': ref})
     self.assertValidEndpointResponse(r, ref)
Ejemplo n.º 21
0
 def test_create_endpoint_no_enabled(self):
     """Call ``POST /endpoints``."""
     ref = unit.new_endpoint_ref(service_id=self.service_id,
                                 interface='public',
                                 region_id=self.region_id)
     r = self.post('/endpoints', body={'endpoint': ref})
     ref['enabled'] = True
     self.assertValidEndpointResponse(r, ref)
Ejemplo n.º 22
0
 def test_update_endpoint_nonexistent_region(self):
     dummy_service, enabled_endpoint, dummy_disabled_endpoint = (
         self._create_endpoints())
     new_endpoint = unit.new_endpoint_ref(service_id=uuid.uuid4().hex)
     self.assertRaises(exception.ValidationError,
                       self.catalog_api.update_endpoint,
                       enabled_endpoint['id'],
                       new_endpoint)
Ejemplo n.º 23
0
 def test_create_endpoint_enabled_false(self):
     """Call ``POST /endpoints`` with enabled: false."""
     ref = unit.new_endpoint_ref(service_id=self.service_id,
                                 interface='public',
                                 region_id=self.region_id,
                                 enabled=False)
     r = self.post('/endpoints', body={'endpoint': ref})
     self.assertValidEndpointResponse(r, ref)
Ejemplo n.º 24
0
    def _create_random_endpoint(self, interface="public", parent_region_id=None):
        region = self._create_region_with_parent_id(parent_id=parent_region_id)
        service = self._create_random_service()
        ref = unit.new_endpoint_ref(
            service_id=service["id"], interface=interface, region_id=region.result["region"]["id"]
        )

        response = self.post("/endpoints", body={"endpoint": ref})
        return response.json["endpoint"]
Ejemplo n.º 25
0
    def test_endpoint_create_with_valid_url_project_id(self):
        """Create endpoint with valid url should be tested,too."""
        valid_url = 'http://127.0.0.1:8774/v1.1/$(project_id)s'

        ref = unit.new_endpoint_ref(self.service_id,
                                    interface='public',
                                    region_id=self.region_id,
                                    url=valid_url)
        self.post('/endpoints', body={'endpoint': ref})
Ejemplo n.º 26
0
    def test_user_can_get_an_endpoint(self):
        service = PROVIDERS.catalog_api.create_service(uuid.uuid4().hex,
                                                       unit.new_service_ref())
        endpoint = unit.new_endpoint_ref(service['id'], region_id=None)
        endpoint = PROVIDERS.catalog_api.create_endpoint(
            endpoint['id'], endpoint)

        with self.test_client() as c:
            c.get('/v3/endpoints/%s' % endpoint['id'], headers=self.headers)
Ejemplo n.º 27
0
    def test_create_endpoint_nonexistent_region(self):
        service = unit.new_service_ref()
        self.catalog_api.create_service(service['id'], service)

        endpoint = unit.new_endpoint_ref(service_id=service['id'])
        self.assertRaises(exception.ValidationError,
                          self.catalog_api.create_endpoint,
                          endpoint['id'],
                          endpoint)
Ejemplo n.º 28
0
        def create_endpoint(service_id, region, **kwargs):
            ref = unit.new_endpoint_ref(
                service_id=service_id,
                region_id=region,
                url='http://localhost/%s' % uuid.uuid4().hex,
                **kwargs)

            self.catalog_api.create_endpoint(ref['id'], ref)
            return ref
Ejemplo n.º 29
0
    def test_create_endpoint_region_returns_not_found(self):
        service = unit.new_service_ref()
        self.catalog_api.create_service(service['id'], service)

        endpoint = unit.new_endpoint_ref(region_id=uuid.uuid4().hex,
                                         service_id=service['id'])

        self.assertRaises(exception.ValidationError,
                          self.catalog_api.create_endpoint, endpoint['id'],
                          endpoint.copy())
Ejemplo n.º 30
0
    def test_endpoint_create_with_valid_url(self):
        """Create endpoint with valid url should be tested,too."""
        # list one valid url is enough, no need to list too much
        valid_url = 'http://127.0.0.1:8774/v1.1/$(tenant_id)s'

        ref = unit.new_endpoint_ref(self.service_id,
                                    interface='public',
                                    region_id=self.region_id,
                                    url=valid_url)
        self.post('/endpoints', body={'endpoint': ref})
Ejemplo n.º 31
0
    def load_sample_data(self):
        self._populate_default_domain()
        self.domain = unit.new_domain_ref()
        self.domain_id = self.domain['id']
        self.resource_api.create_domain(self.domain_id, self.domain)

        self.project = unit.new_project_ref(domain_id=self.domain_id)
        self.project_id = self.project['id']
        self.resource_api.create_project(self.project_id, self.project)

        self.user = unit.create_user(self.identity_api,
                                     domain_id=self.domain_id)
        self.user_id = self.user['id']

        self.default_domain_project_id = uuid.uuid4().hex
        self.default_domain_project = unit.new_project_ref(
            domain_id=DEFAULT_DOMAIN_ID)
        self.default_domain_project['id'] = self.default_domain_project_id
        self.resource_api.create_project(self.default_domain_project_id,
                                         self.default_domain_project)

        self.default_domain_user = unit.create_user(
            self.identity_api,
            domain_id=DEFAULT_DOMAIN_ID)
        self.default_domain_user_id = self.default_domain_user['id']

        # create & grant policy.json's default role for admin_required
        self.role = unit.new_role_ref(name='admin')
        self.role_id = self.role['id']
        self.role_api.create_role(self.role_id, self.role)
        self.assignment_api.add_role_to_user_and_project(
            self.user_id, self.project_id, self.role_id)
        self.assignment_api.add_role_to_user_and_project(
            self.default_domain_user_id, self.default_domain_project_id,
            self.role_id)
        self.assignment_api.add_role_to_user_and_project(
            self.default_domain_user_id, self.project_id,
            self.role_id)

        self.region = unit.new_region_ref()
        self.region_id = self.region['id']
        self.catalog_api.create_region(self.region)

        self.service = unit.new_service_ref()
        self.service_id = self.service['id']
        self.catalog_api.create_service(self.service_id, self.service.copy())

        self.endpoint = unit.new_endpoint_ref(service_id=self.service_id,
                                              interface='public',
                                              region_id=self.region_id)
        self.endpoint_id = self.endpoint['id']
        self.catalog_api.create_endpoint(self.endpoint_id,
                                         self.endpoint.copy())
        # The server adds 'enabled' and defaults to True.
        self.endpoint['enabled'] = True
Ejemplo n.º 32
0
    def test_create_endpoint_region_returns_not_found(self):
        service = unit.new_service_ref()
        self.catalog_api.create_service(service['id'], service)

        endpoint = unit.new_endpoint_ref(region_id=uuid.uuid4().hex,
                                         service_id=service['id'])

        self.assertRaises(exception.ValidationError,
                          self.catalog_api.create_endpoint,
                          endpoint['id'],
                          endpoint.copy())
Ejemplo n.º 33
0
    def test_user_cannot_delete_endpoints(self):
        service = PROVIDERS.catalog_api.create_service(uuid.uuid4().hex,
                                                       unit.new_service_ref())
        endpoint = unit.new_endpoint_ref(service['id'], region_id=None)
        endpoint = PROVIDERS.catalog_api.create_endpoint(
            endpoint['id'], endpoint)

        with self.test_client() as c:
            c.delete('/v3/endpoints/%s' % endpoint['id'],
                     headers=self.headers,
                     expected_status_code=http_client.FORBIDDEN)
Ejemplo n.º 34
0
    def test_user_can_get_an_endpoint(self):
        service = PROVIDERS.catalog_api.create_service(
            uuid.uuid4().hex, unit.new_service_ref()
        )
        endpoint = unit.new_endpoint_ref(service['id'], region_id=None)
        endpoint = PROVIDERS.catalog_api.create_endpoint(
            endpoint['id'], endpoint
        )

        with self.test_client() as c:
            c.get('/v3/endpoints/%s' % endpoint['id'], headers=self.headers)
Ejemplo n.º 35
0
    def test_v3_catalog_endpoint_filter_enabled(self):
        srv_1 = unit.new_service_ref()
        self.catalog_api.create_service(srv_1['id'], srv_1)
        endpoint_1 = unit.new_endpoint_ref(service_id=srv_1['id'],
                                           region_id=None)
        self.catalog_api.create_endpoint(endpoint_1['id'], endpoint_1)
        endpoint_2 = unit.new_endpoint_ref(service_id=srv_1['id'],
                                           region_id=None)
        self.catalog_api.create_endpoint(endpoint_2['id'], endpoint_2)
        # create endpoint-project association.
        self.catalog_api.add_endpoint_to_project(endpoint_1['id'],
                                                 self.tenant_bar['id'])

        catalog_ref = self.catalog_api.get_v3_catalog(uuid.uuid4().hex,
                                                      self.tenant_bar['id'])
        self.assertThat(catalog_ref, matchers.HasLength(1))
        self.assertThat(catalog_ref[0]['endpoints'], matchers.HasLength(1))
        # the endpoint is that defined in the endpoint-project association.
        self.assertEqual(endpoint_1['id'],
                         catalog_ref[0]['endpoints'][0]['id'])
Ejemplo n.º 36
0
    def _create_random_endpoint(self,
                                interface='public',
                                parent_region_id=None):
        region = self._create_region_with_parent_id(parent_id=parent_region_id)
        service = self._create_random_service()
        ref = unit.new_endpoint_ref(service_id=service['id'],
                                    interface=interface,
                                    region_id=region.result['region']['id'])

        response = self.post('/endpoints', body={'endpoint': ref})
        return response.json['endpoint']
Ejemplo n.º 37
0
 def test_update_endpoint(self):
     """Call ``PATCH /endpoints/{endpoint_id}``."""
     ref = unit.new_endpoint_ref(service_id=self.service_id,
                                 interface='public',
                                 region_id=self.region_id)
     del ref['id']
     r = self.patch('/endpoints/%(endpoint_id)s' %
                    {'endpoint_id': self.endpoint_id},
                    body={'endpoint': ref})
     ref['enabled'] = True
     self.assertValidEndpointResponse(r, ref)
 def setUp(self):
     super(EndpointPolicyTestCase, self).setUp()
     self.policy = unit.new_policy_ref()
     self.policy_api.create_policy(self.policy['id'], self.policy)
     self.service = unit.new_service_ref()
     self.catalog_api.create_service(self.service['id'], self.service)
     self.endpoint = unit.new_endpoint_ref(self.service['id'], enabled=True,
                                           interface='public',
                                           region_id=self.region_id)
     self.catalog_api.create_endpoint(self.endpoint['id'], self.endpoint)
     self.region = unit.new_region_ref()
     self.catalog_api.create_region(self.region)
 def setUp(self):
     super(EndpointPolicyTestCase, self).setUp()
     self.policy = unit.new_policy_ref()
     self.policy_api.create_policy(self.policy['id'], self.policy)
     self.service = unit.new_service_ref()
     self.catalog_api.create_service(self.service['id'], self.service)
     self.endpoint = unit.new_endpoint_ref(self.service['id'], enabled=True,
                                           interface='public',
                                           region_id=self.region_id)
     self.catalog_api.create_endpoint(self.endpoint['id'], self.endpoint)
     self.region = unit.new_region_ref()
     self.catalog_api.create_region(self.region)
Ejemplo n.º 40
0
    def test_v3_catalog_endpoint_filter_enabled(self):
        srv_1 = unit.new_service_ref()
        self.catalog_api.create_service(srv_1['id'], srv_1)
        endpoint_1 = unit.new_endpoint_ref(service_id=srv_1['id'],
                                           region_id=None)
        self.catalog_api.create_endpoint(endpoint_1['id'], endpoint_1)
        endpoint_2 = unit.new_endpoint_ref(service_id=srv_1['id'],
                                           region_id=None)
        self.catalog_api.create_endpoint(endpoint_2['id'], endpoint_2)
        # create endpoint-project association.
        self.catalog_api.add_endpoint_to_project(
            endpoint_1['id'],
            self.tenant_bar['id'])

        catalog_ref = self.catalog_api.get_v3_catalog(uuid.uuid4().hex,
                                                      self.tenant_bar['id'])
        self.assertThat(catalog_ref, matchers.HasLength(1))
        self.assertThat(catalog_ref[0]['endpoints'], matchers.HasLength(1))
        # the endpoint is that defined in the endpoint-project association.
        self.assertEqual(endpoint_1['id'],
                         catalog_ref[0]['endpoints'][0]['id'])
Ejemplo n.º 41
0
 def test_update_endpoint(self):
     """Call ``PATCH /endpoints/{endpoint_id}``."""
     ref = unit.new_endpoint_ref(service_id=self.service_id,
                                 interface='public',
                                 region_id=self.region_id)
     del ref['id']
     r = self.patch(
         '/endpoints/%(endpoint_id)s' % {
             'endpoint_id': self.endpoint_id},
         body={'endpoint': ref})
     ref['enabled'] = True
     self.assertValidEndpointResponse(r, ref)
Ejemplo n.º 42
0
    def test_create_endpoint_region_returns_not_found(self):
        service = {
            "id": uuid.uuid4().hex,
            "type": uuid.uuid4().hex,
            "name": uuid.uuid4().hex,
            "description": uuid.uuid4().hex,
        }
        self.catalog_api.create_service(service["id"], service.copy())

        endpoint = unit.new_endpoint_ref(region_id=uuid.uuid4().hex, service_id=service["id"])

        self.assertRaises(exception.ValidationError, self.catalog_api.create_endpoint, endpoint["id"], endpoint.copy())
Ejemplo n.º 43
0
    def test_list_endpoints(self):
        service = unit.new_service_ref()
        self.catalog_api.create_service(service['id'], service)

        expected_ids = set([uuid.uuid4().hex for _ in range(3)])
        for endpoint_id in expected_ids:
            endpoint = unit.new_endpoint_ref(service_id=service['id'],
                                             id=endpoint_id,
                                             region_id=None)
            self.catalog_api.create_endpoint(endpoint['id'], endpoint)

        endpoints = self.catalog_api.list_endpoints()
        self.assertEqual(expected_ids, set(e['id'] for e in endpoints))
Ejemplo n.º 44
0
    def test_catalog_ignored_malformed_urls(self):
        service = unit.new_service_ref()
        self.catalog_api.create_service(service['id'], service)

        malformed_url = "http://192.168.1.104:8774/v2/$(tenant)s"
        endpoint = unit.new_endpoint_ref(service_id=service['id'],
                                         url=malformed_url,
                                         region_id=None)
        self.catalog_api.create_endpoint(endpoint['id'], endpoint.copy())

        # NOTE(dstanek): there are no valid URLs, so nothing is in the catalog
        catalog = self.catalog_api.get_catalog('fake-user', 'fake-tenant')
        self.assertEqual({}, catalog)
Ejemplo n.º 45
0
    def test_user_can_update_endpoints(self):
        service = PROVIDERS.catalog_api.create_service(uuid.uuid4().hex,
                                                       unit.new_service_ref())
        endpoint = unit.new_endpoint_ref(service['id'], region_id=None)
        endpoint = PROVIDERS.catalog_api.create_endpoint(
            endpoint['id'], endpoint)

        update = {'endpoint': {'interface': 'internal'}}

        with self.test_client() as c:
            c.patch('/v3/endpoints/%s' % endpoint['id'],
                    json=update,
                    headers=self.headers)
Ejemplo n.º 46
0
    def test_user_cannot_delete_endpoints(self):
        service = PROVIDERS.catalog_api.create_service(
            uuid.uuid4().hex, unit.new_service_ref()
        )
        endpoint = unit.new_endpoint_ref(service['id'], region_id=None)
        endpoint = PROVIDERS.catalog_api.create_endpoint(
            endpoint['id'], endpoint
        )

        with self.test_client() as c:
            c.delete(
                '/v3/endpoints/%s' % endpoint['id'], headers=self.headers,
                expected_status_code=http_client.FORBIDDEN
            )
Ejemplo n.º 47
0
    def test_user_can_delete_policy_association_for_endpoint(self):
        policy = unit.new_policy_ref()
        policy = PROVIDERS.policy_api.create_policy(policy['id'], policy)
        service = PROVIDERS.catalog_api.create_service(uuid.uuid4().hex,
                                                       unit.new_service_ref())
        endpoint = unit.new_endpoint_ref(service['id'], region_id=None)
        endpoint = PROVIDERS.catalog_api.create_endpoint(
            endpoint['id'], endpoint)

        with self.test_client() as c:
            c.delete('/v3/policies/%s/OS-ENDPOINT-POLICY/endpoints/%s' %
                     (policy['id'], endpoint['id']),
                     headers=self.headers,
                     expected_status_code=http_client.NO_CONTENT)
Ejemplo n.º 48
0
 def test_user_can_get_policy_for_endpoint(self):
     policy = unit.new_policy_ref()
     policy = PROVIDERS.policy_api.create_policy(policy['id'], policy)
     service = PROVIDERS.catalog_api.create_service(uuid.uuid4().hex,
                                                    unit.new_service_ref())
     endpoint = unit.new_endpoint_ref(service['id'], region_id=None)
     endpoint = PROVIDERS.catalog_api.create_endpoint(
         endpoint['id'], endpoint)
     PROVIDERS.endpoint_policy_api.create_policy_association(
         policy['id'], endpoint['id'])
     with self.test_client() as c:
         c.get('/v3/endpoints/%s/OS-ENDPOINT-POLICY/policy' %
               (endpoint['id']),
               headers=self.headers)
Ejemplo n.º 49
0
    def _create_random_endpoint(self, interface='public',
                                parent_region_id=None):
        region = self._create_region_with_parent_id(
            parent_id=parent_region_id)
        service = self._create_random_service()
        ref = unit.new_endpoint_ref(
            service_id=service['id'],
            interface=interface,
            region_id=region.result['region']['id'])

        response = self.post(
            '/endpoints',
            body={'endpoint': ref})
        return response.json['endpoint']
Ejemplo n.º 50
0
    def test_user_cannot_list_endpoints(self):
        # Domain and project users should access this information through the
        # token response they get when they authenticate for or validate a
        # token.
        service = PROVIDERS.catalog_api.create_service(uuid.uuid4().hex,
                                                       unit.new_service_ref())
        endpoint = unit.new_endpoint_ref(service['id'], region_id=None)
        endpoint = PROVIDERS.catalog_api.create_endpoint(
            endpoint['id'], endpoint)

        with self.test_client() as c:
            c.get('/v3/endpoints',
                  headers=self.headers,
                  expected_status_code=http.client.FORBIDDEN)
Ejemplo n.º 51
0
    def test_get_catalog_with_empty_public_url(self):
        service = unit.new_service_ref()
        self.catalog_api.create_service(service['id'], service)

        endpoint = unit.new_endpoint_ref(url='', service_id=service['id'],
                                         region_id=None)
        self.catalog_api.create_endpoint(endpoint['id'], endpoint.copy())

        catalog = self.catalog_api.get_catalog('user', 'tenant')
        catalog_endpoint = catalog[endpoint['region_id']][service['type']]
        self.assertEqual(service['name'], catalog_endpoint['name'])
        self.assertEqual(endpoint['id'], catalog_endpoint['id'])
        self.assertEqual('', catalog_endpoint['publicURL'])
        self.assertIsNone(catalog_endpoint.get('adminURL'))
        self.assertIsNone(catalog_endpoint.get('internalURL'))