blob: b367dad9f01915b2cc3bbdd620069531d7087e7b [file] [log] [blame]
ivan-zhua2c9cd52013-08-20 20:01:44 +08001# Copyright 2013 NEC Corporation
2# Copyright 2013 IBM Corp.
3# All Rights Reserved.
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may
6# not use this file except in compliance with the License. You may obtain
7# a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14# License for the specific language governing permissions and limitations
15# under the License.
16
17from tempest.api.compute import base
ivan-zhua2c9cd52013-08-20 20:01:44 +080018from tempest.test import attr
19
20
Ken'ichi Ohmichi7f508ed2014-01-30 22:35:20 +090021class ServicesAdminV3Test(base.BaseV3ComputeAdminTest):
ivan-zhua2c9cd52013-08-20 20:01:44 +080022
23 """
24 Tests Services API. List and Enable/Disable require admin privileges.
25 """
26
ivan-zhua2c9cd52013-08-20 20:01:44 +080027 @classmethod
28 def setUpClass(cls):
Ken'ichi Ohmichi7f508ed2014-01-30 22:35:20 +090029 super(ServicesAdminV3Test, cls).setUpClass()
ivan-zhu5c86ae62013-08-20 21:09:01 +080030 cls.client = cls.services_admin_client
ivan-zhua2c9cd52013-08-20 20:01:44 +080031
32 @attr(type='gate')
33 def test_list_services(self):
34 resp, services = self.client.list_services()
Chris Yeohc266b282014-03-13 18:19:00 +103035 self.assertEqual(200, resp.status)
ivan-zhua2c9cd52013-08-20 20:01:44 +080036 self.assertNotEqual(0, len(services))
37
ivan-zhua2c9cd52013-08-20 20:01:44 +080038 @attr(type='gate')
39 def test_get_service_by_service_binary_name(self):
40 binary_name = 'nova-compute'
41 params = {'binary': binary_name}
42 resp, services = self.client.list_services(params)
Chris Yeohc266b282014-03-13 18:19:00 +103043 self.assertEqual(200, resp.status)
ivan-zhua2c9cd52013-08-20 20:01:44 +080044 self.assertNotEqual(0, len(services))
45 for service in services:
46 self.assertEqual(binary_name, service['binary'])
47
48 @attr(type='gate')
49 def test_get_service_by_host_name(self):
50 resp, services = self.client.list_services()
Chris Yeohc266b282014-03-13 18:19:00 +103051 self.assertEqual(200, resp.status)
ivan-zhua2c9cd52013-08-20 20:01:44 +080052 host_name = services[0]['host']
53 services_on_host = [service for service in services if
54 service['host'] == host_name]
55 params = {'host': host_name}
Ken'ichi Ohmichi986bf412014-03-06 04:06:21 +090056
ivan-zhua2c9cd52013-08-20 20:01:44 +080057 resp, services = self.client.list_services(params)
58
59 # we could have a periodic job checkin between the 2 service
60 # lookups, so only compare binary lists.
61 s1 = map(lambda x: x['binary'], services)
62 s2 = map(lambda x: x['binary'], services_on_host)
63
64 # sort the lists before comparing, to take out dependency
65 # on order.
66 self.assertEqual(sorted(s1), sorted(s2))
67
ivan-zhua2c9cd52013-08-20 20:01:44 +080068 @attr(type='gate')
69 def test_get_service_by_service_and_host_name(self):
70 resp, services = self.client.list_services()
71 host_name = services[0]['host']
72 binary_name = services[0]['binary']
73 params = {'host': host_name, 'binary': binary_name}
Ken'ichi Ohmichi986bf412014-03-06 04:06:21 +090074
ivan-zhua2c9cd52013-08-20 20:01:44 +080075 resp, services = self.client.list_services(params)
Chris Yeohc266b282014-03-13 18:19:00 +103076 self.assertEqual(200, resp.status)
ivan-zhua2c9cd52013-08-20 20:01:44 +080077 self.assertEqual(1, len(services))
78 self.assertEqual(host_name, services[0]['host'])
79 self.assertEqual(binary_name, services[0]['binary'])