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 | |
ivan-zhu | f2b0050 | 2013-10-18 10:06:52 +0800 | [diff] [blame] | 20 | class HypervisorAdminTestJSON(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): |
| 25 | super(HypervisorAdminTestJSON, cls).setup_clients() |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 26 | cls.client = cls.os_adm.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 | |
Sean Dague | 1c408f5 | 2013-12-12 16:46:32 -0500 | [diff] [blame] | 33 | def assertHypervisors(self, hypers): |
Béla Vancsics | 64862f7 | 2016-11-08 09:12:31 +0100 | [diff] [blame] | 34 | self.assertGreater(len(hypers), 0, "No hypervisors found: %s" % hypers) |
Sean Dague | 1c408f5 | 2013-12-12 16:46:32 -0500 | [diff] [blame] | 35 | |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 36 | @decorators.idempotent_id('7f0ceacd-c64d-4e96-b8ee-d02943142cc5') |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 37 | def test_get_hypervisor_list(self): |
| 38 | # List of hypervisor and available hypervisors hostname |
| 39 | hypers = self._list_hypervisors() |
Sean Dague | 1c408f5 | 2013-12-12 16:46:32 -0500 | [diff] [blame] | 40 | self.assertHypervisors(hypers) |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 41 | |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 42 | @decorators.idempotent_id('1e7fdac2-b672-4ad1-97a4-bad0e3030118') |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 43 | def test_get_hypervisor_list_details(self): |
| 44 | # Display the details of the all hypervisor |
ghanshyam | 2dfd053 | 2015-08-18 17:18:40 +0900 | [diff] [blame] | 45 | hypers = self.client.list_hypervisors(detail=True)['hypervisors'] |
Sean Dague | 1c408f5 | 2013-12-12 16:46:32 -0500 | [diff] [blame] | 46 | self.assertHypervisors(hypers) |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 47 | |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 48 | @decorators.idempotent_id('94ff9eae-a183-428e-9cdb-79fde71211cc') |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 49 | def test_get_hypervisor_show_details(self): |
| 50 | # Display the details of the specified hypervisor |
| 51 | hypers = self._list_hypervisors() |
Sean Dague | 1c408f5 | 2013-12-12 16:46:32 -0500 | [diff] [blame] | 52 | self.assertHypervisors(hypers) |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 53 | |
ghanshyam | 2dfd053 | 2015-08-18 17:18:40 +0900 | [diff] [blame] | 54 | details = self.client.show_hypervisor(hypers[0]['id'])['hypervisor'] |
zhufl | 080dcfb | 2016-10-21 17:45:38 +0800 | [diff] [blame] | 55 | self.assertGreater(len(details), 0) |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 56 | self.assertEqual(details['hypervisor_hostname'], |
| 57 | hypers[0]['hypervisor_hostname']) |
| 58 | |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 59 | @decorators.idempotent_id('e81bba3f-6215-4e39-a286-d52d2f906862') |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 60 | def test_get_hypervisor_show_servers(self): |
| 61 | # Show instances about the specific hypervisors |
| 62 | hypers = self._list_hypervisors() |
Sean Dague | 1c408f5 | 2013-12-12 16:46:32 -0500 | [diff] [blame] | 63 | self.assertHypervisors(hypers) |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 64 | |
| 65 | hostname = hypers[0]['hypervisor_hostname'] |
ghanshyam | 2dfd053 | 2015-08-18 17:18:40 +0900 | [diff] [blame] | 66 | hypervisors = (self.client.list_servers_on_hypervisor(hostname) |
| 67 | ['hypervisors']) |
zhufl | 080dcfb | 2016-10-21 17:45:38 +0800 | [diff] [blame] | 68 | self.assertGreater(len(hypervisors), 0) |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 69 | |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 70 | @decorators.idempotent_id('797e4f28-b6e0-454d-a548-80cc77c00816') |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 71 | def test_get_hypervisor_stats(self): |
| 72 | # Verify the stats of the all hypervisor |
ghanshyam | 2dfd053 | 2015-08-18 17:18:40 +0900 | [diff] [blame] | 73 | stats = (self.client.show_hypervisor_statistics() |
| 74 | ['hypervisor_statistics']) |
zhufl | 080dcfb | 2016-10-21 17:45:38 +0800 | [diff] [blame] | 75 | self.assertGreater(len(stats), 0) |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 76 | |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 77 | @decorators.idempotent_id('91a50d7d-1c2b-4f24-b55a-a1fe20efca70') |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 78 | def test_get_hypervisor_uptime(self): |
| 79 | # Verify that GET shows the specified hypervisor uptime |
| 80 | hypers = self._list_hypervisors() |
| 81 | |
David Shrewsbury | 152b781 | 2014-07-07 16:56:16 -0400 | [diff] [blame] | 82 | # Ironic will register each baremetal node as a 'hypervisor', |
| 83 | # so the hypervisor list can contain many hypervisors of type |
| 84 | # 'ironic'. If they are ALL ironic, skip this test since ironic |
| 85 | # doesn't support hypervisor uptime. Otherwise, remove them |
| 86 | # from the list of hypervisors to test. |
| 87 | ironic_only = True |
| 88 | hypers_without_ironic = [] |
Sean Dague | 1c408f5 | 2013-12-12 16:46:32 -0500 | [diff] [blame] | 89 | for hyper in hypers: |
zhufl | e9260e2 | 2016-12-07 11:55:33 +0800 | [diff] [blame] | 90 | details = (self.client.show_hypervisor(hyper['id']) |
ghanshyam | 2dfd053 | 2015-08-18 17:18:40 +0900 | [diff] [blame] | 91 | ['hypervisor']) |
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: |
ghanshyam | 2dfd053 | 2015-08-18 17:18:40 +0900 | [diff] [blame] | 105 | uptime = (self.client.show_hypervisor_uptime(hyper['id']) |
| 106 | ['hypervisor']) |
Masayuki Igawa | 0c0f014 | 2017-04-10 17:22:02 +0900 | [diff] [blame^] | 107 | if uptime: |
Sean Dague | 1c408f5 | 2013-12-12 16:46:32 -0500 | [diff] [blame] | 108 | has_valid_uptime = True |
| 109 | break |
| 110 | except Exception: |
| 111 | pass |
| 112 | self.assertTrue( |
| 113 | has_valid_uptime, |
| 114 | "None of the hypervisors had a valid uptime: %s" % hypers) |
Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame] | 115 | |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 116 | @decorators.idempotent_id('d7e1805b-3b14-4a3b-b6fd-50ec6d9f361f') |
Lingxian Kong | 1629d5d | 2013-10-05 17:12:29 +0800 | [diff] [blame] | 117 | def test_search_hypervisor(self): |
| 118 | hypers = self._list_hypervisors() |
Sean Dague | 1c408f5 | 2013-12-12 16:46:32 -0500 | [diff] [blame] | 119 | self.assertHypervisors(hypers) |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 120 | hypers = self.client.search_hypervisor( |
ghanshyam | 2dfd053 | 2015-08-18 17:18:40 +0900 | [diff] [blame] | 121 | hypers[0]['hypervisor_hostname'])['hypervisors'] |
Sean Dague | 1c408f5 | 2013-12-12 16:46:32 -0500 | [diff] [blame] | 122 | self.assertHypervisors(hypers) |