blob: ce0cbd289932a92d4e3afe858d7f965e0f3bf224 [file] [log] [blame]
Nayna Patel4a5024c2013-11-18 07:08:23 +00001# Copyright 2013 OpenStack Foundation
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16from tempest.api.volume import base
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080017from tempest.lib import decorators
Nayna Patel4a5024c2013-11-18 07:08:23 +000018
19
Ken'ichi Ohmichie8afb8c2017-03-27 11:25:37 -070020class VolumeHostsAdminTestsJSON(base.BaseVolumeAdminTest):
Nayna Patel4a5024c2013-11-18 07:08:23 +000021
Ken'ichi Ohmichi6b279c72017-01-27 18:26:59 -080022 @decorators.idempotent_id('d5f3efa2-6684-4190-9ced-1c2f526352ad')
Nayna Patel4a5024c2013-11-18 07:08:23 +000023 def test_list_hosts(self):
bkopilov62d21752016-06-08 10:16:11 +030024 hosts = self.admin_hosts_client.list_hosts()['hosts']
jeremy.zhang44c2e0f2017-04-26 20:52:34 +080025 self.assertGreaterEqual(len(hosts), 2,
26 "The count of volume hosts is < 2, "
27 "response of list hosts is: %s" % hosts)
28
29 # Check elements in volume hosts list
30 host_list_keys = ['service', 'host_name', 'last-update',
31 'zone', 'service-status', 'service-state']
32 for host in hosts:
33 for key in host_list_keys:
34 self.assertIn(key, host)
35
36 @decorators.idempotent_id('21168d57-b373-4b71-a3ac-f2c88f0c5d31')
37 def test_show_host(self):
38 hosts = self.admin_hosts_client.list_hosts()['hosts']
39 self.assertGreaterEqual(len(hosts), 2,
40 "The count of volume hosts is < 2, "
41 "response of list hosts is: %s" % hosts)
42
jeremy.zhangaf55ae32017-08-18 11:36:46 +080043 # Note(jeremyZ): The show host API is to show volume usage info on the
44 # specified cinder-volume host. If the host does not run cinder-volume
45 # service, or the cinder-volume service is disabled on the host, the
46 # show host API should fail (return code: 404). The cinder-volume host
47 # is presented in format: <host-name>@driver-name.
48 c_vol_hosts = [host['host_name'] for host in hosts
49 if (host['service'] == 'cinder-volume'
50 and host['service-state'] == 'enabled')]
51 self.assertNotEmpty(c_vol_hosts,
52 "No available cinder-volume host is found, "
53 "all hosts that found are: %s" % hosts)
jeremy.zhang44c2e0f2017-04-26 20:52:34 +080054
jeremy.zhangaf55ae32017-08-18 11:36:46 +080055 # Check each cinder-volume host.
jeremy.zhang44c2e0f2017-04-26 20:52:34 +080056 host_detail_keys = ['project', 'volume_count', 'snapshot_count',
57 'host', 'total_volume_gb', 'total_snapshot_gb']
jeremy.zhangaf55ae32017-08-18 11:36:46 +080058 for host in c_vol_hosts:
59 host_details = self.admin_hosts_client.show_host(host)['host']
60 self.assertNotEmpty(host_details)
61 for detail in host_details:
62 self.assertIn('resource', detail)
63 for key in host_detail_keys:
64 self.assertIn(key, detail['resource'])