Add tag in compute interfaces schema for microversion 2.70
https://docs.openstack.org/api-ref/compute/#list-port-interfaces
Optional field 'tag' is added in the response body of the following APIs
in compute microversion 2.70:
- GET /servers/{server_id}/os-interface
- POST /servers/{server_id}/os-interface
- GET /servers/{server_id}/os-interface/{port_id}
This is to add it in the interface schema of compute microversion 2.70.
Implements: blueprint fix-microversion-gap
Change-Id: I6d5c27cadf75919a54e20eb2b095dec22817e47a
diff --git a/tempest/api/compute/servers/test_attach_interfaces.py b/tempest/api/compute/servers/test_attach_interfaces.py
index 0601bbe..102792e 100644
--- a/tempest/api/compute/servers/test_attach_interfaces.py
+++ b/tempest/api/compute/servers/test_attach_interfaces.py
@@ -427,3 +427,33 @@
CONF.compute.build_interval, original_ip_count):
raise lib_exc.TimeoutException(
'Timed out while waiting for IP count to decrease.')
+
+
+class AttachInterfacesV270Test(AttachInterfacesTestBase):
+ """Test interface API with microversion greater than 2.69"""
+ min_microversion = '2.70'
+
+ @decorators.idempotent_id('2853f095-8277-4067-92bd-9f10bd4f8e0c')
+ @utils.services('network')
+ def test_create_get_list_interfaces(self):
+ """Test interface API with microversion greater than 2.69
+
+ Checking create, get, list interface APIs response schema.
+ """
+ server = self.create_test_server(wait_until='ACTIVE')
+ try:
+ iface = self.interfaces_client.create_interface(server['id'])[
+ 'interfaceAttachment']
+ iface = waiters.wait_for_interface_status(
+ self.interfaces_client, server['id'], iface['port_id'],
+ 'ACTIVE')
+ except lib_exc.BadRequest as e:
+ msg = ('Multiple possible networks found, use a Network ID to be '
+ 'more specific.')
+ if not CONF.compute.fixed_network_name and six.text_type(e) == msg:
+ raise
+ else:
+ # just to check the response schema
+ self.interfaces_client.show_interface(
+ server['id'], iface['port_id'])
+ self.interfaces_client.list_interfaces(server['id'])
diff --git a/tempest/lib/api_schema/response/compute/v2_70/interfaces.py b/tempest/lib/api_schema/response/compute/v2_70/interfaces.py
new file mode 100644
index 0000000..3160b92
--- /dev/null
+++ b/tempest/lib/api_schema/response/compute/v2_70/interfaces.py
@@ -0,0 +1,37 @@
+# Copyright 2014 NEC Corporation. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+import copy
+
+from tempest.lib.api_schema.response.compute.v2_1 import interfaces
+
+# ****** Schemas changed in microversion 2.70 *****************
+#
+# 1. add optional field 'tag' in the Response body of the following APIs:
+# - GET /servers/{server_id}/os-interface
+# - POST /servers/{server_id}/os-interface
+# - GET /servers/{server_id}/os-interface/{port_id}
+
+get_create_interfaces = copy.deepcopy(interfaces.get_create_interfaces)
+get_create_interfaces['response_body']['properties']['interfaceAttachment'][
+ 'properties'].update({'tag': {'type': ['string', 'null']}})
+
+list_interfaces = copy.deepcopy(interfaces.list_interfaces)
+list_interfaces['response_body']['properties']['interfaceAttachments'][
+ 'items']['properties'].update({'tag': {'type': ['string', 'null']}})
+
+# NOTE(zhufl): Below are the unchanged schema in this microversion. We need
+# to keep this schema in this file to have the generic way to select the
+# right schema based on self.schema_versions_info mapping in service client.
+# ****** Schemas unchanged since microversion 2.1 ***
+delete_interface = copy.deepcopy(interfaces.delete_interface)
diff --git a/tempest/lib/services/compute/interfaces_client.py b/tempest/lib/services/compute/interfaces_client.py
index e1c02fa..9244a4a 100644
--- a/tempest/lib/services/compute/interfaces_client.py
+++ b/tempest/lib/services/compute/interfaces_client.py
@@ -16,15 +16,22 @@
from oslo_serialization import jsonutils as json
from tempest.lib.api_schema.response.compute.v2_1 import interfaces as schema
+from tempest.lib.api_schema.response.compute.v2_70 import interfaces as \
+ schemav270
from tempest.lib.common import rest_client
from tempest.lib.services.compute import base_compute_client
class InterfacesClient(base_compute_client.BaseComputeClient):
+ schema_versions_info = [
+ {'min': None, 'max': '2.69', 'schema': schema},
+ {'min': '2.70', 'max': None, 'schema': schemav270}]
+
def list_interfaces(self, server_id):
resp, body = self.get('servers/%s/os-interface' % server_id)
body = json.loads(body)
+ schema = self.get_schema(self.schema_versions_info)
self.validate_response(schema.list_interfaces, resp, body)
return rest_client.ResponseBody(resp, body)
@@ -40,6 +47,7 @@
resp, body = self.post('servers/%s/os-interface' % server_id,
body=post_body)
body = json.loads(body)
+ schema = self.get_schema(self.schema_versions_info)
self.validate_response(schema.get_create_interfaces, resp, body)
return rest_client.ResponseBody(resp, body)
@@ -47,6 +55,7 @@
resp, body = self.get('servers/%s/os-interface/%s' % (server_id,
port_id))
body = json.loads(body)
+ schema = self.get_schema(self.schema_versions_info)
self.validate_response(schema.get_create_interfaces, resp, body)
return rest_client.ResponseBody(resp, body)