ivan-zhu | 8577cb1 | 2013-08-20 14:38:36 +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 |
| 16 | from tempest.common import tempest_fixtures as fixtures |
ivan-zhu | 00fe64f | 2013-08-20 19:35:51 +0800 | [diff] [blame] | 17 | from tempest import test |
ivan-zhu | 8577cb1 | 2013-08-20 14:38:36 +0800 | [diff] [blame] | 18 | |
| 19 | |
Ken'ichi Ohmichi | 7f508ed | 2014-01-30 22:35:20 +0900 | [diff] [blame] | 20 | class HostsAdminV3Test(base.BaseV3ComputeAdminTest): |
ivan-zhu | 8577cb1 | 2013-08-20 14:38:36 +0800 | [diff] [blame] | 21 | |
| 22 | """ |
| 23 | Tests hosts API using admin privileges. |
| 24 | """ |
| 25 | |
| 26 | _interface = 'json' |
| 27 | |
| 28 | @classmethod |
| 29 | def setUpClass(cls): |
Ken'ichi Ohmichi | 7f508ed | 2014-01-30 22:35:20 +0900 | [diff] [blame] | 30 | super(HostsAdminV3Test, cls).setUpClass() |
ivan-zhu | 00fe64f | 2013-08-20 19:35:51 +0800 | [diff] [blame] | 31 | cls.client = cls.hosts_admin_client |
ivan-zhu | 8577cb1 | 2013-08-20 14:38:36 +0800 | [diff] [blame] | 32 | |
ivan-zhu | 00fe64f | 2013-08-20 19:35:51 +0800 | [diff] [blame] | 33 | @test.attr(type='gate') |
ivan-zhu | 8577cb1 | 2013-08-20 14:38:36 +0800 | [diff] [blame] | 34 | def test_list_hosts(self): |
| 35 | resp, hosts = self.client.list_hosts() |
| 36 | self.assertEqual(200, resp.status) |
| 37 | self.assertTrue(len(hosts) >= 2, str(hosts)) |
| 38 | |
ivan-zhu | 00fe64f | 2013-08-20 19:35:51 +0800 | [diff] [blame] | 39 | @test.attr(type='gate') |
ivan-zhu | 8577cb1 | 2013-08-20 14:38:36 +0800 | [diff] [blame] | 40 | def test_list_hosts_with_zone(self): |
| 41 | self.useFixture(fixtures.LockFixture('availability_zone')) |
| 42 | resp, hosts = self.client.list_hosts() |
| 43 | host = hosts[0] |
| 44 | zone_name = host['zone'] |
| 45 | params = {'zone': zone_name} |
| 46 | resp, hosts = self.client.list_hosts(params) |
| 47 | self.assertEqual(200, resp.status) |
| 48 | self.assertTrue(len(hosts) >= 1) |
| 49 | self.assertIn(host, hosts) |
| 50 | |
ivan-zhu | 00fe64f | 2013-08-20 19:35:51 +0800 | [diff] [blame] | 51 | @test.attr(type='gate') |
ivan-zhu | 8577cb1 | 2013-08-20 14:38:36 +0800 | [diff] [blame] | 52 | def test_list_hosts_with_a_blank_zone(self): |
| 53 | # If send the request with a blank zone, the request will be successful |
| 54 | # and it will return all the hosts list |
| 55 | params = {'zone': ''} |
| 56 | resp, hosts = self.client.list_hosts(params) |
| 57 | self.assertNotEqual(0, len(hosts)) |
| 58 | self.assertEqual(200, resp.status) |
| 59 | |
ivan-zhu | 00fe64f | 2013-08-20 19:35:51 +0800 | [diff] [blame] | 60 | @test.attr(type='gate') |
ivan-zhu | 8577cb1 | 2013-08-20 14:38:36 +0800 | [diff] [blame] | 61 | def test_list_hosts_with_nonexistent_zone(self): |
| 62 | # If send the request with a nonexistent zone, the request will be |
| 63 | # successful and no hosts will be retured |
| 64 | params = {'zone': 'xxx'} |
| 65 | resp, hosts = self.client.list_hosts(params) |
| 66 | self.assertEqual(0, len(hosts)) |
| 67 | self.assertEqual(200, resp.status) |
| 68 | |
ivan-zhu | 00fe64f | 2013-08-20 19:35:51 +0800 | [diff] [blame] | 69 | @test.attr(type='gate') |
ivan-zhu | 8577cb1 | 2013-08-20 14:38:36 +0800 | [diff] [blame] | 70 | def test_show_host_detail(self): |
| 71 | resp, hosts = self.client.list_hosts() |
| 72 | self.assertEqual(200, resp.status) |
| 73 | |
| 74 | hosts = [host for host in hosts if host['service'] == 'compute'] |
| 75 | self.assertTrue(len(hosts) >= 1) |
| 76 | |
| 77 | for host in hosts: |
| 78 | hostname = host['host_name'] |
| 79 | resp, resources = self.client.show_host_detail(hostname) |
| 80 | self.assertEqual(200, resp.status) |
| 81 | self.assertTrue(len(resources) >= 1) |
| 82 | host_resource = resources[0]['resource'] |
| 83 | self.assertIsNotNone(host_resource) |
| 84 | self.assertIsNotNone(host_resource['cpu']) |
| 85 | self.assertIsNotNone(host_resource['disk_gb']) |
| 86 | self.assertIsNotNone(host_resource['memory_mb']) |
| 87 | self.assertIsNotNone(host_resource['project']) |
| 88 | self.assertEqual(hostname, host_resource['host']) |