Merge "Add fields in hypervisor schema for 2.33 and 2.53"

This commit is contained in:
Zuul 2022-01-17 02:53:57 +00:00 committed by Gerrit Code Review
commit 268606a720
6 changed files with 164 additions and 3 deletions

View File

@ -350,6 +350,10 @@ Microversion tests implemented in Tempest
.. _2.32: https://docs.openstack.org/nova/latest/reference/api-microversion-history.html#id29 .. _2.32: https://docs.openstack.org/nova/latest/reference/api-microversion-history.html#id29
* `2.33`_
.. _2.33: https://docs.openstack.org/nova/latest/reference/api-microversion-history.html#id30
* `2.36`_ * `2.36`_
.. _2.36: https://docs.openstack.org/nova/latest/reference/api-microversion-history.html#microversion .. _2.36: https://docs.openstack.org/nova/latest/reference/api-microversion-history.html#microversion

View File

@ -145,3 +145,26 @@ class HypervisorAdminUnderV252Test(HypervisorAdminTestBase):
hypers = self.client.search_hypervisor( hypers = self.client.search_hypervisor(
hypers[0]['hypervisor_hostname'])['hypervisors'] hypers[0]['hypervisor_hostname'])['hypervisors']
self.assertNotEmpty(hypers, "No hypervisors found.") self.assertNotEmpty(hypers, "No hypervisors found.")
class HypervisorAdminV253TestBase(base.BaseV2ComputeAdminTest):
"""Tests Hypervisors API above 2.53 that require admin privileges"""
min_microversion = '2.53'
@classmethod
def setup_clients(cls):
super(HypervisorAdminV253TestBase, cls).setup_clients()
cls.client = cls.os_admin.hypervisor_client
@decorators.idempotent_id('4ab54a14-77a2-4e39-b9d2-1306d157c705')
def test_list_show_detail_hypervisors(self):
"""Verify the list, list details, and show hypevisors
This verify the Hypervisor API response schema with v2.53 microversion
"""
self.client.list_hypervisors(
detail=True, with_servers=True)['hypervisors']
hypers = self.client.list_hypervisors(with_servers=True)['hypervisors']
self.client.show_hypervisor(
hypers[0]['id'], with_servers=True)['hypervisor']

View File

@ -0,0 +1,53 @@
# Copyright 2018 ZTE 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 parameter_types
from tempest.lib.api_schema.response.compute.v2_28 \
import hypervisors as hypervisorsv228
###########################################################################
#
# 2.33:
#
# hypervisor_links parameter is added to the response body for the following
# APIs:
#
# - GET /os-hypervisors
# - GET /os-hypervisors/detail
###########################################################################
list_search_hypervisors = copy.deepcopy(
hypervisorsv228.list_search_hypervisors)
list_search_hypervisors['response_body']['properties'].update(
{'hypervisors_links': parameter_types.links}
)
list_hypervisors_detail = copy.deepcopy(
hypervisorsv228.list_hypervisors_detail)
list_hypervisors_detail['response_body']['properties'].update(
{'hypervisors_links': parameter_types.links}
)
# 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.28 ***
get_hypervisor = copy.deepcopy(hypervisorsv228.get_hypervisor)
hypervisor_detail = copy.deepcopy(hypervisorsv228.hypervisor_detail)
get_hypervisor_statistics = \
copy.deepcopy(hypervisorsv228.get_hypervisor_statistics)
get_hypervisor_uptime = copy.deepcopy(hypervisorsv228.get_hypervisor_uptime)
get_hypervisors_servers = copy.deepcopy(
hypervisorsv228.get_hypervisors_servers)

View File

