blob: af76ad03b96a6efb22e2b157db016b072fa7e45c [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
18from tempest import exceptions
19from tempest.test import attr
20
21
22class HostsAdminTestJSON(base.BaseComputeAdminTest):
23
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
34 cls.non_admin_client = cls.os.hosts_client
35
Attila Fazekasaa04d612013-08-12 17:49:46 +020036 @attr(type='gate')
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080037 def test_list_hosts(self):
38 resp, hosts = self.client.list_hosts()
39 self.assertEqual(200, resp.status)
40 self.assertTrue(len(hosts) >= 2)
41
Attila Fazekasaa04d612013-08-12 17:49:46 +020042 @attr(type='gate')
Liu, Zhi Kuna9d10822013-07-01 17:48:17 +080043 def test_list_hosts_with_zone(self):
44 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
53 @attr(type='negative')
54 def test_list_hosts_with_non_existent_zone(self):
55 params = {'zone': 'xxx'}
56 resp, hosts = self.client.list_hosts(params)
57 self.assertEqual(0, len(hosts))
58 self.assertEqual(200, resp.status)
59
60 @attr(type='negative')
61 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
69 @attr(type=['negative', 'gate'])
70 def test_list_hosts_with_non_admin_user(self):
71 self.assertRaises(exceptions.Unauthorized,
72 self.non_admin_client.list_hosts)
73
74
75class HostsAdminTestXML(HostsAdminTestJSON):
76 _interface = 'xml'