blob: 4d7dea589fa445cdf5fcf79536d45552e80e9816 [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
Masayuki Igawa394d8d92014-03-04 17:21:56 +090018from tempest import test
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
Leo Toyoda3ae31e12013-04-19 11:19:57 +090027 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +053028 def setup_clients(cls):
29 super(ServicesAdminTestJSON, cls).setup_clients()
Leo Toyoda3ae31e12013-04-19 11:19:57 +090030 cls.client = cls.os_adm.services_client
Leo Toyoda3ae31e12013-04-19 11:19:57 +090031
Chris Hoge7579c1a2015-02-26 14:12:15 -080032 @test.idempotent_id('5be41ef4-53d1-41cc-8839-5c2a48a1b283')
Leo Toyoda3ae31e12013-04-19 11:19:57 +090033 def test_list_services(self):
ghanshyam0de02842015-08-24 17:47:41 +090034 services = self.client.list_services()['services']
Liu, Zhi Kund42c9912013-07-18 23:03:57 +080035 self.assertNotEqual(0, len(services))
Leo Toyoda3ae31e12013-04-19 11:19:57 +090036
Chris Hoge7579c1a2015-02-26 14:12:15 -080037 @test.idempotent_id('f345b1ec-bc6e-4c38-a527-3ca2bc00bef5')
Liu, Zhi Kund42c9912013-07-18 23:03:57 +080038 def test_get_service_by_service_binary_name(self):
39 binary_name = 'nova-compute'
ghanshyam0de02842015-08-24 17:47:41 +090040 services = self.client.list_services(binary=binary_name)['services']
Liu, Zhi Kund42c9912013-07-18 23:03:57 +080041 self.assertNotEqual(0, len(services))
42 for service in services:
43 self.assertEqual(binary_name, service['binary'])
44
Chris Hoge7579c1a2015-02-26 14:12:15 -080045 @test.idempotent_id('affb42d5-5b4b-43c8-8b0b-6dca054abcca')
Liu, Zhi Kund42c9912013-07-18 23:03:57 +080046 def test_get_service_by_host_name(self):
ghanshyam0de02842015-08-24 17:47:41 +090047 services = self.client.list_services()['services']
Liu, Zhi Kund42c9912013-07-18 23:03:57 +080048 host_name = services[0]['host']
49 services_on_host = [service for service in services if
50 service['host'] == host_name]
Ken'ichi Ohmichi986bf412014-03-06 04:06:21 +090051
ghanshyam0de02842015-08-24 17:47:41 +090052 services = self.client.list_services(host=host_name)['services']
Sean Dague3b616492013-07-26 15:04:12 -040053
54 # we could have a periodic job checkin between the 2 service
55 # lookups, so only compare binary lists.
56 s1 = map(lambda x: x['binary'], services)
57 s2 = map(lambda x: x['binary'], services_on_host)
Sumanth Nagadavalli31422202013-07-31 10:54:21 +053058
Attila Fazekasf7f34f92013-08-01 17:01:44 +020059 # sort the lists before comparing, to take out dependency
60 # on order.
Sumanth Nagadavalli31422202013-07-31 10:54:21 +053061 self.assertEqual(sorted(s1), sorted(s2))
Liu, Zhi Kund42c9912013-07-18 23:03:57 +080062
Chris Hoge7579c1a2015-02-26 14:12:15 -080063 @test.idempotent_id('39397f6f-37b8-4234-8671-281e44c74025')
Liu, Zhi Kund42c9912013-07-18 23:03:57 +080064 def test_get_service_by_service_and_host_name(self):
ghanshyam0de02842015-08-24 17:47:41 +090065 services = self.client.list_services()['services']
Liu, Zhi Kund42c9912013-07-18 23:03:57 +080066 host_name = services[0]['host']
67 binary_name = services[0]['binary']
Ken'ichi Ohmichi986bf412014-03-06 04:06:21 +090068
Ken'ichi Ohmichi118776d2015-07-01 08:15:00 +000069 services = self.client.list_services(host=host_name,
ghanshyam0de02842015-08-24 17:47:41 +090070 binary=binary_name)['services']
Liu, Zhi Kund42c9912013-07-18 23:03:57 +080071 self.assertEqual(1, len(services))
72 self.assertEqual(host_name, services[0]['host'])
73 self.assertEqual(binary_name, services[0]['binary'])