blob: 47f66af76c5403cd91641a41514ecba923540d81 [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
Rohan Kanade60b73092015-02-04 17:58:19 +053027 def setup_clients(cls):
28 super(HypervisorAdminTestJSON, cls).setup_clients()
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
Ken'ichi Ohmichi394e6e42015-06-11 04:20:37 +000033 hypers = self.client.list_hypervisors()
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
Chris Hoge7579c1a2015-02-26 14:12:15 -080039 @test.idempotent_id('7f0ceacd-c64d-4e96-b8ee-d02943142cc5')
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
Chris Hoge7579c1a2015-02-26 14:12:15 -080045 @test.idempotent_id('1e7fdac2-b672-4ad1-97a4-bad0e3030118')
Tony Yang3d5f1632013-06-06 14:17:57 +080046 def test_get_hypervisor_list_details(self):
47 # Display the details of the all hypervisor
Ken'ichi Ohmichi394e6e42015-06-11 04:20:37 +000048 hypers = self.client.list_hypervisors(detail=True)
Sean Dague1c408f52013-12-12 16:46:32 -050049 self.assertHypervisors(hypers)
Tony Yang3d5f1632013-06-06 14:17:57 +080050
Chris Hoge7579c1a2015-02-26 14:12:15 -080051 @test.idempotent_id('94ff9eae-a183-428e-9cdb-79fde71211cc')
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
Ken'ichi Ohmichi394e6e42015-06-11 04:20:37 +000057 details = self.client.show_hypervisor(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
Chris Hoge7579c1a2015-02-26 14:12:15 -080062 @test.idempotent_id('e81bba3f-6215-4e39-a286-d52d2f906862')
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']
Ken'ichi Ohmichi394e6e42015-06-11 04:20:37 +000069 hypervisors = self.client.list_servers_on_hypervisor(hostname)
Tony Yang3d5f1632013-06-06 14:17:57 +080070 self.assertTrue(len(hypervisors) > 0)
71
Chris Hoge7579c1a2015-02-26 14:12:15 -080072 @test.idempotent_id('797e4f28-b6e0-454d-a548-80cc77c00816')
Tony Yang3d5f1632013-06-06 14:17:57 +080073 def test_get_hypervisor_stats(self):
74 # Verify the stats of the all hypervisor
Ken'ichi Ohmichi394e6e42015-06-11 04:20:37 +000075 stats = self.client.show_hypervisor_statistics()
Tony Yang3d5f1632013-06-06 14:17:57 +080076 self.assertTrue(len(stats) > 0)
77
Chris Hoge7579c1a2015-02-26 14:12:15 -080078 @test.idempotent_id('91a50d7d-1c2b-4f24-b55a-a1fe20efca70')
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:
Ken'ichi Ohmichi394e6e42015-06-11 04:20:37 +000091 details = self.client.show_hypervisor(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:
Ken'ichi Ohmichi394e6e42015-06-11 04:20:37 +0000105 uptime = self.client.show_hypervisor_uptime(hyper['id'])
David Kranz0a735172015-01-16 10:51:18 -0500106 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
Chris Hoge7579c1a2015-02-26 14:12:15 -0800115 @test.idempotent_id('d7e1805b-3b14-4a3b-b6fd-50ec6d9f361f')
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)