@ -0,0 +1,68 @@
# Copyright 2018 ZTE 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_33 \
import hypervisors as hypervisorsv233
###########################################################################
#
# 2.53:
#
# servers parameter is added to the response body for the following
# APIs:
#
# - GET /os-hypervisor
# - GET /os-hypervisors
# - GET /os-hypervisors/detail
#
###########################################################################
servers = {
'type': 'array',
'items': {
'type': 'object',
'properties': {
'uuid': {'type': 'string', 'format': 'uuid'},
'name': {'type': 'string'},
},
'additionalProperties': False,
},
}
hypervisor_detail = copy.deepcopy(hypervisorsv233.hypervisor_detail)
hypervisor_detail['properties'].update({'servers': servers})
get_hypervisor = copy.deepcopy(hypervisorsv233.get_hypervisor)
get_hypervisor['response_body']['properties'].update(
{'hypervisor': hypervisor_detail})
list_hypervisors_detail = copy.deepcopy(
hypervisorsv233.list_hypervisors_detail)
list_hypervisors_detail['response_body']['properties']['hypervisors'].update(
{'items': hypervisor_detail})
list_search_hypervisors = copy.deepcopy(
hypervisorsv233.list_search_hypervisors)
list_search_hypervisors['response_body']['properties']['hypervisors'][
'items']['properties'].update({'servers': servers})
# 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.33 ***
get_hypervisor_statistics = \
copy.deepcopy(hypervisorsv233.get_hypervisor_statistics)
get_hypervisor_uptime = copy.deepcopy(hypervisorsv233.get_hypervisor_uptime)
get_hypervisors_servers = copy.deepcopy(
hypervisorsv233.get_hypervisors_servers)

View File

@ -13,12 +13,18 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from urllib import parse as urllib
from oslo_serialization import jsonutils as json from oslo_serialization import jsonutils as json
from tempest.lib.api_schema.response.compute.v2_1 \ from tempest.lib.api_schema.response.compute.v2_1 \
import hypervisors as schemav21 import hypervisors as schemav21
from tempest.lib.api_schema.response.compute.v2_28 \ from tempest.lib.api_schema.response.compute.v2_28 \
import hypervisors as schemav228 import hypervisors as schemav228
from tempest.lib.api_schema.response.compute.v2_33 \
import hypervisors as schemav233
from tempest.lib.api_schema.response.compute.v2_53 \
import hypervisors as schemav253
from tempest.lib.common import rest_client from tempest.lib.common import rest_client
from tempest.lib.services.compute import base_compute_client from tempest.lib.services.compute import base_compute_client
@ -27,9 +33,11 @@ class HypervisorClient(base_compute_client.BaseComputeClient):
schema_versions_info = [ schema_versions_info = [
{'min': None, 'max': '2.27', 'schema': schemav21}, {'min': None, 'max': '2.27', 'schema': schemav21},
{'min': '2.28', 'max': None, 'schema': schemav228}] {'min': '2.28', 'max': '2.32', 'schema': schemav228},
{'min': '2.33', 'max': '2.52', 'schema': schemav233},
{'min': '2.53', 'max': None, 'schema': schemav253}]
def list_hypervisors(self, detail=False): def list_hypervisors(self, detail=False, **kwargs):
"""List hypervisors information.""" """List hypervisors information."""
url = 'os-hypervisors' url = 'os-hypervisors'
schema = self.get_schema(self.schema_versions_info) schema = self.get_schema(self.schema_versions_info)
@ -37,14 +45,19 @@ class HypervisorClient(base_compute_client.BaseComputeClient):
if detail: if detail:
url += '/detail' url += '/detail'
_schema = schema.list_hypervisors_detail _schema = schema.list_hypervisors_detail
if kwargs:
url += '?%s' % urllib.urlencode(kwargs)
resp, body = self.get(url) resp, body = self.get(url)
body = json.loads(body) body = json.loads(body)
self.validate_response(_schema, resp, body) self.validate_response(_schema, resp, body)
return rest_client.ResponseBody(resp, body) return rest_client.ResponseBody(resp, body)
def show_hypervisor(self, hypervisor_id): def show_hypervisor(self, hypervisor_id, **kwargs):
"""Display the details of the specified hypervisor.""" """Display the details of the specified hypervisor."""
url = 'os-hypervisors/%s' % hypervisor_id
if kwargs:
url += '?%s' % urllib.urlencode(kwargs)
resp, body = self.get('os-hypervisors/%s' % hypervisor_id) resp, body = self.get('os-hypervisors/%s' % hypervisor_id)
body = json.loads(body) body = json.loads(body)
schema = self.get_schema(self.schema_versions_info) schema = self.get_schema(self.schema_versions_info)