blob: bd431d49cbbc9ac073a70befce9ae7290a7ba750 [file] [log] [blame]
Tony Yang3d5f1632013-06-06 14:17:57 +08001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2013 IBM Corporation
4# All Rights Reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License. You may obtain
8# a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15# License for the specific language governing permissions and limitations
16# under the License.
17
18from tempest.api.compute import base
Tony Yang3d5f1632013-06-06 14:17:57 +080019from tempest.test import attr
20
21
ivan-zhuf2b00502013-10-18 10:06:52 +080022class HypervisorAdminTestJSON(base.BaseV2ComputeAdminTest):
Tony Yang3d5f1632013-06-06 14:17:57 +080023
24 """
25 Tests Hypervisors API that require admin privileges
26 """
27
28 _interface = 'json'
29
30 @classmethod
31 def setUpClass(cls):
32 super(HypervisorAdminTestJSON, cls).setUpClass()
33 cls.client = cls.os_adm.hypervisor_client
Tony Yang3d5f1632013-06-06 14:17:57 +080034
35 def _list_hypervisors(self):
36 # List of hypervisors
37 resp, hypers = self.client.get_hypervisor_list()
38 self.assertEqual(200, resp.status)
39 return hypers
40
Sean Dague1c408f52013-12-12 16:46:32 -050041 def assertHypervisors(self, hypers):
42 self.assertTrue(len(hypers) > 0, "No hypervisors found: %s" % hypers)
43
Attila Fazekasaa04d612013-08-12 17:49:46 +020044 @attr(type='gate')
Tony Yang3d5f1632013-06-06 14:17:57 +080045 def test_get_hypervisor_list(self):
46 # List of hypervisor and available hypervisors hostname
47 hypers = self._list_hypervisors()
Sean Dague1c408f52013-12-12 16:46:32 -050048 self.assertHypervisors(hypers)
Tony Yang3d5f1632013-06-06 14:17:57 +080049
Attila Fazekasaa04d612013-08-12 17:49:46 +020050 @attr(type='gate')
Tony Yang3d5f1632013-06-06 14:17:57 +080051 def test_get_hypervisor_list_details(self):
52 # Display the details of the all hypervisor
53 resp, hypers = self.client.get_hypervisor_list_details()
54 self.assertEqual(200, resp.status)
Sean Dague1c408f52013-12-12 16:46:32 -050055 self.assertHypervisors(hypers)
Tony Yang3d5f1632013-06-06 14:17:57 +080056
Attila Fazekasaa04d612013-08-12 17:49:46 +020057 @attr(type='gate')
Tony Yang3d5f1632013-06-06 14:17:57 +080058 def test_get_hypervisor_show_details(self):
59 # Display the details of the specified hypervisor
60 hypers = self._list_hypervisors()
Sean Dague1c408f52013-12-12 16:46:32 -050061 self.assertHypervisors(hypers)
Tony Yang3d5f1632013-06-06 14:17:57 +080062
63 resp, details = (self.client.
64 get_hypervisor_show_details(hypers[0]['id']))
65 self.assertEqual(200, resp.status)
66 self.assertTrue(len(details) > 0)
67 self.assertEqual(details['hypervisor_hostname'],
68 hypers[0]['hypervisor_hostname'])
69
Attila Fazekasaa04d612013-08-12 17:49:46 +020070 @attr(type='gate')
Tony Yang3d5f1632013-06-06 14:17:57 +080071 def test_get_hypervisor_show_servers(self):
72 # Show instances about the specific hypervisors
73 hypers = self._list_hypervisors()
Sean Dague1c408f52013-12-12 16:46:32 -050074 self.assertHypervisors(hypers)
Tony Yang3d5f1632013-06-06 14:17:57 +080075
76 hostname = hypers[0]['hypervisor_hostname']
77 resp, hypervisors = self.client.get_hypervisor_servers(hostname)
78 self.assertEqual(200, resp.status)
79 self.assertTrue(len(hypervisors) > 0)
80
Attila Fazekasaa04d612013-08-12 17:49:46 +020081 @attr(type='gate')
Tony Yang3d5f1632013-06-06 14:17:57 +080082 def test_get_hypervisor_stats(self):
83 # Verify the stats of the all hypervisor
84 resp, stats = self.client.get_hypervisor_stats()
85 self.assertEqual(200, resp.status)
86 self.assertTrue(len(stats) > 0)
87
Attila Fazekasaa04d612013-08-12 17:49:46 +020088 @attr(type='gate')
Tony Yang3d5f1632013-06-06 14:17:57 +080089 def test_get_hypervisor_uptime(self):
90 # Verify that GET shows the specified hypervisor uptime
91 hypers = self._list_hypervisors()
92
Sean Dague1c408f52013-12-12 16:46:32 -050093 has_valid_uptime = False
94 for hyper in hypers:
95 # because hypervisors might be disabled, this loops looking
96 # for any good hit.
97 try:
98 resp, uptime = self.client.get_hypervisor_uptime(hyper['id'])
99 if (resp.status == 200) and (len(uptime) > 0):
100 has_valid_uptime = True
101 break
102 except Exception:
103 pass
104 self.assertTrue(
105 has_valid_uptime,
106 "None of the hypervisors had a valid uptime: %s" % hypers)
Tony Yang3d5f1632013-06-06 14:17:57 +0800107
Lingxian Kong1629d5d2013-10-05 17:12:29 +0800108 @attr(type='gate')
109 def test_search_hypervisor(self):
110 hypers = self._list_hypervisors()
Sean Dague1c408f52013-12-12 16:46:32 -0500111 self.assertHypervisors(hypers)
Lingxian Kong1629d5d2013-10-05 17:12:29 +0800112 resp, hypers = self.client.search_hypervisor(
113 hypers[0]['hypervisor_hostname'])
114 self.assertEqual(200, resp.status)
Sean Dague1c408f52013-12-12 16:46:32 -0500115 self.assertHypervisors(hypers)
Tony Yang3d5f1632013-06-06 14:17:57 +0800116
117
118class HypervisorAdminTestXML(HypervisorAdminTestJSON):
119 _interface = 'xml'