Abhijeet.Jain | 0056b07 | 2014-04-15 09:32:29 +0530 | [diff] [blame] | 1 | # Copyright 2014 NEC Corporation |
| 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 |
| 17 | from tempest import test |
| 18 | |
| 19 | |
jun xie | 9f12382 | 2014-11-20 14:21:23 +0800 | [diff] [blame] | 20 | class VolumesServicesV2TestJSON(base.BaseVolumeAdminTest): |
Abhijeet.Jain | 0056b07 | 2014-04-15 09:32:29 +0530 | [diff] [blame] | 21 | """ |
| 22 | Tests Volume Services API. |
| 23 | volume service list requires admin privileges. |
| 24 | """ |
Abhijeet.Jain | 0056b07 | 2014-04-15 09:32:29 +0530 | [diff] [blame] | 25 | |
| 26 | @classmethod |
Andrea Frittoli | 61a12e2 | 2014-09-15 13:14:54 +0100 | [diff] [blame] | 27 | def resource_setup(cls): |
jun xie | 9f12382 | 2014-11-20 14:21:23 +0800 | [diff] [blame] | 28 | super(VolumesServicesV2TestJSON, cls).resource_setup() |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 29 | cls.services = cls.admin_volume_services_client.list_services() |
Abhijeet.Jain | 0056b07 | 2014-04-15 09:32:29 +0530 | [diff] [blame] | 30 | cls.host_name = cls.services[0]['host'] |
| 31 | cls.binary_name = cls.services[0]['binary'] |
| 32 | |
| 33 | @test.attr(type='gate') |
| 34 | def test_list_services(self): |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 35 | services = self.admin_volume_services_client.list_services() |
Abhijeet.Jain | 0056b07 | 2014-04-15 09:32:29 +0530 | [diff] [blame] | 36 | self.assertNotEqual(0, len(services)) |
| 37 | |
| 38 | @test.attr(type='gate') |
| 39 | def test_get_service_by_service_binary_name(self): |
| 40 | params = {'binary': self.binary_name} |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 41 | services = self.admin_volume_services_client.list_services(params) |
Abhijeet.Jain | 0056b07 | 2014-04-15 09:32:29 +0530 | [diff] [blame] | 42 | self.assertNotEqual(0, len(services)) |
| 43 | for service in services: |
| 44 | self.assertEqual(self.binary_name, service['binary']) |
| 45 | |
| 46 | @test.attr(type='gate') |
| 47 | def test_get_service_by_host_name(self): |
| 48 | services_on_host = [service for service in self.services if |
| 49 | service['host'] == self.host_name] |
| 50 | params = {'host': self.host_name} |
| 51 | |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 52 | services = self.admin_volume_services_client.list_services(params) |
Abhijeet.Jain | 0056b07 | 2014-04-15 09:32:29 +0530 | [diff] [blame] | 53 | |
| 54 | # we could have a periodic job checkin between the 2 service |
| 55 | # lookups, so only compare binary lists. |
| 56 | s1 = map(lambda x: x['binary'], services) |
| 57 | s2 = map(lambda x: x['binary'], services_on_host) |
| 58 | # sort the lists before comparing, to take out dependency |
| 59 | # on order. |
| 60 | self.assertEqual(sorted(s1), sorted(s2)) |
| 61 | |
| 62 | @test.attr(type='gate') |
| 63 | def test_get_service_by_service_and_host_name(self): |
| 64 | params = {'host': self.host_name, 'binary': self.binary_name} |
| 65 | |
Joseph Lanoux | 6809bab | 2014-12-18 14:57:18 +0000 | [diff] [blame] | 66 | services = self.admin_volume_services_client.list_services(params) |
Abhijeet.Jain | 0056b07 | 2014-04-15 09:32:29 +0530 | [diff] [blame] | 67 | self.assertEqual(1, len(services)) |
| 68 | self.assertEqual(self.host_name, services[0]['host']) |
| 69 | self.assertEqual(self.binary_name, services[0]['binary']) |
jun xie | 9f12382 | 2014-11-20 14:21:23 +0800 | [diff] [blame] | 70 | |
| 71 | |
| 72 | class VolumesServicesV1TestJSON(VolumesServicesV2TestJSON): |
| 73 | _api_version = 1 |