Haiwei Xu | 1461c78 | 2013-12-09 10:14:13 +0900 | [diff] [blame] | 1 | # 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 Igawa | 29d554f | 2015-01-20 12:36:42 +0900 | [diff] [blame] | 15 | from tempest_lib import exceptions as lib_exc |
| 16 | |
Haiwei Xu | 1461c78 | 2013-12-09 10:14:13 +0900 | [diff] [blame] | 17 | from tempest.api.compute import base |
Masayuki Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 18 | from tempest import test |
Haiwei Xu | 1461c78 | 2013-12-09 10:14:13 +0900 | [diff] [blame] | 19 | |
| 20 | |
Haiwei Xu | 661049c | 2013-12-09 17:28:13 +0900 | [diff] [blame] | 21 | class ServicesAdminNegativeTestJSON(base.BaseV2ComputeAdminTest): |
Haiwei Xu | 1461c78 | 2013-12-09 10:14:13 +0900 | [diff] [blame] | 22 | |
| 23 | """ |
| 24 | Tests Services API. List and Enable/Disable require admin privileges. |
| 25 | """ |
| 26 | |
Haiwei Xu | 1461c78 | 2013-12-09 10:14:13 +0900 | [diff] [blame] | 27 | @classmethod |
Rohan Kanade | 60b7309 | 2015-02-04 17:58:19 +0530 | [diff] [blame] | 28 | def setup_clients(cls): |
| 29 | super(ServicesAdminNegativeTestJSON, cls).setup_clients() |
Haiwei Xu | 1461c78 | 2013-12-09 10:14:13 +0900 | [diff] [blame] | 30 | cls.client = cls.os_adm.services_client |
| 31 | cls.non_admin_client = cls.services_client |
| 32 | |
Sean Dague | 639f2fa | 2015-04-27 09:00:33 -0400 | [diff] [blame] | 33 | @test.attr(type=['negative']) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 34 | @test.idempotent_id('1126d1f8-266e-485f-a687-adc547492646') |
Haiwei Xu | 1461c78 | 2013-12-09 10:14:13 +0900 | [diff] [blame] | 35 | def test_list_services_with_non_admin_user(self): |
Masayuki Igawa | 6b1cd29 | 2015-02-16 11:11:55 +0900 | [diff] [blame] | 36 | self.assertRaises(lib_exc.Forbidden, |
Haiwei Xu | 1461c78 | 2013-12-09 10:14:13 +0900 | [diff] [blame] | 37 | self.non_admin_client.list_services) |
| 38 | |
Sean Dague | 639f2fa | 2015-04-27 09:00:33 -0400 | [diff] [blame] | 39 | @test.attr(type=['negative']) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 40 | @test.idempotent_id('d0884a69-f693-4e79-a9af-232d15643bf7') |
Haiwei Xu | 1461c78 | 2013-12-09 10:14:13 +0900 | [diff] [blame] | 41 | def test_get_service_by_invalid_params(self): |
| 42 | # return all services if send the request with invalid parameter |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 43 | services = self.client.list_services() |
Ken'ichi Ohmichi | 118776d | 2015-07-01 08:15:00 +0000 | [diff] [blame] | 44 | services_xxx = self.client.list_services(xxx='nova-compute') |
Haiwei Xu | 1461c78 | 2013-12-09 10:14:13 +0900 | [diff] [blame] | 45 | self.assertEqual(len(services), len(services_xxx)) |
| 46 | |
Sean Dague | 639f2fa | 2015-04-27 09:00:33 -0400 | [diff] [blame] | 47 | @test.attr(type=['negative']) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 48 | @test.idempotent_id('1e966d4a-226e-47c7-b601-0b18a27add54') |
Haiwei Xu | 1461c78 | 2013-12-09 10:14:13 +0900 | [diff] [blame] | 49 | def test_get_service_by_invalid_service_and_valid_host(self): |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 50 | services = self.client.list_services() |
Haiwei Xu | 1461c78 | 2013-12-09 10:14:13 +0900 | [diff] [blame] | 51 | host_name = services[0]['host'] |
Ken'ichi Ohmichi | 118776d | 2015-07-01 08:15:00 +0000 | [diff] [blame] | 52 | services = self.client.list_services(host=host_name, binary='xxx') |
Haiwei Xu | 1461c78 | 2013-12-09 10:14:13 +0900 | [diff] [blame] | 53 | self.assertEqual(0, len(services)) |
| 54 | |
Sean Dague | 639f2fa | 2015-04-27 09:00:33 -0400 | [diff] [blame] | 55 | @test.attr(type=['negative']) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 56 | @test.idempotent_id('64e7e7fb-69e8-4cb6-a71d-8d5eb0c98655') |
Haiwei Xu | 1461c78 | 2013-12-09 10:14:13 +0900 | [diff] [blame] | 57 | def test_get_service_with_valid_service_and_invalid_host(self): |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 58 | services = self.client.list_services() |
Haiwei Xu | 1461c78 | 2013-12-09 10:14:13 +0900 | [diff] [blame] | 59 | binary_name = services[0]['binary'] |
Ken'ichi Ohmichi | 118776d | 2015-07-01 08:15:00 +0000 | [diff] [blame] | 60 | services = self.client.list_services(host='xxx', binary=binary_name) |
Haiwei Xu | 1461c78 | 2013-12-09 10:14:13 +0900 | [diff] [blame] | 61 | self.assertEqual(0, len(services)) |