diff --git a/tempest/api_schema/compute/hypervisors.py b/tempest/api_schema/compute/hypervisors.py index 7de51479c5..a935f87f7a 100644 --- a/tempest/api_schema/compute/hypervisors.py +++ b/tempest/api_schema/compute/hypervisors.py @@ -147,3 +147,42 @@ common_show_hypervisor = { 'required': ['hypervisor'] } } + +common_hypervisors_detail = { + 'status_code': [200], + 'response_body': { + 'type': 'object', + 'properties': { + 'hypervisors': { + 'type': 'array', + 'items': { + 'type': 'object', + 'properties': { + 'id': {'type': ['integer', 'string']}, + 'hypervisor_hostname': {'type': 'string'} + }, + 'required': ['id', 'hypervisor_hostname'] + } + } + }, + 'required': ['hypervisors'] + } +} + +common_hypervisors_info = { + 'status_code': [200], + 'response_body': { + 'type': 'object', + 'properties': { + 'hypervisor': { + 'type': 'object', + 'properties': { + 'id': {'type': ['integer', 'string']}, + 'hypervisor_hostname': {'type': 'string'}, + }, + 'required': ['id', 'hypervisor_hostname'] + } + }, + 'required': ['hypervisor'] + } +} diff --git a/tempest/api_schema/compute/v2/hypervisors.py b/tempest/api_schema/compute/v2/hypervisors.py new file mode 100644 index 0000000000..6bb43a758b --- /dev/null +++ b/tempest/api_schema/compute/v2/hypervisors.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.api_schema.compute import hypervisors + +hypervisors_servers = copy.deepcopy(hypervisors.common_hypervisors_detail) + +# Defining extra attributes for V3 show hypervisor schema +hypervisors_servers['response_body']['properties']['hypervisors']['items'][ + 'properties']['servers'] = { + 'type': 'array', + 'items': { + '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']}, + 'name': {'type': 'string'} + } + } + } +# In V2 API, if there is no servers (VM) on the Hypervisor host then 'servers' +# attribute will not be present in response body So it is not 'required'. diff --git a/tempest/api_schema/compute/v3/hypervisors.py b/tempest/api_schema/compute/v3/hypervisors.py index 6eb0072c98..aa31827ef4 100644 --- a/tempest/api_schema/compute/v3/hypervisors.py +++ b/tempest/api_schema/compute/v3/hypervisors.py @@ -25,3 +25,26 @@ show_hypervisor = copy.deepcopy(hypervisors.common_show_hypervisor) # Defining extra attributes for V3 show hypervisor schema show_hypervisor['response_body']['properties']['hypervisor']['properties'][ 'os-pci:pci_stats'] = {'type': 'array'} + +hypervisors_servers = copy.deepcopy(hypervisors.common_hypervisors_info) + +# Defining extra attributes for V3 show hypervisor schema +hypervisors_servers['response_body']['properties']['hypervisor']['properties'][ + 'servers'] = { + 'type': 'array', + 'items': { + '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']}, + 'name': {'type': 'string'} + } + } + } +# V3 API response body always contains the 'servers' attribute even there +# is no server (VM) are present on Hypervisor host. +hypervisors_servers['response_body']['properties']['hypervisor'][ + 'required'] = ['id', 'hypervisor_hostname', 'servers'] diff --git a/tempest/services/compute/json/hypervisor_client.py b/tempest/services/compute/json/hypervisor_client.py index 89a79617c9..28ca2a6f46 100644 --- a/tempest/services/compute/json/hypervisor_client.py +++ b/tempest/services/compute/json/hypervisor_client.py @@ -16,6 +16,7 @@ import json from tempest.api_schema.compute import hypervisors as common_schema +from tempest.api_schema.compute.v2 import hypervisors as v2schema from tempest.common import rest_client from tempest import config @@ -54,6 +55,7 @@ class HypervisorClientJSON(rest_client.RestClient): """List instances belonging to the specified hypervisor.""" resp, body = self.get('os-hypervisors/%s/servers' % hyper_name) body = json.loads(body) + self.validate_response(v2schema.hypervisors_servers, resp, body) return resp, body['hypervisors'] def get_hypervisor_stats(self): diff --git a/tempest/services/compute/v3/json/hypervisor_client.py b/tempest/services/compute/v3/json/hypervisor_client.py index 0ba6ebfca6..abe6788760 100644 --- a/tempest/services/compute/v3/json/hypervisor_client.py +++ b/tempest/services/compute/v3/json/hypervisor_client.py @@ -53,6 +53,7 @@ class HypervisorV3ClientJSON(rest_client.RestClient): """List instances belonging to the specified hypervisor.""" resp, body = self.get('os-hypervisors/%s/servers' % hyper_name) body = json.loads(body) + self.validate_response(v3schema.hypervisors_servers, resp, body) return resp, body['hypervisor'] def get_hypervisor_stats(self):