Liu, Zhi Kun | a9d1082 | 2013-07-01 17:48:17 +0800 | [diff] [blame] | 1 | # Copyright 2013 IBM Corp. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | # not use this file except in compliance with the License. You may obtain |
| 5 | # a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | # License for the specific language governing permissions and limitations |
| 13 | # under the License. |
| 14 | |
| 15 | from tempest.api.compute import base |
Matthew Treinish | 98b8b54 | 2013-09-20 15:46:31 +0000 | [diff] [blame] | 16 | from tempest.common import tempest_fixtures as fixtures |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 17 | from tempest.lib import decorators |
Liu, Zhi Kun | a9d1082 | 2013-07-01 17:48:17 +0800 | [diff] [blame] | 18 | |
| 19 | |
ivan-zhu | f2b0050 | 2013-10-18 10:06:52 +0800 | [diff] [blame] | 20 | class HostsAdminTestJSON(base.BaseV2ComputeAdminTest): |
Ken'ichi Ohmichi | 88363cb | 2015-11-19 08:00:54 +0000 | [diff] [blame] | 21 | """Tests hosts API using admin privileges.""" |
Liu, Zhi Kun | a9d1082 | 2013-07-01 17:48:17 +0800 | [diff] [blame] | 22 | |
zhufl | e739804 | 2018-03-13 16:20:18 +0800 | [diff] [blame] | 23 | max_microversion = '2.42' |
| 24 | |
Liu, Zhi Kun | a9d1082 | 2013-07-01 17:48:17 +0800 | [diff] [blame] | 25 | @classmethod |
Rohan Kanade | 60b7309 | 2015-02-04 17:58:19 +0530 | [diff] [blame] | 26 | def setup_clients(cls): |
| 27 | super(HostsAdminTestJSON, cls).setup_clients() |
Jordan Pittier | 8160d31 | 2017-04-18 11:52:23 +0200 | [diff] [blame] | 28 | cls.client = cls.os_admin.hosts_client |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 29 | |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 30 | @decorators.idempotent_id('9bfaf98d-e2cb-44b0-a07e-2558b2821e4f') |
Liu, Zhi Kun | a9d1082 | 2013-07-01 17:48:17 +0800 | [diff] [blame] | 31 | def test_list_hosts(self): |
zhufl | 2a6dcdb | 2020-03-04 15:47:25 +0800 | [diff] [blame] | 32 | # Listing hosts. |
ghanshyam | e1bd29e | 2015-08-18 16:47:24 +0900 | [diff] [blame] | 33 | hosts = self.client.list_hosts()['hosts'] |
Béla Vancsics | 64862f7 | 2016-11-08 09:12:31 +0100 | [diff] [blame] | 34 | self.assertGreaterEqual(len(hosts), 2, str(hosts)) |
Liu, Zhi Kun | a9d1082 | 2013-07-01 17:48:17 +0800 | [diff] [blame] | 35 | |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 36 | @decorators.idempotent_id('5dc06f5b-d887-47a2-bb2a-67762ef3c6de') |
Liu, Zhi Kun | a9d1082 | 2013-07-01 17:48:17 +0800 | [diff] [blame] | 37 | def test_list_hosts_with_zone(self): |
zhufl | 2a6dcdb | 2020-03-04 15:47:25 +0800 | [diff] [blame] | 38 | # Listing hosts with specified availability zone |
Matthew Treinish | 98b8b54 | 2013-09-20 15:46:31 +0000 | [diff] [blame] | 39 | self.useFixture(fixtures.LockFixture('availability_zone')) |
ghanshyam | e1bd29e | 2015-08-18 16:47:24 +0900 | [diff] [blame] | 40 | hosts = self.client.list_hosts()['hosts'] |
Liu, Zhi Kun | a9d1082 | 2013-07-01 17:48:17 +0800 | [diff] [blame] | 41 | host = hosts[0] |
ghanshyam | e1bd29e | 2015-08-18 16:47:24 +0900 | [diff] [blame] | 42 | hosts = self.client.list_hosts(zone=host['zone'])['hosts'] |
Ferenc Horváth | 268ccce | 2017-06-08 12:39:02 +0200 | [diff] [blame] | 43 | self.assertNotEmpty(hosts) |
Attila Fazekas | e191cb1 | 2013-07-29 06:41:52 +0200 | [diff] [blame] | 44 | self.assertIn(host, hosts) |
Liu, Zhi Kun | a9d1082 | 2013-07-01 17:48:17 +0800 | [diff] [blame] | 45 | |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 46 | @decorators.idempotent_id('9af3c171-fbf4-4150-a624-22109733c2a6') |
Liu, Zhi Kun | a9d1082 | 2013-07-01 17:48:17 +0800 | [diff] [blame] | 47 | def test_list_hosts_with_a_blank_zone(self): |
zhufl | 2a6dcdb | 2020-03-04 15:47:25 +0800 | [diff] [blame] | 48 | # Listing hosts with blank availability zone. |
Liu, Zhi Kun | a9d1082 | 2013-07-01 17:48:17 +0800 | [diff] [blame] | 49 | # If send the request with a blank zone, the request will be successful |
| 50 | # and it will return all the hosts list |
ghanshyam | e1bd29e | 2015-08-18 16:47:24 +0900 | [diff] [blame] | 51 | hosts = self.client.list_hosts(zone='')['hosts'] |
Masayuki Igawa | f9009b4 | 2017-04-10 14:49:29 +0900 | [diff] [blame] | 52 | self.assertNotEmpty(hosts) |
Liu, Zhi Kun | a9d1082 | 2013-07-01 17:48:17 +0800 | [diff] [blame] | 53 | |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 54 | @decorators.idempotent_id('c6ddbadb-c94e-4500-b12f-8ffc43843ff8') |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 55 | def test_list_hosts_with_nonexistent_zone(self): |
zhufl | 2a6dcdb | 2020-03-04 15:47:25 +0800 | [diff] [blame] | 56 | # Listing hosts with not existing availability zone. |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 57 | # If send the request with a nonexistent zone, the request will be |
zhufl | 0892cb2 | 2016-05-06 14:46:00 +0800 | [diff] [blame] | 58 | # successful and no hosts will be returned |
ghanshyam | e1bd29e | 2015-08-18 16:47:24 +0900 | [diff] [blame] | 59 | hosts = self.client.list_hosts(zone='xxx')['hosts'] |
Masayuki Igawa | f9009b4 | 2017-04-10 14:49:29 +0900 | [diff] [blame] | 60 | self.assertEmpty(hosts) |
Liu, Zhi Kun | a9d1082 | 2013-07-01 17:48:17 +0800 | [diff] [blame] | 61 | |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 62 | @decorators.idempotent_id('38adbb12-aee2-4498-8aec-329c72423aa4') |
Zhu Zhu | ff15005 | 2013-09-17 17:48:39 +0800 | [diff] [blame] | 63 | def test_show_host_detail(self): |
zhufl | 2a6dcdb | 2020-03-04 15:47:25 +0800 | [diff] [blame] | 64 | # Showing host details. |
ghanshyam | e1bd29e | 2015-08-18 16:47:24 +0900 | [diff] [blame] | 65 | hosts = self.client.list_hosts()['hosts'] |
m.benchchaoui@cloudbau.de | 6991836 | 2013-10-31 20:31:15 +0100 | [diff] [blame] | 66 | |
| 67 | hosts = [host for host in hosts if host['service'] == 'compute'] |
zhufl | 9d2ebc4 | 2017-06-12 11:09:09 +0800 | [diff] [blame] | 68 | self.assertNotEmpty(hosts) |
m.benchchaoui@cloudbau.de | 6991836 | 2013-10-31 20:31:15 +0100 | [diff] [blame] | 69 | |
| 70 | for host in hosts: |
| 71 | hostname = host['host_name'] |
ghanshyam | e1bd29e | 2015-08-18 16:47:24 +0900 | [diff] [blame] | 72 | resources = self.client.show_host(hostname)['host'] |
Ferenc Horváth | 268ccce | 2017-06-08 12:39:02 +0200 | [diff] [blame] | 73 | self.assertNotEmpty(resources) |
m.benchchaoui@cloudbau.de | 6991836 | 2013-10-31 20:31:15 +0100 | [diff] [blame] | 74 | host_resource = resources[0]['resource'] |
m.benchchaoui@cloudbau.de | 6991836 | 2013-10-31 20:31:15 +0100 | [diff] [blame] | 75 | self.assertEqual(hostname, host_resource['host']) |