Verify list_virtual_interfaces attributes of API
This patch adds the JSON schema for Nova V2 list_virtual_interfaces
API response and validate the response with added JSON schema
to block the backward incompatibility change in the future.
This patch also adds the mac address in common parameter type for
reusability amongs other schema.
The response body of list_virtual_interfaces V2 APIs is below:
{
"virtual_interfaces": [
{
"id": "%(id)s",
"mac_address": "%(mac_addr)s",
"OS-EXT-VIF-NET:net_id": "%(id)s"
}
]
}
Partially implements blueprint nova-api-attribute-test
Change-Id: I261917920aea880cf3419f23478b6df322a10ded
diff --git a/tempest/api_schema/compute/parameter_types.py b/tempest/api_schema/compute/parameter_types.py
index 67c0c9b..95d5b92 100644
--- a/tempest/api_schema/compute/parameter_types.py
+++ b/tempest/api_schema/compute/parameter_types.py
@@ -26,3 +26,8 @@
'required': ['href', 'rel']
}
}
+
+mac_address = {
+ 'type': 'string',
+ 'pattern': '(?:[a-f0-9]{2}:){5}[a-f0-9]{2}'
+}
diff --git a/tempest/api_schema/compute/v2/servers.py b/tempest/api_schema/compute/v2/servers.py
index 4e0cec0..81d2ef7 100644
--- a/tempest/api_schema/compute/v2/servers.py
+++ b/tempest/api_schema/compute/v2/servers.py
@@ -42,3 +42,27 @@
'required': ['server']
}
}
+
+list_virtual_interfaces = {
+ 'status_code': [200],
+ 'response_body': {
+ 'type': 'object',
+ 'properties': {
+ 'virtual_interfaces': {
+ 'type': 'array',
+ 'items': {
+ 'type': 'object',
+ 'properties': {
+ 'id': {'type': 'string'},
+ 'mac_address': parameter_types.mac_address,
+ 'OS-EXT-VIF-NET:net_id': {'type': 'string'}
+ },
+ # 'OS-EXT-VIF-NET:net_id' is API extension So it is
+ # not defined as 'required'
+ 'required': ['id', 'mac_address']
+ }
+ }
+ },
+ 'required': ['virtual_interfaces']
+ }
+}
diff --git a/tempest/services/compute/json/servers_client.py b/tempest/services/compute/json/servers_client.py
index d6705db..438fce8 100644
--- a/tempest/services/compute/json/servers_client.py
+++ b/tempest/services/compute/json/servers_client.py
@@ -403,7 +403,9 @@
"""
resp, body = self.get('/'.join(['servers', server_id,
'os-virtual-interfaces']))
- return resp, json.loads(body)
+ body = json.loads(body)
+ self.validate_response(schema.list_virtual_interfaces, resp, body)
+ return resp, body
def rescue_server(self, server_id, **kwargs):
"""Rescue the provided server."""