blob: 898a7041858c777a7c063cea39069423c7de0910 [file] [log] [blame]
ivan-zhu8577cb12013-08-20 14:38:36 +08001# 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
15from tempest.api.compute import base
16from tempest.common import tempest_fixtures as fixtures
ivan-zhu00fe64f2013-08-20 19:35:51 +080017from tempest import test
ivan-zhu8577cb12013-08-20 14:38:36 +080018
19
Ken'ichi Ohmichi7f508ed2014-01-30 22:35:20 +090020class HostsAdminV3Test(base.BaseV3ComputeAdminTest):
ivan-zhu8577cb12013-08-20 14:38:36 +080021
22 """
23 Tests hosts API using admin privileges.
24 """
25
ivan-zhu8577cb12013-08-20 14:38:36 +080026 @classmethod
Andrea Frittoli3d3efba2014-09-15 12:36:30 +010027 def resource_setup(cls):
28 super(HostsAdminV3Test, cls).resource_setup()
ivan-zhu00fe64f2013-08-20 19:35:51 +080029 cls.client = cls.hosts_admin_client
ivan-zhu8577cb12013-08-20 14:38:36 +080030
ivan-zhu00fe64f2013-08-20 19:35:51 +080031 @test.attr(type='gate')
ivan-zhu8577cb12013-08-20 14:38:36 +080032 def test_list_hosts(self):
33 resp, hosts = self.client.list_hosts()
34 self.assertEqual(200, resp.status)
35 self.assertTrue(len(hosts) >= 2, str(hosts))
36
ivan-zhu00fe64f2013-08-20 19:35:51 +080037 @test.attr(type='gate')
ivan-zhu8577cb12013-08-20 14:38:36 +080038 def test_list_hosts_with_zone(self):
39 self.useFixture(fixtures.LockFixture('availability_zone'))
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)
47 self.assertIn(host, hosts)
48
ivan-zhu00fe64f2013-08-20 19:35:51 +080049 @test.attr(type='gate')
ivan-zhu8577cb12013-08-20 14:38:36 +080050 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
ivan-zhu00fe64f2013-08-20 19:35:51 +080058 @test.attr(type='gate')
ivan-zhu8577cb12013-08-20 14:38:36 +080059 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)
66
ivan-zhu00fe64f2013-08-20 19:35:51 +080067 @test.attr(type='gate')
ivan-zhu8577cb12013-08-20 14:38:36 +080068 def test_show_host_detail(self):
69 resp, hosts = self.client.list_hosts()
70 self.assertEqual(200, resp.status)
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'])