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 | |
| 15 | from tempest.api.compute import base |
| 16 | from tempest import exceptions |
| 17 | from tempest.test import attr |
| 18 | |
| 19 | |
Haiwei Xu | 661049c | 2013-12-09 17:28:13 +0900 | [diff] [blame] | 20 | class ServicesAdminNegativeTestJSON(base.BaseV2ComputeAdminTest): |
Haiwei Xu | 1461c78 | 2013-12-09 10:14:13 +0900 | [diff] [blame] | 21 | |
| 22 | """ |
| 23 | Tests Services API. List and Enable/Disable require admin privileges. |
| 24 | """ |
| 25 | |
| 26 | _interface = 'json' |
| 27 | |
| 28 | @classmethod |
| 29 | def setUpClass(cls): |
Haiwei Xu | 661049c | 2013-12-09 17:28:13 +0900 | [diff] [blame] | 30 | super(ServicesAdminNegativeTestJSON, cls).setUpClass() |
Haiwei Xu | 1461c78 | 2013-12-09 10:14:13 +0900 | [diff] [blame] | 31 | cls.client = cls.os_adm.services_client |
| 32 | cls.non_admin_client = cls.services_client |
| 33 | |
| 34 | @attr(type=['negative', 'gate']) |
| 35 | def test_list_services_with_non_admin_user(self): |
| 36 | self.assertRaises(exceptions.Unauthorized, |
| 37 | self.non_admin_client.list_services) |
| 38 | |
| 39 | @attr(type=['negative', 'gate']) |
| 40 | def test_get_service_by_invalid_params(self): |
| 41 | # return all services if send the request with invalid parameter |
| 42 | resp, services = self.client.list_services() |
| 43 | params = {'xxx': 'nova-compute'} |
| 44 | resp, services_xxx = self.client.list_services(params) |
| 45 | self.assertEqual(200, resp.status) |
| 46 | self.assertEqual(len(services), len(services_xxx)) |
| 47 | |
| 48 | @attr(type=['negative', 'gate']) |
| 49 | def test_get_service_by_invalid_service_and_valid_host(self): |
| 50 | resp, services = self.client.list_services() |
| 51 | host_name = services[0]['host'] |
| 52 | params = {'host': host_name, 'binary': 'xxx'} |
| 53 | resp, services = self.client.list_services(params) |
| 54 | self.assertEqual(200, resp.status) |
| 55 | self.assertEqual(0, len(services)) |
| 56 | |
| 57 | @attr(type=['negative', 'gate']) |
| 58 | def test_get_service_with_valid_service_and_invalid_host(self): |
| 59 | resp, services = self.client.list_services() |
| 60 | binary_name = services[0]['binary'] |
| 61 | params = {'host': 'xxx', 'binary': binary_name} |
| 62 | resp, services = self.client.list_services(params) |
| 63 | self.assertEqual(200, resp.status) |
| 64 | self.assertEqual(0, len(services)) |
| 65 | |
| 66 | |
Haiwei Xu | 661049c | 2013-12-09 17:28:13 +0900 | [diff] [blame] | 67 | class ServicesAdminNegativeTestXML(ServicesAdminNegativeTestJSON): |
Haiwei Xu | 1461c78 | 2013-12-09 10:14:13 +0900 | [diff] [blame] | 68 | _interface = 'xml' |