blob: 989c0d8c0268ccc2aaa01bd9f0ad0612fe113974 [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
Tony Yang3d5f1632013-06-06 14:17:57 +080017from tempest.test import attr
18
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
26 _interface = 'json'
27
28 @classmethod
29 def setUpClass(cls):
30 super(HypervisorAdminTestJSON, cls).setUpClass()
31 cls.client = cls.os_adm.hypervisor_client
Tony Yang3d5f1632013-06-06 14:17:57 +080032
33 def _list_hypervisors(self):
34 # List of hypervisors
35 resp, hypers = self.client.get_hypervisor_list()
36 self.assertEqual(200, resp.status)
37 return hypers
38
Sean Dague1c408f52013-12-12 16:46:32 -050039 def assertHypervisors(self, hypers):
40 self.assertTrue(len(hypers) > 0, "No hypervisors found: %s" % hypers)
41
Attila Fazekasaa04d612013-08-12 17:49:46 +020042 @attr(type='gate')
Tony Yang3d5f1632013-06-06 14:17:57 +080043 def test_get_hypervisor_list(self):
44 # List of hypervisor and available hypervisors hostname
45 hypers = self._list_hypervisors()
Sean Dague1c408f52013-12-12 16:46:32 -050046 self.assertHypervisors(hypers)
Tony Yang3d5f1632013-06-06 14:17:57 +080047
Attila Fazekasaa04d612013-08-12 17:49:46 +020048 @attr(type='gate')
Tony Yang3d5f1632013-06-06 14:17:57 +080049 def test_get_hypervisor_list_details(self):
50 # Display the details of the all hypervisor
51 resp, hypers = self.client.get_hypervisor_list_details()
52 self.assertEqual(200, resp.status)
Sean Dague1c408f52013-12-12 16:46:32 -050053 self.assertHypervisors(hypers)
Tony Yang3d5f1632013-06-06 14:17:57 +080054
Attila Fazekasaa04d612013-08-12 17:49:46 +020055 @attr(type='gate')
Tony Yang3d5f1632013-06-06 14:17:57 +080056 def test_get_hypervisor_show_details(self):
57 # Display the details of the specified hypervisor
58 hypers = self._list_hypervisors()
Sean Dague1c408f52013-12-12 16:46:32 -050059 self.assertHypervisors(hypers)
Tony Yang3d5f1632013-06-06 14:17:57 +080060
61 resp, details = (self.client.
62 get_hypervisor_show_details(hypers[0]['id']))
63 self.assertEqual(200, resp.status)
64 self.assertTrue(len(details) > 0)
65 self.assertEqual(details['hypervisor_hostname'],
66 hypers[0]['hypervisor_hostname'])
67
Attila Fazekasaa04d612013-08-12 17:49:46 +020068 @attr(type='gate')
Tony Yang3d5f1632013-06-06 14:17:57 +080069 def test_get_hypervisor_show_servers(self):
70 # Show instances about the specific hypervisors
71 hypers = self._list_hypervisors()
Sean Dague1c408f52013-12-12 16:46:32 -050072 self.assertHypervisors(hypers)
Tony Yang3d5f1632013-06-06 14:17:57 +080073
74 hostname = hypers[0]['hypervisor_hostname']
75 resp, hypervisors = self.client.get_hypervisor_servers(hostname)
76 self.assertEqual(200, resp.status)
77 self.assertTrue(len(hypervisors) > 0)
78
Attila Fazekasaa04d612013-08-12 17:49:46 +020079 @attr(type='gate')
Tony Yang3d5f1632013-06-06 14:17:57 +080080 def test_get_hypervisor_stats(self):
81 # Verify the stats of the all hypervisor
82 resp, stats = self.client.get_hypervisor_stats()
83 self.assertEqual(200, resp.status)
84 self.assertTrue(len(stats) > 0)
85
Attila Fazekasaa04d612013-08-12 17:49:46 +020086 @attr(type='gate')
Tony Yang3d5f1632013-06-06 14:17:57 +080087 def test_get_hypervisor_uptime(self):
88 # Verify that GET shows the specified hypervisor uptime
89 hypers = self._list_hypervisors()
90
Sean Dague1c408f52013-12-12 16:46:32 -050091 has_valid_uptime = False
92 for hyper in hypers:
93 # because hypervisors might be disabled, this loops looking
94 # for any good hit.
95 try:
96 resp, uptime = self.client.get_hypervisor_uptime(hyper['id'])
97 if (resp.status == 200) and (len(uptime) > 0):
98 has_valid_uptime = True
99 break
100 except Exception:
101 pass
102 self.assertTrue(
103 has_valid_uptime,
104 "None of the hypervisors had a valid uptime: %s" % hypers)
Tony Yang3d5f1632013-06-06 14:17:57 +0800105
Lingxian Kong1629d5d2013-10-05 17:12:29 +0800106 @attr(type='gate')
107 def test_search_hypervisor(self):
108 hypers = self._list_hypervisors()
Sean Dague1c408f52013-12-12 16:46:32 -0500109 self.assertHypervisors(hypers)
Lingxian Kong1629d5d2013-10-05 17:12:29 +0800110 resp, hypers = self.client.search_hypervisor(
111 hypers[0]['hypervisor_hostname'])
112 self.assertEqual(200, resp.status)
Sean Dague1c408f52013-12-12 16:46:32 -0500113 self.assertHypervisors(hypers)
Tony Yang3d5f1632013-06-06 14:17:57 +0800114
115
116class HypervisorAdminTestXML(HypervisorAdminTestJSON):
117 _interface = 'xml'