blob: e0e5a29e168bc5cdd7cab586999abfb2cdbc26db [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
ivan-zhuf2b00502013-10-18 10:06:52 +080020class HypervisorAdminTestJSON(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):
25 super(HypervisorAdminTestJSON, cls).setup_clients()
Tony Yang3d5f1632013-06-06 14:17:57 +080026 cls.client = cls.os_adm.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
Sean Dague1c408f52013-12-12 16:46:32 -050033 def assertHypervisors(self, hypers):
Béla Vancsics64862f72016-11-08 09:12:31 +010034 self.assertGreater(len(hypers), 0, "No hypervisors found: %s" % hypers)
Sean Dague1c408f52013-12-12 16:46:32 -050035
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080036 @decorators.idempotent_id('7f0ceacd-c64d-4e96-b8ee-d02943142cc5')
Tony Yang3d5f1632013-06-06 14:17:57 +080037 def test_get_hypervisor_list(self):
38 # List of hypervisor and available hypervisors hostname
39 hypers = self._list_hypervisors()
Sean Dague1c408f52013-12-12 16:46:32 -050040 self.assertHypervisors(hypers)
Tony Yang3d5f1632013-06-06 14:17:57 +080041
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080042 @decorators.idempotent_id('1e7fdac2-b672-4ad1-97a4-bad0e3030118')
Tony Yang3d5f1632013-06-06 14:17:57 +080043 def test_get_hypervisor_list_details(self):
44 # Display the details of the all hypervisor
ghanshyam2dfd0532015-08-18 17:18:40 +090045 hypers = self.client.list_hypervisors(detail=True)['hypervisors']
Sean Dague1c408f52013-12-12 16:46:32 -050046 self.assertHypervisors(hypers)
Tony Yang3d5f1632013-06-06 14:17:57 +080047
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080048 @decorators.idempotent_id('94ff9eae-a183-428e-9cdb-79fde71211cc')
Tony Yang3d5f1632013-06-06 14:17:57 +080049 def test_get_hypervisor_show_details(self):
50 # Display the details of the specified hypervisor
51 hypers = self._list_hypervisors()
Sean Dague1c408f52013-12-12 16:46:32 -050052 self.assertHypervisors(hypers)
Tony Yang3d5f1632013-06-06 14:17:57 +080053
ghanshyam2dfd0532015-08-18 17:18:40 +090054 details = self.client.show_hypervisor(hypers[0]['id'])['hypervisor']
zhufl080dcfb2016-10-21 17:45:38 +080055 self.assertGreater(len(details), 0)
Tony Yang3d5f1632013-06-06 14:17:57 +080056 self.assertEqual(details['hypervisor_hostname'],
57 hypers[0]['hypervisor_hostname'])
58
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080059 @decorators.idempotent_id('e81bba3f-6215-4e39-a286-d52d2f906862')
Tony Yang3d5f1632013-06-06 14:17:57 +080060 def test_get_hypervisor_show_servers(self):
61 # Show instances about the specific hypervisors
62 hypers = self._list_hypervisors()
Sean Dague1c408f52013-12-12 16:46:32 -050063 self.assertHypervisors(hypers)
Tony Yang3d5f1632013-06-06 14:17:57 +080064
65 hostname = hypers[0]['hypervisor_hostname']
ghanshyam2dfd0532015-08-18 17:18:40 +090066 hypervisors = (self.client.list_servers_on_hypervisor(hostname)
67 ['hypervisors'])
zhufl080dcfb2016-10-21 17:45:38 +080068 self.assertGreater(len(hypervisors), 0)
Tony Yang3d5f1632013-06-06 14:17:57 +080069
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080070 @decorators.idempotent_id('797e4f28-b6e0-454d-a548-80cc77c00816')
Tony Yang3d5f1632013-06-06 14:17:57 +080071 def test_get_hypervisor_stats(self):
72 # Verify the stats of the all hypervisor
ghanshyam2dfd0532015-08-18 17:18:40 +090073 stats = (self.client.show_hypervisor_statistics()
74 ['hypervisor_statistics'])
zhufl080dcfb2016-10-21 17:45:38 +080075 self.assertGreater(len(stats), 0)
Tony Yang3d5f1632013-06-06 14:17:57 +080076
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080077 @decorators.idempotent_id('91a50d7d-1c2b-4f24-b55a-a1fe20efca70')
Tony Yang3d5f1632013-06-06 14:17:57 +080078 def test_get_hypervisor_uptime(self):
79 # Verify that GET shows the specified hypervisor uptime
80 hypers = self._list_hypervisors()
81
David Shrewsbury152b7812014-07-07 16:56:16 -040082 # Ironic will register each baremetal node as a 'hypervisor',
83 # so the hypervisor list can contain many hypervisors of type
84 # 'ironic'. If they are ALL ironic, skip this test since ironic
85 # doesn't support hypervisor uptime. Otherwise, remove them
86 # from the list of hypervisors to test.
87 ironic_only = True
88 hypers_without_ironic = []
Sean Dague1c408f52013-12-12 16:46:32 -050089 for hyper in hypers:
zhufle9260e22016-12-07 11:55:33 +080090 details = (self.client.show_hypervisor(hyper['id'])
ghanshyam2dfd0532015-08-18 17:18:40 +090091 ['hypervisor'])
David Shrewsbury152b7812014-07-07 16:56:16 -040092 if details['hypervisor_type'] != 'ironic':
93 hypers_without_ironic.append(hyper)
94 ironic_only = False
95
96 if ironic_only:
97 raise self.skipException(
98 "Ironic does not support hypervisor uptime")
99
100 has_valid_uptime = False
101 for hyper in hypers_without_ironic:
Sean Dague1c408f52013-12-12 16:46:32 -0500102 # because hypervisors might be disabled, this loops looking
103 # for any good hit.
104 try:
ghanshyam2dfd0532015-08-18 17:18:40 +0900105 uptime = (self.client.show_hypervisor_uptime(hyper['id'])
106 ['hypervisor'])
Masayuki Igawa0c0f0142017-04-10 17:22:02 +0900107 if uptime:
Sean Dague1c408f52013-12-12 16:46:32 -0500108 has_valid_uptime = True
109 break
110 except Exception:
111 pass
112 self.assertTrue(
113 has_valid_uptime,
114 "None of the hypervisors had a valid uptime: %s" % hypers)
Tony Yang3d5f1632013-06-06 14:17:57 +0800115
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -0800116 @decorators.idempotent_id('d7e1805b-3b14-4a3b-b6fd-50ec6d9f361f')
Lingxian Kong1629d5d2013-10-05 17:12:29 +0800117 def test_search_hypervisor(self):
118 hypers = self._list_hypervisors()
Sean Dague1c408f52013-12-12 16:46:32 -0500119 self.assertHypervisors(hypers)
David Kranz0a735172015-01-16 10:51:18 -0500120 hypers = self.client.search_hypervisor(
ghanshyam2dfd0532015-08-18 17:18:40 +0900121 hypers[0]['hypervisor_hostname'])['hypervisors']
Sean Dague1c408f52013-12-12 16:46:32 -0500122 self.assertHypervisors(hypers)