blob: 327d8b89a1efa3b2aadd76f5e24bd34ae21dbea9 [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 import exceptions
21from tempest.test import attr
Leo Toyoda3ae31e12013-04-19 11:19:57 +090022
23
ivan-zhuf2b00502013-10-18 10:06:52 +080024class ServicesAdminTestJSON(base.BaseV2ComputeAdminTest):
Leo Toyoda3ae31e12013-04-19 11:19:57 +090025
26 """
27 Tests Services API. List and Enable/Disable require admin privileges.
28 """
29
30 _interface = 'json'
31
32 @classmethod
33 def setUpClass(cls):
34 super(ServicesAdminTestJSON, cls).setUpClass()
35 cls.client = cls.os_adm.services_client
36 cls.non_admin_client = cls.services_client
37
Giulio Fidenteba3985a2013-05-29 01:46:36 +020038 @attr(type='gate')
Leo Toyoda3ae31e12013-04-19 11:19:57 +090039 def test_list_services(self):
Leo Toyoda3ae31e12013-04-19 11:19:57 +090040 resp, services = self.client.list_services()
41 self.assertEqual(200, resp.status)
Liu, Zhi Kund42c9912013-07-18 23:03:57 +080042 self.assertNotEqual(0, len(services))
Leo Toyoda3ae31e12013-04-19 11:19:57 +090043
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040044 @attr(type=['negative', 'gate'])
Leo Toyoda3ae31e12013-04-19 11:19:57 +090045 def test_list_services_with_non_admin_user(self):
Leo Toyoda3ae31e12013-04-19 11:19:57 +090046 self.assertRaises(exceptions.Unauthorized,
47 self.non_admin_client.list_services)
48
Liu, Zhi Kund42c9912013-07-18 23:03:57 +080049 @attr(type='gate')
50 def test_get_service_by_service_binary_name(self):
51 binary_name = 'nova-compute'
52 params = {'binary': binary_name}
53 resp, services = self.client.list_services(params)
54 self.assertEqual(200, resp.status)
55 self.assertNotEqual(0, len(services))
56 for service in services:
57 self.assertEqual(binary_name, service['binary'])
58
59 @attr(type='gate')
60 def test_get_service_by_host_name(self):
61 resp, services = self.client.list_services()
62 host_name = services[0]['host']
63 services_on_host = [service for service in services if
64 service['host'] == host_name]
65 params = {'host': host_name}
66 resp, services = self.client.list_services(params)
Sean Dague3b616492013-07-26 15:04:12 -040067
68 # we could have a periodic job checkin between the 2 service
69 # lookups, so only compare binary lists.
70 s1 = map(lambda x: x['binary'], services)
71 s2 = map(lambda x: x['binary'], services_on_host)
Sumanth Nagadavalli31422202013-07-31 10:54:21 +053072
Attila Fazekasf7f34f92013-08-01 17:01:44 +020073 # sort the lists before comparing, to take out dependency
74 # on order.
Sumanth Nagadavalli31422202013-07-31 10:54:21 +053075 self.assertEqual(sorted(s1), sorted(s2))
Liu, Zhi Kund42c9912013-07-18 23:03:57 +080076
77 @attr(type=['negative', 'gate'])
78 def test_get_service_by_invalid_params(self):
Attila Fazekasf7f34f92013-08-01 17:01:44 +020079 # return all services if send the request with invalid parameter
Liu, Zhi Kund42c9912013-07-18 23:03:57 +080080 resp, services = self.client.list_services()
81 params = {'xxx': 'nova-compute'}
82 resp, services_xxx = self.client.list_services(params)
83 self.assertEqual(200, resp.status)
84 self.assertEqual(len(services), len(services_xxx))
85
86 @attr(type='gate')
87 def test_get_service_by_service_and_host_name(self):
88 resp, services = self.client.list_services()
89 host_name = services[0]['host']
90 binary_name = services[0]['binary']
91 params = {'host': host_name, 'binary': binary_name}
92 resp, services = self.client.list_services(params)
93 self.assertEqual(200, resp.status)
94 self.assertEqual(1, len(services))
95 self.assertEqual(host_name, services[0]['host'])
96 self.assertEqual(binary_name, services[0]['binary'])
97
98 @attr(type=['negative', 'gate'])
99 def test_get_service_by_invalid_service_and_valid_host(self):
100 resp, services = self.client.list_services()
101 host_name = services[0]['host']
102 params = {'host': host_name, 'binary': 'xxx'}
103 resp, services = self.client.list_services(params)
104 self.assertEqual(200, resp.status)
105 self.assertEqual(0, len(services))
106
107 @attr(type=['negative', 'gate'])
108 def test_get_service_with_valid_service_and_invalid_host(self):
109 resp, services = self.client.list_services()
110 binary_name = services[0]['binary']
111 params = {'host': 'xxx', 'binary': binary_name}
112 resp, services = self.client.list_services(params)
113 self.assertEqual(200, resp.status)
114 self.assertEqual(0, len(services))
115
116 @attr(type='gate')
117 def test_service_enable_disable(self):
118 resp, services = self.client.list_services()
119 host_name = services[0]['host']
120 binary_name = services[0]['binary']
121
122 resp, service = self.client.disable_service(host_name, binary_name)
123 self.assertEqual(200, resp.status)
124 params = {'host': host_name, 'binary': binary_name}
125 resp, services = self.client.list_services(params)
126 self.assertEqual('disabled', services[0]['status'])
127
128 resp, service = self.client.enable_service(host_name, binary_name)
129 self.assertEqual(200, resp.status)
130 resp, services = self.client.list_services(params)
131 self.assertEqual('enabled', services[0]['status'])
132
Leo Toyoda3ae31e12013-04-19 11:19:57 +0900133
134class ServicesAdminTestXML(ServicesAdminTestJSON):
135 _interface = 'xml'