blob: 9fee2a198c0212ef44d15fede9dfdec6dda086e3 [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
Masayuki Igawa394d8d92014-03-04 17:21:56 +090017from tempest import test
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080018
19
ivan-zhuf2b00502013-10-18 10:06:52 +080020class HostsAdminTestJSON(base.BaseV2ComputeAdminTest):
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080021
22 """
23 Tests hosts API using admin privileges.
24 """
25
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080026 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +053027 def setup_clients(cls):
28 super(HostsAdminTestJSON, cls).setup_clients()
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080029 cls.client = cls.os_adm.hosts_client
Lingxian Kong4b398fd2013-10-04 17:14:14 +080030
Chris Hoge7579c1a2015-02-26 14:12:15 -080031 @test.idempotent_id('9bfaf98d-e2cb-44b0-a07e-2558b2821e4f')
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080032 def test_list_hosts(self):
David Kranz0a735172015-01-16 10:51:18 -050033 hosts = self.client.list_hosts()
Attila Fazekas4b8b0082013-10-25 14:24:32 +020034 self.assertTrue(len(hosts) >= 2, str(hosts))
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080035
Chris Hoge7579c1a2015-02-26 14:12:15 -080036 @test.idempotent_id('5dc06f5b-d887-47a2-bb2a-67762ef3c6de')
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080037 def test_list_hosts_with_zone(self):
Matthew Treinish98b8b542013-09-20 15:46:31 +000038 self.useFixture(fixtures.LockFixture('availability_zone'))
David Kranz0a735172015-01-16 10:51:18 -050039 hosts = self.client.list_hosts()
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080040 host = hosts[0]
41 zone_name = host['zone']
42 params = {'zone': zone_name}
David Kranz0a735172015-01-16 10:51:18 -050043 hosts = self.client.list_hosts(params)
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080044 self.assertTrue(len(hosts) >= 1)
Attila Fazekase191cb12013-07-29 06:41:52 +020045 self.assertIn(host, hosts)
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080046
Chris Hoge7579c1a2015-02-26 14:12:15 -080047 @test.idempotent_id('9af3c171-fbf4-4150-a624-22109733c2a6')
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080048 def test_list_hosts_with_a_blank_zone(self):
49 # If send the request with a blank zone, the request will be successful
50 # and it will return all the hosts list
51 params = {'zone': ''}
David Kranz0a735172015-01-16 10:51:18 -050052 hosts = self.client.list_hosts(params)
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080053 self.assertNotEqual(0, len(hosts))
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080054
Chris Hoge7579c1a2015-02-26 14:12:15 -080055 @test.idempotent_id('c6ddbadb-c94e-4500-b12f-8ffc43843ff8')
Lingxian Kong4b398fd2013-10-04 17:14:14 +080056 def test_list_hosts_with_nonexistent_zone(self):
57 # If send the request with a nonexistent zone, the request will be
58 # successful and no hosts will be retured
59 params = {'zone': 'xxx'}
David Kranz0a735172015-01-16 10:51:18 -050060 hosts = self.client.list_hosts(params)
Lingxian Kong4b398fd2013-10-04 17:14:14 +080061 self.assertEqual(0, len(hosts))
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080062
Chris Hoge7579c1a2015-02-26 14:12:15 -080063 @test.idempotent_id('38adbb12-aee2-4498-8aec-329c72423aa4')
Zhu Zhuff150052013-09-17 17:48:39 +080064 def test_show_host_detail(self):
David Kranz0a735172015-01-16 10:51:18 -050065 hosts = self.client.list_hosts()
m.benchchaoui@cloudbau.de69918362013-10-31 20:31:15 +010066
67 hosts = [host for host in hosts if host['service'] == 'compute']
68 self.assertTrue(len(hosts) >= 1)
69
70 for host in hosts:
71 hostname = host['host_name']
Ken'ichi Ohmichi394e6e42015-06-11 04:20:37 +000072 resources = self.client.show_host(hostname)
m.benchchaoui@cloudbau.de69918362013-10-31 20:31:15 +010073 self.assertTrue(len(resources) >= 1)
74 host_resource = resources[0]['resource']
75 self.assertIsNotNone(host_resource)
76 self.assertIsNotNone(host_resource['cpu'])
77 self.assertIsNotNone(host_resource['disk_gb'])
78 self.assertIsNotNone(host_resource['memory_mb'])
79 self.assertIsNotNone(host_resource['project'])
80 self.assertEqual(hostname, host_resource['host'])