Validate hypervisors_servers Nova V2/V3 API

This patch adds the JSON Schema for response of Nova V2 & V3
hypervisors_servers  API and validate the response with added
JSON Schema to block the backward incompatibility change in the future.

The response body of V2 hypervisors_servers API is below:

{
    "hypervisors": [
        {
            "id": 1,
            "hypervisor_hostname": "fake-mini",
            "servers": []
        }
    ]
}

The response body of V3 hypervisors_servers API is below:

{
    "hypervisor": {
        "id": 1,
        "hypervisor_hostname": "fake-mini",
        "servers": []
    }
}

Partially implements blueprint nova-api-attribute-test

Change-Id: I0456c9f2cd9576edd8ce457ac805fab3ba03c060
This commit is contained in:
Ghanshyam 2014-03-26 20:00:37 +09:00
parent 6694fec2a0
commit 8676fa6b5c
5 changed files with 102 additions and 0 deletions

View File

@ -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']
}
}

View File

@ -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'.

View File

@ -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']

View File

@ -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):

View File

@ -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):