Liu, Zhi Kun | a9d1082 | 2013-07-01 17:48:17 +0800 | [diff] [blame] | 1 | # 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 | |
| 17 | from tempest.api.compute import base |
| 18 | from tempest import exceptions |
| 19 | from tempest.test import attr |
| 20 | |
| 21 | |
| 22 | class 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 Fazekas | aa04d61 | 2013-08-12 17:49:46 +0200 | [diff] [blame] | 36 | @attr(type='gate') |
Liu, Zhi Kun | a9d1082 | 2013-07-01 17:48:17 +0800 | [diff] [blame] | 37 | 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 Fazekas | aa04d61 | 2013-08-12 17:49:46 +0200 | [diff] [blame] | 42 | @attr(type='gate') |
Liu, Zhi Kun | a9d1082 | 2013-07-01 17:48:17 +0800 | [diff] [blame] | 43 | 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 Fazekas | e191cb1 | 2013-07-29 06:41:52 +0200 | [diff] [blame] | 51 | self.assertIn(host, hosts) |
Liu, Zhi Kun | a9d1082 | 2013-07-01 17:48:17 +0800 | [diff] [blame] | 52 | |
| 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 | |
| 75 | class HostsAdminTestXML(HostsAdminTestJSON): |
| 76 | _interface = 'xml' |