blob: b9335c98974a78dcd8040b9f4a9e746d0faf9ff8 [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()
Ken'ichi Ohmichi118776d2015-07-01 08:15:00 +000044 services_xxx = self.client.list_services(xxx='nova-compute')
Haiwei Xu1461c782013-12-09 10:14:13 +090045 self.assertEqual(len(services), len(services_xxx))
46
Sean Dague639f2fa2015-04-27 09:00:33 -040047 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080048 @test.idempotent_id('1e966d4a-226e-47c7-b601-0b18a27add54')
Haiwei Xu1461c782013-12-09 10:14:13 +090049 def test_get_service_by_invalid_service_and_valid_host(self):
David Kranz0a735172015-01-16 10:51:18 -050050 services = self.client.list_services()
Haiwei Xu1461c782013-12-09 10:14:13 +090051 host_name = services[0]['host']
Ken'ichi Ohmichi118776d2015-07-01 08:15:00 +000052 services = self.client.list_services(host=host_name, binary='xxx')
Haiwei Xu1461c782013-12-09 10:14:13 +090053 self.assertEqual(0, len(services))
54
Sean Dague639f2fa2015-04-27 09:00:33 -040055 @test.attr(type=['negative'])
Chris Hoge7579c1a2015-02-26 14:12:15 -080056 @test.idempotent_id('64e7e7fb-69e8-4cb6-a71d-8d5eb0c98655')
Haiwei Xu1461c782013-12-09 10:14:13 +090057 def test_get_service_with_valid_service_and_invalid_host(self):
David Kranz0a735172015-01-16 10:51:18 -050058 services = self.client.list_services()
Haiwei Xu1461c782013-12-09 10:14:13 +090059 binary_name = services[0]['binary']
Ken'ichi Ohmichi118776d2015-07-01 08:15:00 +000060 services = self.client.list_services(host='xxx', binary=binary_name)
Haiwei Xu1461c782013-12-09 10:14:13 +090061 self.assertEqual(0, len(services))