blob: 3bab185aa43e6e5bf8ff462bd8d56a71dbfe56c3 [file] [log] [blame]
Abhijeet.Jain0056b072014-04-15 09:32:29 +05301# 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
16from tempest.api.volume import base
17from tempest import test
18
19
jun xie9f123822014-11-20 14:21:23 +080020class VolumesServicesV2TestJSON(base.BaseVolumeAdminTest):
Abhijeet.Jain0056b072014-04-15 09:32:29 +053021 """
22 Tests Volume Services API.
23 volume service list requires admin privileges.
24 """
Abhijeet.Jain0056b072014-04-15 09:32:29 +053025
26 @classmethod
Andrea Frittoli61a12e22014-09-15 13:14:54 +010027 def resource_setup(cls):
jun xie9f123822014-11-20 14:21:23 +080028 super(VolumesServicesV2TestJSON, cls).resource_setup()
Joseph Lanoux6809bab2014-12-18 14:57:18 +000029 cls.services = cls.admin_volume_services_client.list_services()
Abhijeet.Jain0056b072014-04-15 09:32:29 +053030 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 Lanoux6809bab2014-12-18 14:57:18 +000035 services = self.admin_volume_services_client.list_services()
Abhijeet.Jain0056b072014-04-15 09:32:29 +053036 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 Lanoux6809bab2014-12-18 14:57:18 +000041 services = self.admin_volume_services_client.list_services(params)
Abhijeet.Jain0056b072014-04-15 09:32:29 +053042 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 Lanoux6809bab2014-12-18 14:57:18 +000052 services = self.admin_volume_services_client.list_services(params)
Abhijeet.Jain0056b072014-04-15 09:32:29 +053053
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 Lanoux6809bab2014-12-18 14:57:18 +000066 services = self.admin_volume_services_client.list_services(params)
Abhijeet.Jain0056b072014-04-15 09:32:29 +053067 self.assertEqual(1, len(services))
68 self.assertEqual(self.host_name, services[0]['host'])
69 self.assertEqual(self.binary_name, services[0]['binary'])
jun xie9f123822014-11-20 14:21:23 +080070
71
72class VolumesServicesV1TestJSON(VolumesServicesV2TestJSON):
73 _api_version = 1