Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 1 | # 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 | |
| 16 | from tempest.api.compute import base |
Masayuki Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 17 | from tempest import test |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 18 | |
| 19 | |
ivan-zhu | f2b0050 | 2013-10-18 10:06:52 +0800 | [diff] [blame] | 20 | class HypervisorAdminTestJSON(base.BaseV2ComputeAdminTest): |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 21 | |
| 22 | """ |
| 23 | Tests Hypervisors API that require admin privileges |
| 24 | """ |
| 25 | |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 26 | @classmethod |
Andrea Frittoli | 50bb80d | 2014-09-15 12:34:27 +0100 | [diff] [blame] | 27 | def resource_setup(cls): |
| 28 | super(HypervisorAdminTestJSON, cls).resource_setup() |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 29 | cls.client = cls.os_adm.hypervisor_client |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 30 | |
| 31 | def _list_hypervisors(self): |
| 32 | # List of hypervisors |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame^] | 33 | hypers = self.client.get_hypervisor_list() |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 34 | return hypers |
| 35 | |
Sean Dague | 1c408f5 | 2013-12-12 16:46:32 -0500 | [diff] [blame] | 36 | def assertHypervisors(self, hypers): |
| 37 | self.assertTrue(len(hypers) > 0, "No hypervisors found: %s" % hypers) |
| 38 | |
Masayuki Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 39 | @test.attr(type='gate') |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 40 | def test_get_hypervisor_list(self): |
| 41 | # List of hypervisor and available hypervisors hostname |
| 42 | hypers = self._list_hypervisors() |
Sean Dague | 1c408f5 | 2013-12-12 16:46:32 -0500 | [diff] [blame] | 43 | self.assertHypervisors(hypers) |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 44 | |
Masayuki Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 45 | @test.attr(type='gate') |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 46 | def test_get_hypervisor_list_details(self): |
| 47 | # Display the details of the all hypervisor |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame^] | 48 | hypers = self.client.get_hypervisor_list_details() |
Sean Dague | 1c408f5 | 2013-12-12 16:46:32 -0500 | [diff] [blame] | 49 | self.assertHypervisors(hypers) |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 50 | |
Masayuki Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 51 | @test.attr(type='gate') |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 52 | def test_get_hypervisor_show_details(self): |
| 53 | # Display the details of the specified hypervisor |
| 54 | hypers = self._list_hypervisors() |
Sean Dague | 1c408f5 | 2013-12-12 16:46:32 -0500 | [diff] [blame] | 55 | self.assertHypervisors(hypers) |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 56 | |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame^] | 57 | details = self.client.get_hypervisor_show_details(hypers[0]['id']) |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 58 | self.assertTrue(len(details) > 0) |
| 59 | self.assertEqual(details['hypervisor_hostname'], |
| 60 | hypers[0]['hypervisor_hostname']) |
| 61 | |
Masayuki Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 62 | @test.attr(type='gate') |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 63 | def test_get_hypervisor_show_servers(self): |
| 64 | # Show instances about the specific hypervisors |
| 65 | hypers = self._list_hypervisors() |
Sean Dague | 1c408f5 | 2013-12-12 16:46:32 -0500 | [diff] [blame] | 66 | self.assertHypervisors(hypers) |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 67 | |
| 68 | hostname = hypers[0]['hypervisor_hostname'] |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame^] | 69 | hypervisors = self.client.get_hypervisor_servers(hostname) |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 70 | self.assertTrue(len(hypervisors) > 0) |
| 71 | |
Masayuki Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 72 | @test.attr(type='gate') |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 73 | def test_get_hypervisor_stats(self): |
| 74 | # Verify the stats of the all hypervisor |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame^] | 75 | stats = self.client.get_hypervisor_stats() |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 76 | self.assertTrue(len(stats) > 0) |
| 77 | |
Masayuki Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 78 | @test.attr(type='gate') |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 79 | def test_get_hypervisor_uptime(self): |
| 80 | # Verify that GET shows the specified hypervisor uptime |
| 81 | hypers = self._list_hypervisors() |
| 82 | |
David Shrewsbury | 152b781 | 2014-07-07 16:56:16 -0400 | [diff] [blame] | 83 | # 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 Dague | 1c408f5 | 2013-12-12 16:46:32 -0500 | [diff] [blame] | 90 | for hyper in hypers: |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame^] | 91 | details = self.client.get_hypervisor_show_details(hypers[0]['id']) |
David Shrewsbury | 152b781 | 2014-07-07 16:56:16 -0400 | [diff] [blame] | 92 | 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 Dague | 1c408f5 | 2013-12-12 16:46:32 -0500 | [diff] [blame] | 102 | # because hypervisors might be disabled, this loops looking |
| 103 | # for any good hit. |
| 104 | try: |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame^] | 105 | uptime = self.client.get_hypervisor_uptime(hyper['id']) |
| 106 | if len(uptime) > 0: |
Sean Dague | 1c408f5 | 2013-12-12 16:46:32 -0500 | [diff] [blame] | 107 | 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 Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 114 | |
Masayuki Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 115 | @test.attr(type='gate') |
Lingxian Kong | 1629d5d | 2013-10-05 17:12:29 +0800 | [diff] [blame] | 116 | def test_search_hypervisor(self): |
| 117 | hypers = self._list_hypervisors() |
Sean Dague | 1c408f5 | 2013-12-12 16:46:32 -0500 | [diff] [blame] | 118 | self.assertHypervisors(hypers) |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame^] | 119 | hypers = self.client.search_hypervisor( |
Lingxian Kong | 1629d5d | 2013-10-05 17:12:29 +0800 | [diff] [blame] | 120 | hypers[0]['hypervisor_hostname']) |
Sean Dague | 1c408f5 | 2013-12-12 16:46:32 -0500 | [diff] [blame] | 121 | self.assertHypervisors(hypers) |