v3 endpoint create should require url

The url parameter of endpoint object is not nullable in db, but we
do not have a null check in api. So, when create a endpoint if I
do not specify url parameter I will get a 500 reponse.
This patch will add an attribute require check to url parameter.

Change-Id: I9c8aa3bcb99ea5cb5e4e4d3306d8d222c6f074d1
Closes-Bug: #1284422
This commit is contained in:
wanghong 2014-02-26 09:21:14 +08:00
parent c32fe003e7
commit aabf0b525e
2 changed files with 7 additions and 0 deletions

View File

@ -242,6 +242,7 @@ class EndpointV3(controller.V3Controller):
ref = self._assign_unique_id(self._normalize_dict(endpoint))
self._require_attribute(ref, 'service_id')
self._require_attribute(ref, 'interface')
self._require_attribute(ref, 'url')
self.catalog_api.get_service(ref['service_id'])
ref = self.catalog_api.create_endpoint(ref['id'], ref)

View File

@ -140,6 +140,12 @@ class CatalogTestCase(test_v3.RestfulTestCase):
ref["region"] = "0" * 256
self.post('/endpoints', body={'endpoint': ref}, expected_status=400)
def test_create_endpoint_with_empty_url(self):
"""Call ``POST /endpoints``."""
ref = self.new_endpoint_ref(service_id=self.service_id)
del ref["url"]
self.post('/endpoints', body={'endpoint': ref}, expected_status=400)
def test_get_endpoint(self):
"""Call ``GET /endpoints/{endpoint_id}``."""
r = self.get(