Verify attributes through Nova os-security-groups API
This patch adds checks whether a response of Nova security group get/create/update API includes the attributes to block the backward incompatibility change in the future. The response body of v2 get/create/update API is the below: { "security_group": { "id": 10, "name": "sg1", "tenant_id": "bd9a4c2ed39e49f4aa525e99a5f92454", "rules": [], "description": "Test security group." } } Partially implements blueprint nova-api-attribute-test Change-Id: I7888e1e483ff77adcaf2bd9a38676bd2075e1305
This commit is contained in:
parent
71381634e3
commit
b34c1612f5
@ -12,6 +12,49 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
common_security_group_rule = {
|
||||
'from_port': {'type': ['integer', 'null']},
|
||||
'to_port': {'type': ['integer', 'null']},
|
||||
'group': {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'tenant_id': {'type': 'string'},
|
||||
'name': {'type': 'string'}
|
||||
}
|
||||
},
|
||||
'ip_protocol': {'type': ['string', 'null']},
|
||||
# 'parent_group_id' can be UUID so defining it as 'string' also.
|
||||
'parent_group_id': {'type': ['string', 'integer', 'null']},
|
||||
'ip_range': {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'cidr': {'type': 'string'}
|
||||
}
|
||||
# When optional argument is provided in request body
|
||||
# like 'group_id' then, attribute 'cidr' does not
|
||||
# comes in response body. So it is not 'required'.
|
||||
},
|
||||
'id': {'type': ['string', 'integer']}
|
||||
}
|
||||
|
||||
common_security_group = {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'id': {'type': ['integer', 'string']},
|
||||
'name': {'type': 'string'},
|
||||
'tenant_id': {'type': 'string'},
|
||||
'rules': {
|
||||
'type': 'array',
|
||||
'items': {
|
||||
'type': ['object', 'null'],
|
||||
'properties': common_security_group_rule
|
||||
}
|
||||
},
|
||||
'description': {'type': 'string'},
|
||||
},
|
||||
'required': ['id', 'name', 'tenant_id', 'rules', 'description'],
|
||||
}
|
||||
|
||||
list_security_groups = {
|
||||
'status_code': [200],
|
||||
'response_body': {
|
||||
@ -19,24 +62,24 @@ list_security_groups = {
|
||||
'properties': {
|
||||
'security_groups': {
|
||||
'type': 'array',
|
||||
'items': {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'id': {'type': ['integer', 'string']},
|
||||
'name': {'type': 'string'},
|
||||
'tenant_id': {'type': 'string'},
|
||||
'rules': {'type': 'array'},
|
||||
'description': {'type': 'string'},
|
||||
},
|
||||
'required': ['id', 'name', 'tenant_id', 'rules',
|
||||
'description'],
|
||||
}
|
||||
'items': common_security_group
|
||||
}
|
||||
},
|
||||
'required': ['security_groups']
|
||||
}
|
||||
}
|
||||
|
||||
get_security_group = create_security_group = update_security_group = {
|
||||
'status_code': [200],
|
||||
'response_body': {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'security_group': common_security_group
|
||||
},
|
||||
'required': ['security_group']
|
||||
}
|
||||
}
|
||||
|
||||
create_security_group_rule = {
|
||||
'status_code': [200],
|
||||
'response_body': {
|
||||
@ -44,25 +87,7 @@ create_security_group_rule = {
|
||||
'properties': {
|
||||
'security_group_rule': {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'from_port': {'type': 'integer'},
|
||||
'to_port': {'type': 'integer'},
|
||||
'group': {'type': 'object'},
|
||||
'ip_protocol': {'type': 'string'},
|
||||
# 'parent_group_id' can be UUID so defining it
|
||||
# as 'string' also.
|
||||
'parent_group_id': {'type': ['integer', 'string']},
|
||||
'id': {'type': ['integer', 'string']},
|
||||
'ip_range': {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'cidr': {'type': 'string'}
|
||||
}
|
||||
# When optional argument is provided in request body
|
||||
# like 'group_id' then, attribute 'cidr' does not
|
||||
# comes in response body. So it is not 'required'.
|
||||
}
|
||||
},
|
||||
'properties': common_security_group_rule,
|
||||
'required': ['from_port', 'to_port', 'group', 'ip_protocol',
|
||||
'parent_group_id', 'id', 'ip_range']
|
||||
}
|
||||
|
@ -47,6 +47,7 @@ class SecurityGroupsClientJSON(rest_client.RestClient):
|
||||
url = "os-security-groups/%s" % str(security_group_id)
|
||||
resp, body = self.get(url)
|
||||
body = json.loads(body)
|
||||
self.validate_response(schema.get_security_group, resp, body)
|
||||
return resp, body['security_group']
|
||||
|
||||
def create_security_group(self, name, description):
|
||||
@ -62,6 +63,7 @@ class SecurityGroupsClientJSON(rest_client.RestClient):
|
||||
post_body = json.dumps({'security_group': post_body})
|
||||
resp, body = self.post('os-security-groups', post_body)
|
||||
body = json.loads(body)
|
||||
self.validate_response(schema.get_security_group, resp, body)
|
||||
return resp, body['security_group']
|
||||
|
||||
def update_security_group(self, security_group_id, name=None,
|
||||
@ -81,6 +83,7 @@ class SecurityGroupsClientJSON(rest_client.RestClient):
|
||||
resp, body = self.put('os-security-groups/%s' % str(security_group_id),
|
||||
post_body)
|
||||
body = json.loads(body)
|
||||
self.validate_response(schema.update_security_group, resp, body)
|
||||
return resp, body['security_group']
|
||||
|
||||
def delete_security_group(self, security_group_id):
|
||||
|
Loading…
Reference in New Issue
Block a user