blob: 710cac460f4f799be777dad6dd67db52821d2ce7 [file] [log] [blame]
Haiwei Xu1461c782013-12-09 10:14:13 +09001# Copyright 2013 NEC Corporation. All rights reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
15from tempest.api.compute import base
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -050016from tempest.lib import exceptions as lib_exc
Masayuki Igawa394d8d92014-03-04 17:21:56 +090017from tempest import test
Haiwei Xu1461c782013-12-09 10:14:13 +090018
19
Haiwei Xu661049c2013-12-09 17:28:13 +090020class ServicesAdminNegativeTestJSON(base.BaseV2ComputeAdminTest):
Ken'ichi Ohmichi9e3dac02015-11-19 07:01:07 +000021 """Tests Services API. List and Enable/Disable require admin privileges."""
Haiwei Xu1461c782013-12-09 10:14:13 +090022
Haiwei Xu1461c782013-12-09 10:14:13 +090023 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +053024 def setup_clients(cls):
25 super(ServicesAdminNegativeTestJSON, cls).setup_clients()
Haiwei Xu1461c782013-12-09 10:14:13 +090026 cls.client = cls.os_adm.services_client
27 cls.non_admin_client = cls.services_client
28
Sean Dague639f2fa2015-04-27 09:00:33 -040029 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080030 @test.idempotent_id('1126d1f8-266e-485f-a687-adc547492646')
Haiwei Xu1461c782013-12-09 10:14:13 +090031 def test_list_services_with_non_admin_user(self):
Masayuki Igawa6b1cd292015-02-16 11:11:55 +090032 self.assertRaises(lib_exc.Forbidden,
Haiwei Xu1461c782013-12-09 10:14:13 +090033 self.non_admin_client.list_services)
34
Sean Dague639f2fa2015-04-27 09:00:33 -040035 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080036 @test.idempotent_id('d0884a69-f693-4e79-a9af-232d15643bf7')
Haiwei Xu1461c782013-12-09 10:14:13 +090037 def test_get_service_by_invalid_params(self):
38 # return all services if send the request with invalid parameter
ghanshyam0de02842015-08-24 17:47:41 +090039 services = self.client.list_services()['services']
40 services_xxx = (self.client.list_services(xxx='nova-compute')
41 ['services'])
Haiwei Xu1461c782013-12-09 10:14:13 +090042 self.assertEqual(len(services), len(services_xxx))
43
Sean Dague639f2fa2015-04-27 09:00:33 -040044 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080045 @test.idempotent_id('1e966d4a-226e-47c7-b601-0b18a27add54')
Haiwei Xu1461c782013-12-09 10:14:13 +090046 def test_get_service_by_invalid_service_and_valid_host(self):
ghanshyam0de02842015-08-24 17:47:41 +090047 services = self.client.list_services()['services']
Haiwei Xu1461c782013-12-09 10:14:13 +090048 host_name = services[0]['host']
ghanshyam0de02842015-08-24 17:47:41 +090049 services = self.client.list_services(host=host_name,
50 binary='xxx')['services']
Haiwei Xu1461c782013-12-09 10:14:13 +090051 self.assertEqual(0, len(services))
52
Sean Dague639f2fa2015-04-27 09:00:33 -040053 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080054 @test.idempotent_id('64e7e7fb-69e8-4cb6-a71d-8d5eb0c98655')
Haiwei Xu1461c782013-12-09 10:14:13 +090055 def test_get_service_with_valid_service_and_invalid_host(self):
ghanshyam0de02842015-08-24 17:47:41 +090056 services = self.client.list_services()['services']
Haiwei Xu1461c782013-12-09 10:14:13 +090057 binary_name = services[0]['binary']
ghanshyam0de02842015-08-24 17:47:41 +090058 services = self.client.list_services(host='xxx',
59 binary=binary_name)['services']
Haiwei Xu1461c782013-12-09 10:14:13 +090060 self.assertEqual(0, len(services))