blob: 16dcfcc219d1392119fc4b540867ef417c8e9ec6 [file] [log] [blame]
Leo Toyoda3ae31e12013-04-19 11:19:57 +09001# Copyright 2013 NEC Corporation
Liu, Zhi Kund42c9912013-07-18 23:03:57 +08002# Copyright 2013 IBM Corp.
Leo Toyoda3ae31e12013-04-19 11:19:57 +09003# 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
Sean Dague1937d092013-05-17 16:36:38 -040017from tempest.api.compute import base
Leo Toyoda3ae31e12013-04-19 11:19:57 +090018from tempest.test import attr
Leo Toyoda3ae31e12013-04-19 11:19:57 +090019
20
ivan-zhuf2b00502013-10-18 10:06:52 +080021class ServicesAdminTestJSON(base.BaseV2ComputeAdminTest):
Leo Toyoda3ae31e12013-04-19 11:19:57 +090022
23 """
24 Tests Services API. List and Enable/Disable require admin privileges.
25 """
26
27 _interface = 'json'
28
29 @classmethod
30 def setUpClass(cls):
31 super(ServicesAdminTestJSON, cls).setUpClass()
32 cls.client = cls.os_adm.services_client
33 cls.non_admin_client = cls.services_client
34
Giulio Fidenteba3985a2013-05-29 01:46:36 +020035 @attr(type='gate')
Leo Toyoda3ae31e12013-04-19 11:19:57 +090036 def test_list_services(self):
Leo Toyoda3ae31e12013-04-19 11:19:57 +090037 resp, services = self.client.list_services()
38 self.assertEqual(200, resp.status)
Liu, Zhi Kund42c9912013-07-18 23:03:57 +080039 self.assertNotEqual(0, len(services))
Leo Toyoda3ae31e12013-04-19 11:19:57 +090040
Liu, Zhi Kund42c9912013-07-18 23:03:57 +080041 @attr(type='gate')
42 def test_get_service_by_service_binary_name(self):
43 binary_name = 'nova-compute'
44 params = {'binary': binary_name}
45 resp, services = self.client.list_services(params)
46 self.assertEqual(200, resp.status)
47 self.assertNotEqual(0, len(services))
48 for service in services:
49 self.assertEqual(binary_name, service['binary'])
50
51 @attr(type='gate')
52 def test_get_service_by_host_name(self):
53 resp, services = self.client.list_services()
54 host_name = services[0]['host']
55 services_on_host = [service for service in services if
56 service['host'] == host_name]
57 params = {'host': host_name}
58 resp, services = self.client.list_services(params)
Sean Dague3b616492013-07-26 15:04:12 -040059
60 # we could have a periodic job checkin between the 2 service
61 # lookups, so only compare binary lists.
62 s1 = map(lambda x: x['binary'], services)
63 s2 = map(lambda x: x['binary'], services_on_host)
Sumanth Nagadavalli31422202013-07-31 10:54:21 +053064
Attila Fazekasf7f34f92013-08-01 17:01:44 +020065 # sort the lists before comparing, to take out dependency
66 # on order.
Sumanth Nagadavalli31422202013-07-31 10:54:21 +053067 self.assertEqual(sorted(s1), sorted(s2))
Liu, Zhi Kund42c9912013-07-18 23:03:57 +080068
Liu, Zhi Kund42c9912013-07-18 23:03:57 +080069 @attr(type='gate')
70 def test_get_service_by_service_and_host_name(self):
71 resp, services = self.client.list_services()
72 host_name = services[0]['host']
73 binary_name = services[0]['binary']
74 params = {'host': host_name, 'binary': binary_name}
75 resp, services = self.client.list_services(params)
76 self.assertEqual(200, resp.status)
77 self.assertEqual(1, len(services))
78 self.assertEqual(host_name, services[0]['host'])
79 self.assertEqual(binary_name, services[0]['binary'])
80
Leo Toyoda3ae31e12013-04-19 11:19:57 +090081
82class ServicesAdminTestXML(ServicesAdminTestJSON):
83 _interface = 'xml'