blob: b23c59fefc35d3d8a64322f5e9b1c414f7efe962 [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):
39 # List of hypervisor and available hypervisors hostname
40 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):
45 # 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):
51 # Display the details of the specified hypervisor
52 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):
62 # 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):
69 # Verify that GET shows the specified hypervisor uptime
70 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'])
David Shrewsbury152b7812014-07-07 16:56:16 -040082 if details['hypervisor_type'] != 'ironic':
83 hypers_without_ironic.append(hyper)
84 ironic_only = False
85
86 if ironic_only:
87 raise self.skipException(
88 "Ironic does not support hypervisor uptime")
89
90 has_valid_uptime = False
91 for hyper in hypers_without_ironic:
Sean Dague1c408f52013-12-12 16:46:32 -050092 # because hypervisors might be disabled, this loops looking
93 # for any good hit.
94 try:
ghanshyam2dfd0532015-08-18 17:18:40 +090095 uptime = (self.client.show_hypervisor_uptime(hyper['id'])
96 ['hypervisor'])
Masayuki Igawa0c0f0142017-04-10 17:22:02 +090097 if uptime:
Sean Dague1c408f52013-12-12 16:46:32 -050098 has_valid_uptime = True
99 break
100 except Exception:
101 pass
102 self.assertTrue(
103 has_valid_uptime,
104 "None of the hypervisors had a valid uptime: %s" % hypers)
Tony Yang3d5f1632013-06-06 14:17:57 +0800105
zhufl021e66b2018-02-07 14:26:49 +0800106
107class HypervisorAdminUnderV252Test(HypervisorAdminTestBase):
108 max_microversion = '2.52'
109
110 @decorators.idempotent_id('e81bba3f-6215-4e39-a286-d52d2f906862')
111 def test_get_hypervisor_show_servers(self):
112 # Show instances about the specific hypervisors
113 hypers = self._list_hypervisors()
114 self.assertNotEmpty(hypers, "No hypervisors found.")
115
116 hostname = hypers[0]['hypervisor_hostname']
117 hypervisors = (self.client.list_servers_on_hypervisor(hostname)
118 ['hypervisors'])
119 self.assertNotEmpty(hypervisors)
120
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800121 @decorators.idempotent_id('d7e1805b-3b14-4a3b-b6fd-50ec6d9f361f')
Lingxian Kong1629d5d2013-10-05 17:12:29 +0800122 def test_search_hypervisor(self):
123 hypers = self._list_hypervisors()
zhuflcfa1cd52017-08-10 10:23:01 +0800124 self.assertNotEmpty(hypers, "No hypervisors found.")
David Kranz0a735172015-01-16 10:51:18 -0500125 hypers = self.client.search_hypervisor(
ghanshyam2dfd0532015-08-18 17:18:40 +0900126 hypers[0]['hypervisor_hostname'])['hypervisors']
zhuflcfa1cd52017-08-10 10:23:01 +0800127 self.assertNotEmpty(hypers, "No hypervisors found.")