Add a response header validation
Nova API sometimes returns important information in a response header, and Tempest needs to check it for keeping the backward compatibility. This patch adds the check for "create a server snapshot" API as the sample. Partially implements blueprint nova-api-attribute-test Change-Id: I2441147ee050e7b818906aaa754dcec4480d8c18
This commit is contained in:
parent
62ca1013fc
commit
57b384b4d4
|
@ -92,7 +92,17 @@ list_images = {
|
|||
}
|
||||
|
||||
create_image = {
|
||||
'status_code': [202]
|
||||
'status_code': [202],
|
||||
'response_header': {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'location': {
|
||||
'type': 'string',
|
||||
'format': 'uri'
|
||||
}
|
||||
},
|
||||
'required': ['location']
|
||||
}
|
||||
}
|
||||
|
||||
delete = {
|
||||
|
|
|
@ -593,10 +593,12 @@ class RestClient(object):
|
|||
msg = ("The status code(%s) is different than the expected "
|
||||
"one(%s)") % (resp.status, response_code)
|
||||
raise exceptions.InvalidHttpSuccessCode(msg)
|
||||
response_schema = schema.get('response_body')
|
||||
if response_schema:
|
||||
|
||||
# Check the body of a response
|
||||
body_schema = schema.get('response_body')
|
||||
if body_schema:
|
||||
try:
|
||||
jsonschema.validate(body, response_schema)
|
||||
jsonschema.validate(body, body_schema)
|
||||
except jsonschema.ValidationError as ex:
|
||||
msg = ("HTTP response body is invalid (%s)") % ex
|
||||
raise exceptions.InvalidHTTPResponseBody(msg)
|
||||
|
@ -605,6 +607,15 @@ class RestClient(object):
|
|||
msg = ("HTTP response body should not exist (%s)") % body
|
||||
raise exceptions.InvalidHTTPResponseBody(msg)
|
||||
|
||||
# Check the header of a response
|
||||
header_schema = schema.get('response_header')
|
||||
if header_schema:
|
||||
try:
|
||||
jsonschema.validate(resp, header_schema)
|
||||
except jsonschema.ValidationError as ex:
|
||||
msg = ("HTTP response header is invalid (%s)") % ex
|
||||
raise exceptions.InvalidHTTPResponseHeader(msg)
|
||||
|
||||
|
||||
class NegativeRestClient(RestClient):
|
||||
"""
|
||||
|
|
|
@ -197,6 +197,10 @@ class InvalidHTTPResponseBody(RestClientException):
|
|||
message = "HTTP response body is invalid json or xml"
|
||||
|
||||
|
||||
class InvalidHTTPResponseHeader(RestClientException):
|
||||
message = "HTTP response header is invalid"
|
||||
|
||||
|
||||
class InvalidContentType(RestClientException):
|
||||
message = "Invalid content type provided"
|
||||
|
||||
|
|
Loading…
Reference in New Issue