blob: fbfef87746e93e1c702de21683416dc3ebd48bbc [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
Masayuki Igawa394d8d92014-03-04 17:21:56 +090017from tempest import test
Tony Yang3d5f1632013-06-06 14:17:57 +080018
19
ivan-zhuf2b00502013-10-18 10:06:52 +080020class HypervisorAdminTestJSON(base.BaseV2ComputeAdminTest):
Tony Yang3d5f1632013-06-06 14:17:57 +080021
22 """
23 Tests Hypervisors API that require admin privileges
24 """
25
Tony Yang3d5f1632013-06-06 14:17:57 +080026 @classmethod
Andrea Frittoli50bb80d2014-09-15 12:34:27 +010027 def resource_setup(cls):
28 super(HypervisorAdminTestJSON, cls).resource_setup()
Tony Yang3d5f1632013-06-06 14:17:57 +080029 cls.client = cls.os_adm.hypervisor_client
Tony Yang3d5f1632013-06-06 14:17:57 +080030
31 def _list_hypervisors(self):
32 # List of hypervisors
David Kranz0a735172015-01-16 10:51:18 -050033 hypers = self.client.get_hypervisor_list()
Tony Yang3d5f1632013-06-06 14:17:57 +080034 return hypers
35
Sean Dague1c408f52013-12-12 16:46:32 -050036 def assertHypervisors(self, hypers):
37 self.assertTrue(len(hypers) > 0, "No hypervisors found: %s" % hypers)
38
Masayuki Igawa394d8d92014-03-04 17:21:56 +090039 @test.attr(type='gate')
Tony Yang3d5f1632013-06-06 14:17:57 +080040 def test_get_hypervisor_list(self):
41 # List of hypervisor and available hypervisors hostname
42 hypers = self._list_hypervisors()
Sean Dague1c408f52013-12-12 16:46:32 -050043 self.assertHypervisors(hypers)
Tony Yang3d5f1632013-06-06 14:17:57 +080044
Masayuki Igawa394d8d92014-03-04 17:21:56 +090045 @test.attr(type='gate')
Tony Yang3d5f1632013-06-06 14:17:57 +080046 def test_get_hypervisor_list_details(self):
47 # Display the details of the all hypervisor
David Kranz0a735172015-01-16 10:51:18 -050048 hypers = self.client.get_hypervisor_list_details()
Sean Dague1c408f52013-12-12 16:46:32 -050049 self.assertHypervisors(hypers)
Tony Yang3d5f1632013-06-06 14:17:57 +080050
Masayuki Igawa394d8d92014-03-04 17:21:56 +090051 @test.attr(type='gate')
Tony Yang3d5f1632013-06-06 14:17:57 +080052 def test_get_hypervisor_show_details(self):
53 # Display the details of the specified hypervisor
54 hypers = self._list_hypervisors()
Sean Dague1c408f52013-12-12 16:46:32 -050055 self.assertHypervisors(hypers)
Tony Yang3d5f1632013-06-06 14:17:57 +080056
David Kranz0a735172015-01-16 10:51:18 -050057 details = self.client.get_hypervisor_show_details(hypers[0]['id'])
Tony Yang3d5f1632013-06-06 14:17:57 +080058 self.assertTrue(len(details) > 0)
59 self.assertEqual(details['hypervisor_hostname'],
60 hypers[0]['hypervisor_hostname'])
61
Masayuki Igawa394d8d92014-03-04 17:21:56 +090062 @test.attr(type='gate')
Tony Yang3d5f1632013-06-06 14:17:57 +080063 def test_get_hypervisor_show_servers(self):
64 # Show instances about the specific hypervisors
65 hypers = self._list_hypervisors()
Sean Dague1c408f52013-12-12 16:46:32 -050066 self.assertHypervisors(hypers)
Tony Yang3d5f1632013-06-06 14:17:57 +080067
68 hostname = hypers[0]['hypervisor_hostname']
David Kranz0a735172015-01-16 10:51:18 -050069 hypervisors = self.client.get_hypervisor_servers(hostname)
Tony Yang3d5f1632013-06-06 14:17:57 +080070 self.assertTrue(len(hypervisors) > 0)
71
Masayuki Igawa394d8d92014-03-04 17:21:56 +090072 @test.attr(type='gate')
Tony Yang3d5f1632013-06-06 14:17:57 +080073 def test_get_hypervisor_stats(self):
74 # Verify the stats of the all hypervisor
David Kranz0a735172015-01-16 10:51:18 -050075 stats = self.client.get_hypervisor_stats()
Tony Yang3d5f1632013-06-06 14:17:57 +080076 self.assertTrue(len(stats) > 0)
77
Masayuki Igawa394d8d92014-03-04 17:21:56 +090078 @test.attr(type='gate')
Tony Yang3d5f1632013-06-06 14:17:57 +080079 def test_get_hypervisor_uptime(self):
80 # Verify that GET shows the specified hypervisor uptime
81 hypers = self._list_hypervisors()
82
David Shrewsbury152b7812014-07-07 16:56:16 -040083 # Ironic will register each baremetal node as a 'hypervisor',
84 # so the hypervisor list can contain many hypervisors of type
85 # 'ironic'. If they are ALL ironic, skip this test since ironic
86 # doesn't support hypervisor uptime. Otherwise, remove them
87 # from the list of hypervisors to test.
88 ironic_only = True
89 hypers_without_ironic = []
Sean Dague1c408f52013-12-12 16:46:32 -050090 for hyper in hypers:
David Kranz0a735172015-01-16 10:51:18 -050091 details = self.client.get_hypervisor_show_details(hypers[0]['id'])
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:
David Kranz0a735172015-01-16 10:51:18 -0500105 uptime = self.client.get_hypervisor_uptime(hyper['id'])
106 if len(uptime) > 0:
Sean Dague1c408f52013-12-12 16:46:32 -0500107 has_valid_uptime = True
108 break
109 except Exception:
110 pass
111 self.assertTrue(
112 has_valid_uptime,
113 "None of the hypervisors had a valid uptime: %s" % hypers)
Tony Yang3d5f1632013-06-06 14:17:57 +0800114
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900115 @test.attr(type='gate')
Lingxian Kong1629d5d2013-10-05 17:12:29 +0800116 def test_search_hypervisor(self):
117 hypers = self._list_hypervisors()
Sean Dague1c408f52013-12-12 16:46:32 -0500118 self.assertHypervisors(hypers)
David Kranz0a735172015-01-16 10:51:18 -0500119 hypers = self.client.search_hypervisor(
Lingxian Kong1629d5d2013-10-05 17:12:29 +0800120 hypers[0]['hypervisor_hostname'])
Sean Dague1c408f52013-12-12 16:46:32 -0500121 self.assertHypervisors(hypers)