blob: 31fe2b531a8f6f98ec939857bd5b2bc12bbebd66 [file] [log] [blame]
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +08001# 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
15from tempest.api.compute import base
Matthew Treinish98b8b542013-09-20 15:46:31 +000016from tempest.common import tempest_fixtures as fixtures
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080017from tempest.lib import decorators
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080018
19
ivan-zhuf2b00502013-10-18 10:06:52 +080020class HostsAdminTestJSON(base.BaseV2ComputeAdminTest):
Ken'ichi Ohmichi88363cb2015-11-19 08:00:54 +000021 """Tests hosts API using admin privileges."""
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080022
zhufle7398042018-03-13 16:20:18 +080023 max_microversion = '2.42'
24
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080025 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +053026 def setup_clients(cls):
27 super(HostsAdminTestJSON, cls).setup_clients()
Jordan Pittier8160d312017-04-18 11:52:23 +020028 cls.client = cls.os_admin.hosts_client
Lingxian Kong4b398fd2013-10-04 17:14:14 +080029
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080030 @decorators.idempotent_id('9bfaf98d-e2cb-44b0-a07e-2558b2821e4f')
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080031 def test_list_hosts(self):
zhufl2a6dcdb2020-03-04 15:47:25 +080032 # Listing hosts.
ghanshyame1bd29e2015-08-18 16:47:24 +090033 hosts = self.client.list_hosts()['hosts']
Béla Vancsics64862f72016-11-08 09:12:31 +010034 self.assertGreaterEqual(len(hosts), 2, str(hosts))
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080035
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080036 @decorators.idempotent_id('5dc06f5b-d887-47a2-bb2a-67762ef3c6de')
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080037 def test_list_hosts_with_zone(self):
zhufl2a6dcdb2020-03-04 15:47:25 +080038 # Listing hosts with specified availability zone
Matthew Treinish98b8b542013-09-20 15:46:31 +000039 self.useFixture(fixtures.LockFixture('availability_zone'))
ghanshyame1bd29e2015-08-18 16:47:24 +090040 hosts = self.client.list_hosts()['hosts']
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080041 host = hosts[0]
ghanshyame1bd29e2015-08-18 16:47:24 +090042 hosts = self.client.list_hosts(zone=host['zone'])['hosts']
Ferenc Horváth268ccce2017-06-08 12:39:02 +020043 self.assertNotEmpty(hosts)
Attila Fazekase191cb12013-07-29 06:41:52 +020044 self.assertIn(host, hosts)
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080045
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080046 @decorators.idempotent_id('9af3c171-fbf4-4150-a624-22109733c2a6')
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080047 def test_list_hosts_with_a_blank_zone(self):
zhufl2a6dcdb2020-03-04 15:47:25 +080048 # Listing hosts with blank availability zone.
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080049 # If send the request with a blank zone, the request will be successful
50 # and it will return all the hosts list
ghanshyame1bd29e2015-08-18 16:47:24 +090051 hosts = self.client.list_hosts(zone='')['hosts']
Masayuki Igawaf9009b42017-04-10 14:49:29 +090052 self.assertNotEmpty(hosts)
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080053
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080054 @decorators.idempotent_id('c6ddbadb-c94e-4500-b12f-8ffc43843ff8')
Lingxian Kong4b398fd2013-10-04 17:14:14 +080055 def test_list_hosts_with_nonexistent_zone(self):
zhufl2a6dcdb2020-03-04 15:47:25 +080056 # Listing hosts with not existing availability zone.
Lingxian Kong4b398fd2013-10-04 17:14:14 +080057 # If send the request with a nonexistent zone, the request will be
zhufl0892cb22016-05-06 14:46:00 +080058 # successful and no hosts will be returned
ghanshyame1bd29e2015-08-18 16:47:24 +090059 hosts = self.client.list_hosts(zone='xxx')['hosts']
Masayuki Igawaf9009b42017-04-10 14:49:29 +090060 self.assertEmpty(hosts)
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080061
Ken'ichi Ohmichiebbfd1c2017-01-27 16:37:00 -080062 @decorators.idempotent_id('38adbb12-aee2-4498-8aec-329c72423aa4')
Zhu Zhuff150052013-09-17 17:48:39 +080063 def test_show_host_detail(self):
zhufl2a6dcdb2020-03-04 15:47:25 +080064 # Showing host details.
ghanshyame1bd29e2015-08-18 16:47:24 +090065 hosts = self.client.list_hosts()['hosts']
m.benchchaoui@cloudbau.de69918362013-10-31 20:31:15 +010066
67 hosts = [host for host in hosts if host['service'] == 'compute']
zhufl9d2ebc42017-06-12 11:09:09 +080068 self.assertNotEmpty(hosts)
m.benchchaoui@cloudbau.de69918362013-10-31 20:31:15 +010069
70 for host in hosts:
71 hostname = host['host_name']
ghanshyame1bd29e2015-08-18 16:47:24 +090072 resources = self.client.show_host(hostname)['host']
Ferenc Horváth268ccce2017-06-08 12:39:02 +020073 self.assertNotEmpty(resources)
m.benchchaoui@cloudbau.de69918362013-10-31 20:31:15 +010074 host_resource = resources[0]['resource']
m.benchchaoui@cloudbau.de69918362013-10-31 20:31:15 +010075 self.assertEqual(hostname, host_resource['host'])