blob: 602f914162f272ad8f8d1434a6d938f6d174bb00 [file] [log] [blame]
ivan-zhua2c9cd52013-08-20 20:01:44 +08001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2013 NEC Corporation
4# Copyright 2013 IBM Corp.
5# All Rights Reserved.
6#
7# Licensed under the Apache License, Version 2.0 (the "License"); you may
8# not use this file except in compliance with the License. You may obtain
9# a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16# License for the specific language governing permissions and limitations
17# under the License.
18
19from tempest.api.compute import base
ivan-zhua2c9cd52013-08-20 20:01:44 +080020from tempest.test import attr
21
22
ivan-zhu5c86ae62013-08-20 21:09:01 +080023class ServicesAdminV3TestJSON(base.BaseV3ComputeAdminTest):
ivan-zhua2c9cd52013-08-20 20:01:44 +080024
25 """
26 Tests Services API. List and Enable/Disable require admin privileges.
27 """
28
29 _interface = 'json'
30
31 @classmethod
32 def setUpClass(cls):
ivan-zhu5c86ae62013-08-20 21:09:01 +080033 super(ServicesAdminV3TestJSON, cls).setUpClass()
34 cls.client = cls.services_admin_client
ivan-zhua2c9cd52013-08-20 20:01:44 +080035
36 @attr(type='gate')
37 def test_list_services(self):
38 resp, services = self.client.list_services()
39 self.assertEqual(200, resp.status)
40 self.assertNotEqual(0, len(services))
41
ivan-zhua2c9cd52013-08-20 20:01:44 +080042 @attr(type='gate')
43 def test_get_service_by_service_binary_name(self):
44 binary_name = 'nova-compute'
45 params = {'binary': binary_name}
46 resp, services = self.client.list_services(params)
47 self.assertEqual(200, resp.status)
48 self.assertNotEqual(0, len(services))
49 for service in services:
50 self.assertEqual(binary_name, service['binary'])
51
52 @attr(type='gate')
53 def test_get_service_by_host_name(self):
54 resp, services = self.client.list_services()
55 host_name = services[0]['host']
56 services_on_host = [service for service in services if
57 service['host'] == host_name]
58 params = {'host': host_name}
59 resp, services = self.client.list_services(params)
60
61 # we could have a periodic job checkin between the 2 service
62 # lookups, so only compare binary lists.
63 s1 = map(lambda x: x['binary'], services)
64 s2 = map(lambda x: x['binary'], services_on_host)
65
66 # sort the lists before comparing, to take out dependency
67 # on order.
68 self.assertEqual(sorted(s1), sorted(s2))
69
ivan-zhua2c9cd52013-08-20 20:01:44 +080070 @attr(type='gate')
71 def test_get_service_by_service_and_host_name(self):
72 resp, services = self.client.list_services()
73 host_name = services[0]['host']
74 binary_name = services[0]['binary']
75 params = {'host': host_name, 'binary': binary_name}
76 resp, services = self.client.list_services(params)
77 self.assertEqual(200, resp.status)
78 self.assertEqual(1, len(services))
79 self.assertEqual(host_name, services[0]['host'])
80 self.assertEqual(binary_name, services[0]['binary'])
81
ivan-zhua2c9cd52013-08-20 20:01:44 +080082
ivan-zhu5c86ae62013-08-20 21:09:01 +080083class ServicesAdminV3TestXML(ServicesAdminV3TestJSON):
ivan-zhua2c9cd52013-08-20 20:01:44 +080084 _interface = 'xml'