blob: 85b26a1746978a795d84e4fdae34f926c826f682 [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
27 def setUpClass(cls):
28 super(HypervisorAdminTestJSON, cls).setUpClass()
29 cls.client = cls.os_adm.hypervisor_client
Tony Yang3d5f1632013-06-06 14:17:57 +080030
31 def _list_hypervisors(self):
32 # List of hypervisors
33 resp, hypers = self.client.get_hypervisor_list()
34 self.assertEqual(200, resp.status)
35 return hypers
36
Sean Dague1c408f52013-12-12 16:46:32 -050037 def assertHypervisors(self, hypers):
38 self.assertTrue(len(hypers) > 0, "No hypervisors found: %s" % hypers)
39
Masayuki Igawa394d8d92014-03-04 17:21:56 +090040 @test.attr(type='gate')
Tony Yang3d5f1632013-06-06 14:17:57 +080041 def test_get_hypervisor_list(self):
42 # List of hypervisor and available hypervisors hostname
43 hypers = self._list_hypervisors()
Sean Dague1c408f52013-12-12 16:46:32 -050044 self.assertHypervisors(hypers)
Tony Yang3d5f1632013-06-06 14:17:57 +080045
Masayuki Igawa394d8d92014-03-04 17:21:56 +090046 @test.attr(type='gate')
Tony Yang3d5f1632013-06-06 14:17:57 +080047 def test_get_hypervisor_list_details(self):
48 # Display the details of the all hypervisor
49 resp, hypers = self.client.get_hypervisor_list_details()
50 self.assertEqual(200, resp.status)
Sean Dague1c408f52013-12-12 16:46:32 -050051 self.assertHypervisors(hypers)
Tony Yang3d5f1632013-06-06 14:17:57 +080052
Masayuki Igawa394d8d92014-03-04 17:21:56 +090053 @test.attr(type='gate')
Tony Yang3d5f1632013-06-06 14:17:57 +080054 def test_get_hypervisor_show_details(self):
55 # Display the details of the specified hypervisor
56 hypers = self._list_hypervisors()
Sean Dague1c408f52013-12-12 16:46:32 -050057 self.assertHypervisors(hypers)
Tony Yang3d5f1632013-06-06 14:17:57 +080058
59 resp, details = (self.client.
60 get_hypervisor_show_details(hypers[0]['id']))
61 self.assertEqual(200, resp.status)
62 self.assertTrue(len(details) > 0)
63 self.assertEqual(details['hypervisor_hostname'],
64 hypers[0]['hypervisor_hostname'])
65
Masayuki Igawa394d8d92014-03-04 17:21:56 +090066 @test.attr(type='gate')
Tony Yang3d5f1632013-06-06 14:17:57 +080067 def test_get_hypervisor_show_servers(self):
68 # Show instances about the specific hypervisors
69 hypers = self._list_hypervisors()
Sean Dague1c408f52013-12-12 16:46:32 -050070 self.assertHypervisors(hypers)
Tony Yang3d5f1632013-06-06 14:17:57 +080071
72 hostname = hypers[0]['hypervisor_hostname']
73 resp, hypervisors = self.client.get_hypervisor_servers(hostname)
74 self.assertEqual(200, resp.status)
75 self.assertTrue(len(hypervisors) > 0)
76
Masayuki Igawa394d8d92014-03-04 17:21:56 +090077 @test.attr(type='gate')
Tony Yang3d5f1632013-06-06 14:17:57 +080078 def test_get_hypervisor_stats(self):
79 # Verify the stats of the all hypervisor
80 resp, stats = self.client.get_hypervisor_stats()
81 self.assertEqual(200, resp.status)
82 self.assertTrue(len(stats) > 0)
83
Masayuki Igawa394d8d92014-03-04 17:21:56 +090084 @test.attr(type='gate')
Tony Yang3d5f1632013-06-06 14:17:57 +080085 def test_get_hypervisor_uptime(self):
86 # Verify that GET shows the specified hypervisor uptime
87 hypers = self._list_hypervisors()
88
David Shrewsbury152b7812014-07-07 16:56:16 -040089 # Ironic will register each baremetal node as a 'hypervisor',
90 # so the hypervisor list can contain many hypervisors of type
91 # 'ironic'. If they are ALL ironic, skip this test since ironic
92 # doesn't support hypervisor uptime. Otherwise, remove them
93 # from the list of hypervisors to test.
94 ironic_only = True
95 hypers_without_ironic = []
Sean Dague1c408f52013-12-12 16:46:32 -050096 for hyper in hypers:
David Shrewsbury152b7812014-07-07 16:56:16 -040097 resp, details = (self.client.
98 get_hypervisor_show_details(hypers[0]['id']))
99 self.assertEqual(200, resp.status)
100 if details['hypervisor_type'] != 'ironic':
101 hypers_without_ironic.append(hyper)
102 ironic_only = False
103
104 if ironic_only:
105 raise self.skipException(
106 "Ironic does not support hypervisor uptime")
107
108 has_valid_uptime = False
109 for hyper in hypers_without_ironic:
Sean Dague1c408f52013-12-12 16:46:32 -0500110 # because hypervisors might be disabled, this loops looking
111 # for any good hit.
112 try:
113 resp, uptime = self.client.get_hypervisor_uptime(hyper['id'])
114 if (resp.status == 200) and (len(uptime) > 0):
115 has_valid_uptime = True
116 break
117 except Exception:
118 pass
119 self.assertTrue(
120 has_valid_uptime,
121 "None of the hypervisors had a valid uptime: %s" % hypers)
Tony Yang3d5f1632013-06-06 14:17:57 +0800122
Masayuki Igawa394d8d92014-03-04 17:21:56 +0900123 @test.attr(type='gate')
Lingxian Kong1629d5d2013-10-05 17:12:29 +0800124 def test_search_hypervisor(self):
125 hypers = self._list_hypervisors()
Sean Dague1c408f52013-12-12 16:46:32 -0500126 self.assertHypervisors(hypers)
Lingxian Kong1629d5d2013-10-05 17:12:29 +0800127 resp, hypers = self.client.search_hypervisor(
128 hypers[0]['hypervisor_hostname'])
129 self.assertEqual(200, resp.status)
Sean Dague1c408f52013-12-12 16:46:32 -0500130 self.assertHypervisors(hypers)
Tony Yang3d5f1632013-06-06 14:17:57 +0800131
132
133class HypervisorAdminTestXML(HypervisorAdminTestJSON):
134 _interface = 'xml'