blob: 99f31c51b209793ff9f9f848f8f197da7fb73e68 [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
Masayuki Igawa29d554f2015-01-20 12:36:42 +090015from tempest_lib import exceptions as lib_exc
16
Haiwei Xu1461c782013-12-09 10:14:13 +090017from tempest.api.compute import base
Masayuki Igawa394d8d92014-03-04 17:21:56 +090018from tempest import test
Haiwei Xu1461c782013-12-09 10:14:13 +090019
20
Haiwei Xu661049c2013-12-09 17:28:13 +090021class ServicesAdminNegativeTestJSON(base.BaseV2ComputeAdminTest):
Haiwei Xu1461c782013-12-09 10:14:13 +090022
23 """
24 Tests Services API. List and Enable/Disable require admin privileges.
25 """
26
Haiwei Xu1461c782013-12-09 10:14:13 +090027 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +053028 def setup_clients(cls):
29 super(ServicesAdminNegativeTestJSON, cls).setup_clients()
Haiwei Xu1461c782013-12-09 10:14:13 +090030 cls.client = cls.os_adm.services_client
31 cls.non_admin_client = cls.services_client
32
Sean Dague639f2fa2015-04-27 09:00:33 -040033 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080034 @test.idempotent_id('1126d1f8-266e-485f-a687-adc547492646')
Haiwei Xu1461c782013-12-09 10:14:13 +090035 def test_list_services_with_non_admin_user(self):
Masayuki Igawa6b1cd292015-02-16 11:11:55 +090036 self.assertRaises(lib_exc.Forbidden,
Haiwei Xu1461c782013-12-09 10:14:13 +090037 self.non_admin_client.list_services)
38
Sean Dague639f2fa2015-04-27 09:00:33 -040039 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080040 @test.idempotent_id('d0884a69-f693-4e79-a9af-232d15643bf7')
Haiwei Xu1461c782013-12-09 10:14:13 +090041 def test_get_service_by_invalid_params(self):
42 # return all services if send the request with invalid parameter
David Kranz0a735172015-01-16 10:51:18 -050043 services = self.client.list_services()
Haiwei Xu1461c782013-12-09 10:14:13 +090044 params = {'xxx': 'nova-compute'}
David Kranz0a735172015-01-16 10:51:18 -050045 services_xxx = self.client.list_services(params)
Haiwei Xu1461c782013-12-09 10:14:13 +090046 self.assertEqual(len(services), len(services_xxx))
47
Sean Dague639f2fa2015-04-27 09:00:33 -040048 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080049 @test.idempotent_id('1e966d4a-226e-47c7-b601-0b18a27add54')
Haiwei Xu1461c782013-12-09 10:14:13 +090050 def test_get_service_by_invalid_service_and_valid_host(self):
David Kranz0a735172015-01-16 10:51:18 -050051 services = self.client.list_services()
Haiwei Xu1461c782013-12-09 10:14:13 +090052 host_name = services[0]['host']
53 params = {'host': host_name, 'binary': 'xxx'}
David Kranz0a735172015-01-16 10:51:18 -050054 services = self.client.list_services(params)
Haiwei Xu1461c782013-12-09 10:14:13 +090055 self.assertEqual(0, len(services))
56
Sean Dague639f2fa2015-04-27 09:00:33 -040057 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080058 @test.idempotent_id('64e7e7fb-69e8-4cb6-a71d-8d5eb0c98655')
Haiwei Xu1461c782013-12-09 10:14:13 +090059 def test_get_service_with_valid_service_and_invalid_host(self):
David Kranz0a735172015-01-16 10:51:18 -050060 services = self.client.list_services()
Haiwei Xu1461c782013-12-09 10:14:13 +090061 binary_name = services[0]['binary']
62 params = {'host': 'xxx', 'binary': binary_name}
David Kranz0a735172015-01-16 10:51:18 -050063 services = self.client.list_services(params)
Haiwei Xu1461c782013-12-09 10:14:13 +090064 self.assertEqual(0, len(services))