blob: 8e451a0ad728f2198e2b73d9f41ae2964158b0f8 [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
35 def _get_host_name(self):
36 resp, hosts = self.client.list_hosts()
37 self.assertEqual(200, resp.status)
38 self.assertTrue(len(hosts) >= 1)
39 hostname = hosts[0]['host_name']
40 return hostname
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080041
Attila Fazekasaa04d612013-08-12 17:49:46 +020042 @attr(type='gate')
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080043 def test_list_hosts(self):
44 resp, hosts = self.client.list_hosts()
45 self.assertEqual(200, resp.status)
46 self.assertTrue(len(hosts) >= 2)
47
Attila Fazekasaa04d612013-08-12 17:49:46 +020048 @attr(type='gate')
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080049 def test_list_hosts_with_zone(self):
Matthew Treinish98b8b542013-09-20 15:46:31 +000050 self.useFixture(fixtures.LockFixture('availability_zone'))
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080051 resp, hosts = self.client.list_hosts()
52 host = hosts[0]
53 zone_name = host['zone']
54 params = {'zone': zone_name}
55 resp, hosts = self.client.list_hosts(params)
56 self.assertEqual(200, resp.status)
57 self.assertTrue(len(hosts) >= 1)
Attila Fazekase191cb12013-07-29 06:41:52 +020058 self.assertIn(host, hosts)
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080059
Lingxian Kong4b398fd2013-10-04 17:14:14 +080060 @attr(type='gate')
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080061 def test_list_hosts_with_a_blank_zone(self):
62 # If send the request with a blank zone, the request will be successful
63 # and it will return all the hosts list
64 params = {'zone': ''}
65 resp, hosts = self.client.list_hosts(params)
66 self.assertNotEqual(0, len(hosts))
67 self.assertEqual(200, resp.status)
68
Lingxian Kong4b398fd2013-10-04 17:14:14 +080069 @attr(type='gate')
70 def test_list_hosts_with_nonexistent_zone(self):
71 # If send the request with a nonexistent zone, the request will be
72 # successful and no hosts will be retured
73 params = {'zone': 'xxx'}
74 resp, hosts = self.client.list_hosts(params)
75 self.assertEqual(0, len(hosts))
76 self.assertEqual(200, resp.status)
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080077
Zhu Zhuff150052013-09-17 17:48:39 +080078 @attr(type='gate')
79 def test_show_host_detail(self):
Lingxian Kong4b398fd2013-10-04 17:14:14 +080080 hostname = self._get_host_name()
Zhu Zhuff150052013-09-17 17:48:39 +080081
82 resp, resources = self.client.show_host_detail(hostname)
83 self.assertEqual(200, resp.status)
84 self.assertTrue(len(resources) >= 1)
85 host_resource = resources[0]['resource']
86 self.assertIsNotNone(host_resource)
87 self.assertIsNotNone(host_resource['cpu'])
88 self.assertIsNotNone(host_resource['disk_gb'])
89 self.assertIsNotNone(host_resource['memory_mb'])
90 self.assertIsNotNone(host_resource['project'])
91 self.assertEqual(hostname, host_resource['host'])
92
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080093
94class HostsAdminTestXML(HostsAdminTestJSON):
95 _interface = 'xml'