blob: 61227586849e648dc25147dc57561a9512d78775 [file] [log] [blame]
Leo Toyoda3ae31e12013-04-19 11:19:57 +09001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2013 NEC Corporation
Liu, Zhi Kund42c9912013-07-18 23:03:57 +08004# Copyright 2013 IBM Corp.
Leo Toyoda3ae31e12013-04-19 11:19:57 +09005# 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
Sean Dague1937d092013-05-17 16:36:38 -040019from tempest.api.compute import base
Leo Toyoda3ae31e12013-04-19 11:19:57 +090020from tempest.test import attr
Leo Toyoda3ae31e12013-04-19 11:19:57 +090021
22
ivan-zhuf2b00502013-10-18 10:06:52 +080023class ServicesAdminTestJSON(base.BaseV2ComputeAdminTest):
Leo Toyoda3ae31e12013-04-19 11:19:57 +090024
25 """
26 Tests Services API. List and Enable/Disable require admin privileges.
27 """
28
29 _interface = 'json'
30
31 @classmethod
32 def setUpClass(cls):
33 super(ServicesAdminTestJSON, cls).setUpClass()
34 cls.client = cls.os_adm.services_client
35 cls.non_admin_client = cls.services_client
36
Giulio Fidenteba3985a2013-05-29 01:46:36 +020037 @attr(type='gate')
Leo Toyoda3ae31e12013-04-19 11:19:57 +090038 def test_list_services(self):
Leo Toyoda3ae31e12013-04-19 11:19:57 +090039 resp, services = self.client.list_services()
40 self.assertEqual(200, resp.status)
Liu, Zhi Kund42c9912013-07-18 23:03:57 +080041 self.assertNotEqual(0, len(services))
Leo Toyoda3ae31e12013-04-19 11:19:57 +090042
Liu, Zhi Kund42c9912013-07-18 23:03:57 +080043 @attr(type='gate')
44 def test_get_service_by_service_binary_name(self):
45 binary_name = 'nova-compute'
46 params = {'binary': binary_name}
47 resp, services = self.client.list_services(params)
48 self.assertEqual(200, resp.status)
49 self.assertNotEqual(0, len(services))
50 for service in services:
51 self.assertEqual(binary_name, service['binary'])
52
53 @attr(type='gate')
54 def test_get_service_by_host_name(self):
55 resp, services = self.client.list_services()
56 host_name = services[0]['host']
57 services_on_host = [service for service in services if
58 service['host'] == host_name]
59 params = {'host': host_name}
60 resp, services = self.client.list_services(params)
Sean Dague3b616492013-07-26 15:04:12 -040061
62 # we could have a periodic job checkin between the 2 service
63 # lookups, so only compare binary lists.
64 s1 = map(lambda x: x['binary'], services)
65 s2 = map(lambda x: x['binary'], services_on_host)
Sumanth Nagadavalli31422202013-07-31 10:54:21 +053066
Attila Fazekasf7f34f92013-08-01 17:01:44 +020067 # sort the lists before comparing, to take out dependency
68 # on order.
Sumanth Nagadavalli31422202013-07-31 10:54:21 +053069 self.assertEqual(sorted(s1), sorted(s2))
Liu, Zhi Kund42c9912013-07-18 23:03:57 +080070
Liu, Zhi Kund42c9912013-07-18 23:03:57 +080071 @attr(type='gate')
72 def test_get_service_by_service_and_host_name(self):
73 resp, services = self.client.list_services()
74 host_name = services[0]['host']
75 binary_name = services[0]['binary']
76 params = {'host': host_name, 'binary': binary_name}
77 resp, services = self.client.list_services(params)
78 self.assertEqual(200, resp.status)
79 self.assertEqual(1, len(services))
80 self.assertEqual(host_name, services[0]['host'])
81 self.assertEqual(binary_name, services[0]['binary'])
82
Leo Toyoda3ae31e12013-04-19 11:19:57 +090083
84class ServicesAdminTestXML(ServicesAdminTestJSON):
85 _interface = 'xml'