blob: c7a12012d35cce3656a81dd68df9597d3e7364ec [file] [log] [blame]
Tony Yang3d5f1632013-06-06 14:17:57 +08001# Copyright 2013 IBM Corporation
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16from tempest.api.compute import base
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080017from tempest.lib import decorators
Tony Yang3d5f1632013-06-06 14:17:57 +080018
19
zhufl021e66b2018-02-07 14:26:49 +080020class HypervisorAdminTestBase(base.BaseV2ComputeAdminTest):
Ken'ichi Ohmichi88363cb2015-11-19 08:00:54 +000021 """Tests Hypervisors API that require admin privileges"""
Tony Yang3d5f1632013-06-06 14:17:57 +080022
Tony Yang3d5f1632013-06-06 14:17:57 +080023 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +053024 def setup_clients(cls):
zhufl021e66b2018-02-07 14:26:49 +080025 super(HypervisorAdminTestBase, cls).setup_clients()
Jordan Pittier8160d312017-04-18 11:52:23 +020026 cls.client = cls.os_admin.hypervisor_client
Tony Yang3d5f1632013-06-06 14:17:57 +080027
28 def _list_hypervisors(self):
29 # List of hypervisors
ghanshyam2dfd0532015-08-18 17:18:40 +090030 hypers = self.client.list_hypervisors()['hypervisors']
Tony Yang3d5f1632013-06-06 14:17:57 +080031 return hypers
32
zhufl021e66b2018-02-07 14:26:49 +080033
34class HypervisorAdminTestJSON(HypervisorAdminTestBase):
35 """Tests Hypervisors API that require admin privileges"""
36
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080037 @decorators.idempotent_id('7f0ceacd-c64d-4e96-b8ee-d02943142cc5')
Tony Yang3d5f1632013-06-06 14:17:57 +080038 def test_get_hypervisor_list(self):
zhufla0e87dc2020-05-13 15:52:15 +080039 """List of hypervisor and available hypervisors hostname"""
Tony Yang3d5f1632013-06-06 14:17:57 +080040 hypers = self._list_hypervisors()
zhuflcfa1cd52017-08-10 10:23:01 +080041 self.assertNotEmpty(hypers, "No hypervisors found.")
Tony Yang3d5f1632013-06-06 14:17:57 +080042
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080043 @decorators.idempotent_id('1e7fdac2-b672-4ad1-97a4-bad0e3030118')
Tony Yang3d5f1632013-06-06 14:17:57 +080044 def test_get_hypervisor_list_details(self):
zhufla0e87dc2020-05-13 15:52:15 +080045 """Display the details of the all hypervisor"""
ghanshyam2dfd0532015-08-18 17:18:40 +090046 hypers = self.client.list_hypervisors(detail=True)['hypervisors']
zhuflcfa1cd52017-08-10 10:23:01 +080047 self.assertNotEmpty(hypers, "No hypervisors found.")
Tony Yang3d5f1632013-06-06 14:17:57 +080048
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080049 @decorators.idempotent_id('94ff9eae-a183-428e-9cdb-79fde71211cc')
Tony Yang3d5f1632013-06-06 14:17:57 +080050 def test_get_hypervisor_show_details(self):
zhufla0e87dc2020-05-13 15:52:15 +080051 """Display the details of the specified hypervisor"""
Tony Yang3d5f1632013-06-06 14:17:57 +080052 hypers = self._list_hypervisors()
zhuflcfa1cd52017-08-10 10:23:01 +080053 self.assertNotEmpty(hypers, "No hypervisors found.")
Tony Yang3d5f1632013-06-06 14:17:57 +080054
ghanshyam2dfd0532015-08-18 17:18:40 +090055 details = self.client.show_hypervisor(hypers[0]['id'])['hypervisor']
Masayuki Igawaf9009b42017-04-10 14:49:29 +090056 self.assertNotEmpty(details)
Tony Yang3d5f1632013-06-06 14:17:57 +080057 self.assertEqual(details['hypervisor_hostname'],
58 hypers[0]['hypervisor_hostname'])
59
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080060 @decorators.idempotent_id('797e4f28-b6e0-454d-a548-80cc77c00816')
Tony Yang3d5f1632013-06-06 14:17:57 +080061 def test_get_hypervisor_stats(self):
zhufla0e87dc2020-05-13 15:52:15 +080062 """Verify the stats of the all hypervisor"""
ghanshyam2dfd0532015-08-18 17:18:40 +090063 stats = (self.client.show_hypervisor_statistics()
64 ['hypervisor_statistics'])
Masayuki Igawaf9009b42017-04-10 14:49:29 +090065 self.assertNotEmpty(stats)
Tony Yang3d5f1632013-06-06 14:17:57 +080066
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080067 @decorators.idempotent_id('91a50d7d-1c2b-4f24-b55a-a1fe20efca70')
Tony Yang3d5f1632013-06-06 14:17:57 +080068 def test_get_hypervisor_uptime(self):
zhufla0e87dc2020-05-13 15:52:15 +080069 """Verify that GET shows the specified hypervisor uptime"""
Tony Yang3d5f1632013-06-06 14:17:57 +080070 hypers = self._list_hypervisors()
71
David Shrewsbury152b7812014-07-07 16:56:16 -040072 # Ironic will register each baremetal node as a 'hypervisor',
73 # so the hypervisor list can contain many hypervisors of type
74 # 'ironic'. If they are ALL ironic, skip this test since ironic
75 # doesn't support hypervisor uptime. Otherwise, remove them
76 # from the list of hypervisors to test.
77 ironic_only = True
78 hypers_without_ironic = []
Sean Dague1c408f52013-12-12 16:46:32 -050079 for hyper in hypers:
zhufle9260e22016-12-07 11:55:33 +080080 details = (self.client.show_hypervisor(hyper['id'])
ghanshyam2dfd0532015-08-18 17:18:40 +090081 ['hypervisor'])
zhuflc7d65d12018-09-04 16:48:31 +080082 if (details['hypervisor_type'] != 'ironic' and
83 details['state'] == 'up'):
David Shrewsbury152b7812014-07-07 16:56:16 -040084 hypers_without_ironic.append(hyper)
85 ironic_only = False
86
87 if ironic_only:
88 raise self.skipException(
89 "Ironic does not support hypervisor uptime")
90
91 has_valid_uptime = False
92 for hyper in hypers_without_ironic:
Sean Dague1c408f52013-12-12 16:46:32 -050093 # because hypervisors might be disabled, this loops looking
94 # for any good hit.
95 try:
ghanshyam2dfd0532015-08-18 17:18:40 +090096 uptime = (self.client.show_hypervisor_uptime(hyper['id'])
97 ['hypervisor'])
Masayuki Igawa0c0f0142017-04-10 17:22:02 +090098 if uptime:
Sean Dague1c408f52013-12-12 16:46:32 -050099 has_valid_uptime = True
100 break
101 except Exception:
102 pass
103 self.assertTrue(
104 has_valid_uptime,
105 "None of the hypervisors had a valid uptime: %s" % hypers)
Tony Yang3d5f1632013-06-06 14:17:57 +0800106
zhufl021e66b2018-02-07 14:26:49 +0800107
zhufle142f542018-08-01 14:08:52 +0800108class HypervisorAdminV228Test(HypervisorAdminTestBase):
zhufla0e87dc2020-05-13 15:52:15 +0800109 """Tests Hypervisors API higher than 2.27 that require admin privileges"""
110
zhufle142f542018-08-01 14:08:52 +0800111 min_microversion = '2.28'
112
113 @decorators.idempotent_id('d46bab64-0fbe-4eb8-9133-e6ee56188cc5')
114 def test_get_list_hypervisor_details(self):
zhufla0e87dc2020-05-13 15:52:15 +0800115 """Test listing and showing hypervisor details"""
zhufle142f542018-08-01 14:08:52 +0800116 # NOTE(zhufl): This test tests the hypervisor APIs response schema
117 # for 2.28 microversion. No specific assert or behaviour verification
118 # is needed.
119 hypers = self._list_hypervisors()
120 self.assertNotEmpty(hypers, "No hypervisors found.")
121 self.client.show_hypervisor(hypers[0]['id'])
122
123
zhufl021e66b2018-02-07 14:26:49 +0800124class HypervisorAdminUnderV252Test(HypervisorAdminTestBase):
zhufla0e87dc2020-05-13 15:52:15 +0800125 """Tests Hypervisors API below 2.53 that require admin privileges"""
126
zhufl021e66b2018-02-07 14:26:49 +0800127 max_microversion = '2.52'
128
129 @decorators.idempotent_id('e81bba3f-6215-4e39-a286-d52d2f906862')
130 def test_get_hypervisor_show_servers(self):
zhufla0e87dc2020-05-13 15:52:15 +0800131 """Test showing instances about the specific hypervisors"""
zhufl021e66b2018-02-07 14:26:49 +0800132 hypers = self._list_hypervisors()
133 self.assertNotEmpty(hypers, "No hypervisors found.")
134
135 hostname = hypers[0]['hypervisor_hostname']
136 hypervisors = (self.client.list_servers_on_hypervisor(hostname)
137 ['hypervisors'])
138 self.assertNotEmpty(hypervisors)
139
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800140 @decorators.idempotent_id('d7e1805b-3b14-4a3b-b6fd-50ec6d9f361f')
Lingxian Kong1629d5d2013-10-05 17:12:29 +0800141 def test_search_hypervisor(self):
zhufla0e87dc2020-05-13 15:52:15 +0800142 """Test searching for hypervisors by its name"""
Lingxian Kong1629d5d2013-10-05 17:12:29 +0800143 hypers = self._list_hypervisors()
zhuflcfa1cd52017-08-10 10:23:01 +0800144 self.assertNotEmpty(hypers, "No hypervisors found.")
David Kranz0a735172015-01-16 10:51:18 -0500145 hypers = self.client.search_hypervisor(
ghanshyam2dfd0532015-08-18 17:18:40 +0900146 hypers[0]['hypervisor_hostname'])['hypervisors']
zhuflcfa1cd52017-08-10 10:23:01 +0800147 self.assertNotEmpty(hypers, "No hypervisors found.")
zhufl6bc98cc2020-06-22 11:15:05 +0800148
149
150class HypervisorAdminV253TestBase(base.BaseV2ComputeAdminTest):
151 """Tests Hypervisors API above 2.53 that require admin privileges"""
152
153 min_microversion = '2.53'
154
155 @classmethod
156 def setup_clients(cls):
157 super(HypervisorAdminV253TestBase, cls).setup_clients()
158 cls.client = cls.os_admin.hypervisor_client
159
160 @decorators.idempotent_id('4ab54a14-77a2-4e39-b9d2-1306d157c705')
161 def test_list_show_detail_hypervisors(self):
162 """Verify the list, list details, and show hypevisors
163
164 This verify the Hypervisor API response schema with v2.53 microversion
165 """
166 self.client.list_hypervisors(
167 detail=True, with_servers=True)['hypervisors']
168 hypers = self.client.list_hypervisors(with_servers=True)['hypervisors']
169 self.client.show_hypervisor(
170 hypers[0]['id'], with_servers=True)['hypervisor']