Liu, Zhi Kun | a9d1082 | 2013-07-01 17:48:17 +0800 | [diff] [blame] | 1 | # 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 | |
| 15 | from tempest.api.compute import base |
Matthew Treinish | 98b8b54 | 2013-09-20 15:46:31 +0000 | [diff] [blame] | 16 | from tempest.common import tempest_fixtures as fixtures |
Liu, Zhi Kun | a9d1082 | 2013-07-01 17:48:17 +0800 | [diff] [blame] | 17 | from tempest.test import attr |
| 18 | |
| 19 | |
ivan-zhu | f2b0050 | 2013-10-18 10:06:52 +0800 | [diff] [blame] | 20 | class HostsAdminTestJSON(base.BaseV2ComputeAdminTest): |
Liu, Zhi Kun | a9d1082 | 2013-07-01 17:48:17 +0800 | [diff] [blame] | 21 | |
| 22 | """ |
| 23 | Tests hosts API using admin privileges. |
| 24 | """ |
| 25 | |
Liu, Zhi Kun | a9d1082 | 2013-07-01 17:48:17 +0800 | [diff] [blame] | 26 | @classmethod |
| 27 | def setUpClass(cls): |
| 28 | super(HostsAdminTestJSON, cls).setUpClass() |
| 29 | cls.client = cls.os_adm.hosts_client |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 30 | |
Attila Fazekas | aa04d61 | 2013-08-12 17:49:46 +0200 | [diff] [blame] | 31 | @attr(type='gate') |
Liu, Zhi Kun | a9d1082 | 2013-07-01 17:48:17 +0800 | [diff] [blame] | 32 | def test_list_hosts(self): |
| 33 | resp, hosts = self.client.list_hosts() |
| 34 | self.assertEqual(200, resp.status) |
Attila Fazekas | 4b8b008 | 2013-10-25 14:24:32 +0200 | [diff] [blame] | 35 | self.assertTrue(len(hosts) >= 2, str(hosts)) |
Liu, Zhi Kun | a9d1082 | 2013-07-01 17:48:17 +0800 | [diff] [blame] | 36 | |
Attila Fazekas | aa04d61 | 2013-08-12 17:49:46 +0200 | [diff] [blame] | 37 | @attr(type='gate') |
Liu, Zhi Kun | a9d1082 | 2013-07-01 17:48:17 +0800 | [diff] [blame] | 38 | def test_list_hosts_with_zone(self): |
Matthew Treinish | 98b8b54 | 2013-09-20 15:46:31 +0000 | [diff] [blame] | 39 | self.useFixture(fixtures.LockFixture('availability_zone')) |
Liu, Zhi Kun | a9d1082 | 2013-07-01 17:48:17 +0800 | [diff] [blame] | 40 | resp, hosts = self.client.list_hosts() |
| 41 | host = hosts[0] |
| 42 | zone_name = host['zone'] |
| 43 | params = {'zone': zone_name} |
| 44 | resp, hosts = self.client.list_hosts(params) |
| 45 | self.assertEqual(200, resp.status) |
| 46 | self.assertTrue(len(hosts) >= 1) |
Attila Fazekas | e191cb1 | 2013-07-29 06:41:52 +0200 | [diff] [blame] | 47 | self.assertIn(host, hosts) |
Liu, Zhi Kun | a9d1082 | 2013-07-01 17:48:17 +0800 | [diff] [blame] | 48 | |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 49 | @attr(type='gate') |
Liu, Zhi Kun | a9d1082 | 2013-07-01 17:48:17 +0800 | [diff] [blame] | 50 | def test_list_hosts_with_a_blank_zone(self): |
| 51 | # If send the request with a blank zone, the request will be successful |
| 52 | # and it will return all the hosts list |
| 53 | params = {'zone': ''} |
| 54 | resp, hosts = self.client.list_hosts(params) |
| 55 | self.assertNotEqual(0, len(hosts)) |
| 56 | self.assertEqual(200, resp.status) |
| 57 | |
Lingxian Kong | 4b398fd | 2013-10-04 17:14:14 +0800 | [diff] [blame] | 58 | @attr(type='gate') |
| 59 | def test_list_hosts_with_nonexistent_zone(self): |
| 60 | # If send the request with a nonexistent zone, the request will be |
| 61 | # successful and no hosts will be retured |
| 62 | params = {'zone': 'xxx'} |
| 63 | resp, hosts = self.client.list_hosts(params) |
| 64 | self.assertEqual(0, len(hosts)) |
| 65 | self.assertEqual(200, resp.status) |
Liu, Zhi Kun | a9d1082 | 2013-07-01 17:48:17 +0800 | [diff] [blame] | 66 | |
Zhu Zhu | ff15005 | 2013-09-17 17:48:39 +0800 | [diff] [blame] | 67 | @attr(type='gate') |
| 68 | def test_show_host_detail(self): |
m.benchchaoui@cloudbau.de | 6991836 | 2013-10-31 20:31:15 +0100 | [diff] [blame] | 69 | resp, hosts = self.client.list_hosts() |
Zhu Zhu | ff15005 | 2013-09-17 17:48:39 +0800 | [diff] [blame] | 70 | self.assertEqual(200, resp.status) |
m.benchchaoui@cloudbau.de | 6991836 | 2013-10-31 20:31:15 +0100 | [diff] [blame] | 71 | |
| 72 | hosts = [host for host in hosts if host['service'] == 'compute'] |
| 73 | self.assertTrue(len(hosts) >= 1) |
| 74 | |
| 75 | for host in hosts: |
| 76 | hostname = host['host_name'] |
| 77 | resp, resources = self.client.show_host_detail(hostname) |
| 78 | self.assertEqual(200, resp.status) |
| 79 | self.assertTrue(len(resources) >= 1) |
| 80 | host_resource = resources[0]['resource'] |
| 81 | self.assertIsNotNone(host_resource) |
| 82 | self.assertIsNotNone(host_resource['cpu']) |
| 83 | self.assertIsNotNone(host_resource['disk_gb']) |
| 84 | self.assertIsNotNone(host_resource['memory_mb']) |
| 85 | self.assertIsNotNone(host_resource['project']) |
| 86 | self.assertEqual(hostname, host_resource['host']) |
Zhu Zhu | ff15005 | 2013-09-17 17:48:39 +0800 | [diff] [blame] | 87 | |
Liu, Zhi Kun | a9d1082 | 2013-07-01 17:48:17 +0800 | [diff] [blame] | 88 | |
| 89 | class HostsAdminTestXML(HostsAdminTestJSON): |
| 90 | _interface = 'xml' |