blob: 012c2310bef0076fbc881378c73f3c3bbcd13426 [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
20class VolumesServicesTestJSON(base.BaseVolumeV1AdminTest):
21 """
22 Tests Volume Services API.
23 volume service list requires admin privileges.
24 """
25 _interface = "json"
26
27 @classmethod
28 def setUpClass(cls):
29 super(VolumesServicesTestJSON, cls).setUpClass()
30 cls.client = cls.os_adm.volume_services_client
31 resp, cls.services = cls.client.list_services()
32 cls.host_name = cls.services[0]['host']
33 cls.binary_name = cls.services[0]['binary']
34
35 @test.attr(type='gate')
36 def test_list_services(self):
37 resp, services = self.client.list_services()
38 self.assertEqual(200, resp.status)
39 self.assertNotEqual(0, len(services))
40
41 @test.attr(type='gate')
42 def test_get_service_by_service_binary_name(self):
43 params = {'binary': self.binary_name}
44 resp, services = self.client.list_services(params)
45 self.assertEqual(200, resp.status)
46 self.assertNotEqual(0, len(services))
47 for service in services:
48 self.assertEqual(self.binary_name, service['binary'])
49
50 @test.attr(type='gate')
51 def test_get_service_by_host_name(self):
52 services_on_host = [service for service in self.services if
53 service['host'] == self.host_name]
54 params = {'host': self.host_name}
55
56 resp, services = self.client.list_services(params)
57
58 # we could have a periodic job checkin between the 2 service
59 # lookups, so only compare binary lists.
60 s1 = map(lambda x: x['binary'], services)
61 s2 = map(lambda x: x['binary'], services_on_host)
62 # sort the lists before comparing, to take out dependency
63 # on order.
64 self.assertEqual(sorted(s1), sorted(s2))
65
66 @test.attr(type='gate')
67 def test_get_service_by_service_and_host_name(self):
68 params = {'host': self.host_name, 'binary': self.binary_name}
69
70 resp, services = self.client.list_services(params)
71 self.assertEqual(200, resp.status)
72 self.assertEqual(1, len(services))
73 self.assertEqual(self.host_name, services[0]['host'])
74 self.assertEqual(self.binary_name, services[0]['binary'])