Nayna Patel | 4a5024c | 2013-11-18 07:08:23 +0000 | [diff] [blame] | 1 | # 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 | |
| 16 | from tempest.api.volume import base |
Ken'ichi Ohmichi | 6b279c7 | 2017-01-27 18:26:59 -0800 | [diff] [blame] | 17 | from tempest.lib import decorators |
Nayna Patel | 4a5024c | 2013-11-18 07:08:23 +0000 | [diff] [blame] | 18 | |
| 19 | |
Ken'ichi Ohmichi | e8afb8c | 2017-03-27 11:25:37 -0700 | [diff] [blame] | 20 | class VolumeHostsAdminTestsJSON(base.BaseVolumeAdminTest): |
Nayna Patel | 4a5024c | 2013-11-18 07:08:23 +0000 | [diff] [blame] | 21 | |
Ken'ichi Ohmichi | 6b279c7 | 2017-01-27 18:26:59 -0800 | [diff] [blame] | 22 | @decorators.idempotent_id('d5f3efa2-6684-4190-9ced-1c2f526352ad') |
Nayna Patel | 4a5024c | 2013-11-18 07:08:23 +0000 | [diff] [blame] | 23 | def test_list_hosts(self): |
bkopilov | 62d2175 | 2016-06-08 10:16:11 +0300 | [diff] [blame] | 24 | hosts = self.admin_hosts_client.list_hosts()['hosts'] |
jeremy.zhang | 44c2e0f | 2017-04-26 20:52:34 +0800 | [diff] [blame] | 25 | 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.zhang | af55ae3 | 2017-08-18 11:36:46 +0800 | [diff] [blame] | 43 | # 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.zhang | 44c2e0f | 2017-04-26 20:52:34 +0800 | [diff] [blame] | 54 | |
jeremy.zhang | af55ae3 | 2017-08-18 11:36:46 +0800 | [diff] [blame] | 55 | # Check each cinder-volume host. |
jeremy.zhang | 44c2e0f | 2017-04-26 20:52:34 +0800 | [diff] [blame] | 56 | host_detail_keys = ['project', 'volume_count', 'snapshot_count', |
| 57 | 'host', 'total_volume_gb', 'total_snapshot_gb'] |
jeremy.zhang | af55ae3 | 2017-08-18 11:36:46 +0800 | [diff] [blame] | 58 | 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']) |