Verify the list volume attributes of Nova APIs
This patch adds the JSON schema for volume list and
validate the response of Nova Volume list APIs with
added JSON schema to block the backward incompatibility
change in the future.
The response body of Nova APIs volume list-'os-volumes'
& volume list details-'os-volumes/detail' is the below:
{
"volumes": [
{
"id": "a26887c6-c47b-4654-abb5-dfadf7d3f803",
"status": "in-use",
"displayName": "Volume Name",
"availabilityZone": "zone1:host1",
"createdAt": "1999-01-01T01:01:01",
"displayDescription": "Volume Description"
"volumeType": "Backup",
"snapshotId": null,
"metadata": {},
"size": 100,
"attachments": [
{
"id": "a26887c6-c47b-4654-abb5-dfadf7d3f803",
"device": "/",
"volumeId": "a287c6-c47b-4654-abb5-dfadf7d3f803",
"serverId": "3912f4-c5ba-4aec-9165-872876fe202e"
}
]
}
]
}
Partially implements blueprint nova-api-attribute-test
Change-Id: I97bb6310a6fcb7d475dbd2bc53814d38c5e9c173
diff --git a/tempest/api_schema/compute/v2/volumes.py b/tempest/api_schema/compute/v2/volumes.py
index 16ed7c2..9cfd7e3 100644
--- a/tempest/api_schema/compute/v2/volumes.py
+++ b/tempest/api_schema/compute/v2/volumes.py
@@ -20,10 +20,7 @@
'volume': {
'type': 'object',
'properties': {
- # NOTE: Now the type of 'id' is integer, but here allows
- # 'string' also because we will be able to change it to
- # 'uuid' in the future.
- 'id': {'type': ['integer', 'string']},
+ 'id': {'type': 'string'},
'status': {'type': 'string'},
'displayName': {'type': ['string', 'null']},
'availabilityZone': {'type': 'string'},
@@ -38,11 +35,17 @@
'items': {
'type': 'object',
'properties': {
- 'id': {'type': ['integer', 'string']},
+ 'id': {'type': 'string'},
'device': {'type': 'string'},
- 'volumeId': {'type': ['integer', 'string']},
+ 'volumeId': {'type': 'string'},
'serverId': {'type': ['integer', 'string']}
}
+ # NOTE- If volume is not attached to any server
+ # then, 'attachments' attributes comes as array
+ # with empty objects "[{}]" due to that elements
+ # of 'attachments' cannot defined as 'required'.
+ # If it would come as empty array "[]" then,
+ # those elements can be defined as 'required'.
}
}
},
@@ -54,3 +57,54 @@
'required': ['volume']
}
}
+
+list_volumes = {
+ 'status_code': [200],
+ 'response_body': {
+ 'type': 'object',
+ 'properties': {
+ 'volumes': {
+ 'type': 'array',
+ 'items': {
+ 'type': 'object',
+ 'properties': {
+ 'id': {'type': 'string'},
+ 'status': {'type': 'string'},
+ 'displayName': {'type': ['string', 'null']},
+ 'availabilityZone': {'type': 'string'},
+ 'createdAt': {'type': 'string'},
+ 'displayDescription': {'type': ['string', 'null']},
+ 'volumeType': {'type': 'string'},
+ 'snapshotId': {'type': ['string', 'null']},
+ 'metadata': {'type': 'object'},
+ 'size': {'type': 'integer'},
+ 'attachments': {
+ 'type': 'array',
+ 'items': {
+ 'type': 'object',
+ 'properties': {
+ 'id': {'type': 'string'},
+ 'device': {'type': 'string'},
+ 'volumeId': {'type': 'string'},
+ 'serverId': {'type': ['integer', 'string']}
+ }
+ # NOTE- If volume is not attached to any server
+ # then, 'attachments' attributes comes as array
+ # with empty object "[{}]" due to that elements
+ # of 'attachments' cannot defined as 'required'
+ # If it would come as empty array "[]" then,
+ # those elements can be defined as 'required'.
+ }
+ }
+ },
+ 'required': ['id', 'status', 'displayName',
+ 'availabilityZone', 'createdAt',
+ 'displayDescription', 'volumeType',
+ 'snapshotId', 'metadata', 'size',
+ 'attachments']
+ }
+ }
+ },
+ 'required': ['volumes']
+ }
+}
diff --git a/tempest/services/compute/json/volumes_extensions_client.py b/tempest/services/compute/json/volumes_extensions_client.py
index 451dbac..17468eb 100644
--- a/tempest/services/compute/json/volumes_extensions_client.py
+++ b/tempest/services/compute/json/volumes_extensions_client.py
@@ -42,6 +42,7 @@
resp, body = self.get(url)
body = json.loads(body)
+ self.validate_response(schema.list_volumes, resp, body)
return resp, body['volumes']
def list_volumes_with_detail(self, params=None):
@@ -52,6 +53,7 @@
resp, body = self.get(url)
body = json.loads(body)
+ self.validate_response(schema.list_volumes, resp, body)
return resp, body['volumes']
def get_volume(self, volume_id):