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 |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 17 | from tempest.lib import decorators |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 18 | |
| 19 | |
zhufl | 021e66b | 2018-02-07 14:26:49 +0800 | [diff] [blame] | 20 | class HypervisorAdminTestBase(base.BaseV2ComputeAdminTest): |
Ken'ichi Ohmichi | 88363cb | 2015-11-19 08:00:54 +0000 | [diff] [blame] | 21 | """Tests Hypervisors API that require admin privileges""" |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 22 | |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 23 | @classmethod |
Rohan Kanade | 60b7309 | 2015-02-04 17:58:19 +0530 | [diff] [blame] | 24 | def setup_clients(cls): |
zhufl | 021e66b | 2018-02-07 14:26:49 +0800 | [diff] [blame] | 25 | super(HypervisorAdminTestBase, cls).setup_clients() |
Jordan Pittier | 8160d31 | 2017-04-18 11:52:23 +0200 | [diff] [blame] | 26 | cls.client = cls.os_admin.hypervisor_client |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 27 | |
| 28 | def _list_hypervisors(self): |
| 29 | # List of hypervisors |
ghanshyam | 2dfd053 | 2015-08-18 17:18:40 +0900 | [diff] [blame] | 30 | hypers = self.client.list_hypervisors()['hypervisors'] |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 31 | return hypers |
| 32 | |
zhufl | 021e66b | 2018-02-07 14:26:49 +0800 | [diff] [blame] | 33 | |
| 34 | class HypervisorAdminTestJSON(HypervisorAdminTestBase): |
| 35 | """Tests Hypervisors API that require admin privileges""" |
| 36 | |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 37 | @decorators.idempotent_id('7f0ceacd-c64d-4e96-b8ee-d02943142cc5') |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 38 | def test_get_hypervisor_list(self): |
zhufl | a0e87dc | 2020-05-13 15:52:15 +0800 | [diff] [blame] | 39 | """List of hypervisor and available hypervisors hostname""" |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 40 | hypers = self._list_hypervisors() |
zhufl | cfa1cd5 | 2017-08-10 10:23:01 +0800 | [diff] [blame] | 41 | self.assertNotEmpty(hypers, "No hypervisors found.") |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 42 | |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 43 | @decorators.idempotent_id('1e7fdac2-b672-4ad1-97a4-bad0e3030118') |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 44 | def test_get_hypervisor_list_details(self): |
zhufl | a0e87dc | 2020-05-13 15:52:15 +0800 | [diff] [blame] | 45 | """Display the details of the all hypervisor""" |
ghanshyam | 2dfd053 | 2015-08-18 17:18:40 +0900 | [diff] [blame] | 46 | hypers = self.client.list_hypervisors(detail=True)['hypervisors'] |
zhufl | cfa1cd5 | 2017-08-10 10:23:01 +0800 | [diff] [blame] | 47 | self.assertNotEmpty(hypers, "No hypervisors found.") |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 48 | |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 49 | @decorators.idempotent_id('94ff9eae-a183-428e-9cdb-79fde71211cc') |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 50 | def test_get_hypervisor_show_details(self): |
zhufl | a0e87dc | 2020-05-13 15:52:15 +0800 | [diff] [blame] | 51 | """Display the details of the specified hypervisor""" |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 52 | hypers = self._list_hypervisors() |
zhufl | cfa1cd5 | 2017-08-10 10:23:01 +0800 | [diff] [blame] | 53 | self.assertNotEmpty(hypers, "No hypervisors found.") |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 54 | |
ghanshyam | 2dfd053 | 2015-08-18 17:18:40 +0900 | [diff] [blame] | 55 | details = self.client.show_hypervisor(hypers[0]['id'])['hypervisor'] |
Masayuki Igawa | f9009b4 | 2017-04-10 14:49:29 +0900 | [diff] [blame] | 56 | self.assertNotEmpty(details) |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 57 | self.assertEqual(details['hypervisor_hostname'], |
| 58 | hypers[0]['hypervisor_hostname']) |
| 59 | |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 60 | @decorators.idempotent_id('797e4f28-b6e0-454d-a548-80cc77c00816') |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 61 | def test_get_hypervisor_stats(self): |
zhufl | a0e87dc | 2020-05-13 15:52:15 +0800 | [diff] [blame] | 62 | """Verify the stats of the all hypervisor""" |
ghanshyam | 2dfd053 | 2015-08-18 17:18:40 +0900 | [diff] [blame] | 63 | stats = (self.client.show_hypervisor_statistics() |
| 64 | ['hypervisor_statistics']) |
Masayuki Igawa | f9009b4 | 2017-04-10 14:49:29 +0900 | [diff] [blame] | 65 | self.assertNotEmpty(stats) |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 66 | |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 67 | @decorators.idempotent_id('91a50d7d-1c2b-4f24-b55a-a1fe20efca70') |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 68 | def test_get_hypervisor_uptime(self): |
zhufl | a0e87dc | 2020-05-13 15:52:15 +0800 | [diff] [blame] | 69 | """Verify that GET shows the specified hypervisor uptime""" |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 70 | hypers = self._list_hypervisors() |
| 71 | |
David Shrewsbury | 152b781 | 2014-07-07 16:56:16 -0400 | [diff] [blame] | 72 | # Ironic will register each baremetal node as a 'hypervisor', |
| 73 | # so the hypervisor list can contain many hypervisors of type |
| 74 | # 'ironic'. If they are ALL ironic, skip this test since ironic |
| 75 | # doesn't support hypervisor uptime. Otherwise, remove them |
| 76 | # from the list of hypervisors to test. |
| 77 | ironic_only = True |
| 78 | hypers_without_ironic = [] |
Sean Dague | 1c408f5 | 2013-12-12 16:46:32 -0500 | [diff] [blame] | 79 | for hyper in hypers: |
zhufl | e9260e2 | 2016-12-07 11:55:33 +0800 | [diff] [blame] | 80 | details = (self.client.show_hypervisor(hyper['id']) |
ghanshyam | 2dfd053 | 2015-08-18 17:18:40 +0900 | [diff] [blame] | 81 | ['hypervisor']) |
zhufl | c7d65d1 | 2018-09-04 16:48:31 +0800 | [diff] [blame] | 82 | if (details['hypervisor_type'] != 'ironic' and |
| 83 | details['state'] == 'up'): |
David Shrewsbury | 152b781 | 2014-07-07 16:56:16 -0400 | [diff] [blame] | 84 | hypers_without_ironic.append(hyper) |
| 85 | ironic_only = False |
| 86 | |
| 87 | if ironic_only: |
| 88 | raise self.skipException( |
| 89 | "Ironic does not support hypervisor uptime") |
| 90 | |
| 91 | has_valid_uptime = False |
| 92 | for hyper in hypers_without_ironic: |
Sean Dague | 1c408f5 | 2013-12-12 16:46:32 -0500 | [diff] [blame] | 93 | # because hypervisors might be disabled, this loops looking |
| 94 | # for any good hit. |
| 95 | try: |
ghanshyam | 2dfd053 | 2015-08-18 17:18:40 +0900 | [diff] [blame] | 96 | uptime = (self.client.show_hypervisor_uptime(hyper['id']) |
| 97 | ['hypervisor']) |
Masayuki Igawa | 0c0f014 | 2017-04-10 17:22:02 +0900 | [diff] [blame] | 98 | if uptime: |
Sean Dague | 1c408f5 | 2013-12-12 16:46:32 -0500 | [diff] [blame] | 99 | has_valid_uptime = True |
| 100 | break |
| 101 | except Exception: |
| 102 | pass |
| 103 | self.assertTrue( |
| 104 | has_valid_uptime, |
| 105 | "None of the hypervisors had a valid uptime: %s" % hypers) |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 106 | |
zhufl | 021e66b | 2018-02-07 14:26:49 +0800 | [diff] [blame] | 107 | |
zhufl | e142f54 | 2018-08-01 14:08:52 +0800 | [diff] [blame] | 108 | class HypervisorAdminV228Test(HypervisorAdminTestBase): |
zhufl | a0e87dc | 2020-05-13 15:52:15 +0800 | [diff] [blame] | 109 | """Tests Hypervisors API higher than 2.27 that require admin privileges""" |
| 110 | |
zhufl | e142f54 | 2018-08-01 14:08:52 +0800 | [diff] [blame] | 111 | min_microversion = '2.28' |
| 112 | |
| 113 | @decorators.idempotent_id('d46bab64-0fbe-4eb8-9133-e6ee56188cc5') |
| 114 | def test_get_list_hypervisor_details(self): |
zhufl | a0e87dc | 2020-05-13 15:52:15 +0800 | [diff] [blame] | 115 | """Test listing and showing hypervisor details""" |
zhufl | e142f54 | 2018-08-01 14:08:52 +0800 | [diff] [blame] | 116 | # NOTE(zhufl): This test tests the hypervisor APIs response schema |
| 117 | # for 2.28 microversion. No specific assert or behaviour verification |
| 118 | # is needed. |
| 119 | hypers = self._list_hypervisors() |
| 120 | self.assertNotEmpty(hypers, "No hypervisors found.") |
| 121 | self.client.show_hypervisor(hypers[0]['id']) |
| 122 | |
| 123 | |
zhufl | 021e66b | 2018-02-07 14:26:49 +0800 | [diff] [blame] | 124 | class HypervisorAdminUnderV252Test(HypervisorAdminTestBase): |
zhufl | a0e87dc | 2020-05-13 15:52:15 +0800 | [diff] [blame] | 125 | """Tests Hypervisors API below 2.53 that require admin privileges""" |
| 126 | |
zhufl | 021e66b | 2018-02-07 14:26:49 +0800 | [diff] [blame] | 127 | max_microversion = '2.52' |
| 128 | |
| 129 | @decorators.idempotent_id('e81bba3f-6215-4e39-a286-d52d2f906862') |
| 130 | def test_get_hypervisor_show_servers(self): |
zhufl | a0e87dc | 2020-05-13 15:52:15 +0800 | [diff] [blame] | 131 | """Test showing instances about the specific hypervisors""" |
zhufl | 021e66b | 2018-02-07 14:26:49 +0800 | [diff] [blame] | 132 | hypers = self._list_hypervisors() |
| 133 | self.assertNotEmpty(hypers, "No hypervisors found.") |
| 134 | |
| 135 | hostname = hypers[0]['hypervisor_hostname'] |
| 136 | hypervisors = (self.client.list_servers_on_hypervisor(hostname) |
| 137 | ['hypervisors']) |
| 138 | self.assertNotEmpty(hypervisors) |
| 139 | |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 140 | @decorators.idempotent_id('d7e1805b-3b14-4a3b-b6fd-50ec6d9f361f') |
Lingxian Kong | 1629d5d | 2013-10-05 17:12:29 +0800 | [diff] [blame] | 141 | def test_search_hypervisor(self): |
zhufl | a0e87dc | 2020-05-13 15:52:15 +0800 | [diff] [blame] | 142 | """Test searching for hypervisors by its name""" |
Lingxian Kong | 1629d5d | 2013-10-05 17:12:29 +0800 | [diff] [blame] | 143 | hypers = self._list_hypervisors() |
zhufl | cfa1cd5 | 2017-08-10 10:23:01 +0800 | [diff] [blame] | 144 | self.assertNotEmpty(hypers, "No hypervisors found.") |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 145 | hypers = self.client.search_hypervisor( |
ghanshyam | 2dfd053 | 2015-08-18 17:18:40 +0900 | [diff] [blame] | 146 | hypers[0]['hypervisor_hostname'])['hypervisors'] |
zhufl | cfa1cd5 | 2017-08-10 10:23:01 +0800 | [diff] [blame] | 147 | self.assertNotEmpty(hypers, "No hypervisors found.") |
zhufl | 6bc98cc | 2020-06-22 11:15:05 +0800 | [diff] [blame] | 148 | |
| 149 | |
| 150 | class HypervisorAdminV253TestBase(base.BaseV2ComputeAdminTest): |
| 151 | """Tests Hypervisors API above 2.53 that require admin privileges""" |
| 152 | |
| 153 | min_microversion = '2.53' |
| 154 | |
| 155 | @classmethod |
| 156 | def setup_clients(cls): |
| 157 | super(HypervisorAdminV253TestBase, cls).setup_clients() |
| 158 | cls.client = cls.os_admin.hypervisor_client |
| 159 | |
| 160 | @decorators.idempotent_id('4ab54a14-77a2-4e39-b9d2-1306d157c705') |
| 161 | def test_list_show_detail_hypervisors(self): |
| 162 | """Verify the list, list details, and show hypevisors |
| 163 | |
| 164 | This verify the Hypervisor API response schema with v2.53 microversion |
| 165 | """ |
| 166 | self.client.list_hypervisors( |
| 167 | detail=True, with_servers=True)['hypervisors'] |
| 168 | hypers = self.client.list_hypervisors(with_servers=True)['hypervisors'] |
| 169 | self.client.show_hypervisor( |
| 170 | hypers[0]['id'], with_servers=True)['hypervisor'] |