blob: 48b8d12da719d1305809900835a0fbd077d6a04e [file] [log] [blame]
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +08001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2013 IBM Corp.
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may
6# not use this file except in compliance with the License. You may obtain
7# a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14# License for the specific language governing permissions and limitations
15# under the License.
16
17from tempest.api.compute import base
Matthew Treinish98b8b542013-09-20 15:46:31 +000018from tempest.common import tempest_fixtures as fixtures
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080019from tempest.test import attr
20
21
ivan-zhuf2b00502013-10-18 10:06:52 +080022class HostsAdminTestJSON(base.BaseV2ComputeAdminTest):
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080023
24 """
25 Tests hosts API using admin privileges.
26 """
27
28 _interface = 'json'
29
30 @classmethod
31 def setUpClass(cls):
32 super(HostsAdminTestJSON, cls).setUpClass()
33 cls.client = cls.os_adm.hosts_client
Lingxian Kong4b398fd2013-10-04 17:14:14 +080034
Attila Fazekasaa04d612013-08-12 17:49:46 +020035 @attr(type='gate')
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080036 def test_list_hosts(self):
37 resp, hosts = self.client.list_hosts()
38 self.assertEqual(200, resp.status)
39 self.assertTrue(len(hosts) >= 2)
40
Attila Fazekasaa04d612013-08-12 17:49:46 +020041 @attr(type='gate')
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080042 def test_list_hosts_with_zone(self):
Matthew Treinish98b8b542013-09-20 15:46:31 +000043 self.useFixture(fixtures.LockFixture('availability_zone'))
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080044 resp, hosts = self.client.list_hosts()
45 host = hosts[0]
46 zone_name = host['zone']
47 params = {'zone': zone_name}
48 resp, hosts = self.client.list_hosts(params)
49 self.assertEqual(200, resp.status)
50 self.assertTrue(len(hosts) >= 1)
Attila Fazekase191cb12013-07-29 06:41:52 +020051 self.assertIn(host, hosts)
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080052
Lingxian Kong4b398fd2013-10-04 17:14:14 +080053 @attr(type='gate')
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080054 def test_list_hosts_with_a_blank_zone(self):
55 # If send the request with a blank zone, the request will be successful
56 # and it will return all the hosts list
57 params = {'zone': ''}
58 resp, hosts = self.client.list_hosts(params)
59 self.assertNotEqual(0, len(hosts))
60 self.assertEqual(200, resp.status)
61
Lingxian Kong4b398fd2013-10-04 17:14:14 +080062 @attr(type='gate')
63 def test_list_hosts_with_nonexistent_zone(self):
64 # If send the request with a nonexistent zone, the request will be
65 # successful and no hosts will be retured
66 params = {'zone': 'xxx'}
67 resp, hosts = self.client.list_hosts(params)
68 self.assertEqual(0, len(hosts))
69 self.assertEqual(200, resp.status)
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080070
Zhu Zhuff150052013-09-17 17:48:39 +080071 @attr(type='gate')
72 def test_show_host_detail(self):
m.benchchaoui@cloudbau.de69918362013-10-31 20:31:15 +010073 resp, hosts = self.client.list_hosts()
Zhu Zhuff150052013-09-17 17:48:39 +080074 self.assertEqual(200, resp.status)
m.benchchaoui@cloudbau.de69918362013-10-31 20:31:15 +010075
76 hosts = [host for host in hosts if host['service'] == 'compute']
77 self.assertTrue(len(hosts) >= 1)
78
79 for host in hosts:
80 hostname = host['host_name']
81 resp, resources = self.client.show_host_detail(hostname)
82 self.assertEqual(200, resp.status)
83 self.assertTrue(len(resources) >= 1)
84 host_resource = resources[0]['resource']
85 self.assertIsNotNone(host_resource)
86 self.assertIsNotNone(host_resource['cpu'])
87 self.assertIsNotNone(host_resource['disk_gb'])
88 self.assertIsNotNone(host_resource['memory_mb'])
89 self.assertIsNotNone(host_resource['project'])
90 self.assertEqual(hostname, host_resource['host'])
Zhu Zhuff150052013-09-17 17:48:39 +080091
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080092
93class HostsAdminTestXML(HostsAdminTestJSON):
94 _interface = 'xml'