ivan-zhu | a2c9cd5 | 2013-08-20 20:01:44 +0800 | [diff] [blame] | 1 | # Copyright 2013 NEC Corporation |
| 2 | # Copyright 2013 IBM Corp. |
| 3 | # All Rights Reserved. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | # not use this file except in compliance with the License. You may obtain |
| 7 | # a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | # License for the specific language governing permissions and limitations |
| 15 | # under the License. |
| 16 | |
| 17 | from tempest.api.compute import base |
ivan-zhu | a2c9cd5 | 2013-08-20 20:01:44 +0800 | [diff] [blame] | 18 | from tempest.test import attr |
| 19 | |
| 20 | |
Ken'ichi Ohmichi | 7f508ed | 2014-01-30 22:35:20 +0900 | [diff] [blame] | 21 | class ServicesAdminV3Test(base.BaseV3ComputeAdminTest): |
ivan-zhu | a2c9cd5 | 2013-08-20 20:01:44 +0800 | [diff] [blame] | 22 | |
| 23 | """ |
| 24 | Tests Services API. List and Enable/Disable require admin privileges. |
| 25 | """ |
| 26 | |
ivan-zhu | a2c9cd5 | 2013-08-20 20:01:44 +0800 | [diff] [blame] | 27 | @classmethod |
| 28 | def setUpClass(cls): |
Ken'ichi Ohmichi | 7f508ed | 2014-01-30 22:35:20 +0900 | [diff] [blame] | 29 | super(ServicesAdminV3Test, cls).setUpClass() |
ivan-zhu | 5c86ae6 | 2013-08-20 21:09:01 +0800 | [diff] [blame] | 30 | cls.client = cls.services_admin_client |
ivan-zhu | a2c9cd5 | 2013-08-20 20:01:44 +0800 | [diff] [blame] | 31 | |
| 32 | @attr(type='gate') |
| 33 | def test_list_services(self): |
| 34 | resp, services = self.client.list_services() |
Chris Yeoh | c266b28 | 2014-03-13 18:19:00 +1030 | [diff] [blame] | 35 | self.assertEqual(200, resp.status) |
ivan-zhu | a2c9cd5 | 2013-08-20 20:01:44 +0800 | [diff] [blame] | 36 | self.assertNotEqual(0, len(services)) |
| 37 | |
ivan-zhu | a2c9cd5 | 2013-08-20 20:01:44 +0800 | [diff] [blame] | 38 | @attr(type='gate') |
| 39 | def test_get_service_by_service_binary_name(self): |
| 40 | binary_name = 'nova-compute' |
| 41 | params = {'binary': binary_name} |
| 42 | resp, services = self.client.list_services(params) |
Chris Yeoh | c266b28 | 2014-03-13 18:19:00 +1030 | [diff] [blame] | 43 | self.assertEqual(200, resp.status) |
ivan-zhu | a2c9cd5 | 2013-08-20 20:01:44 +0800 | [diff] [blame] | 44 | self.assertNotEqual(0, len(services)) |
| 45 | for service in services: |
| 46 | self.assertEqual(binary_name, service['binary']) |
| 47 | |
| 48 | @attr(type='gate') |
| 49 | def test_get_service_by_host_name(self): |
| 50 | resp, services = self.client.list_services() |
Chris Yeoh | c266b28 | 2014-03-13 18:19:00 +1030 | [diff] [blame] | 51 | self.assertEqual(200, resp.status) |
ivan-zhu | a2c9cd5 | 2013-08-20 20:01:44 +0800 | [diff] [blame] | 52 | host_name = services[0]['host'] |
| 53 | services_on_host = [service for service in services if |
| 54 | service['host'] == host_name] |
| 55 | params = {'host': host_name} |
Ken'ichi Ohmichi | 986bf41 | 2014-03-06 04:06:21 +0900 | [diff] [blame] | 56 | |
ivan-zhu | a2c9cd5 | 2013-08-20 20:01:44 +0800 | [diff] [blame] | 57 | resp, services = self.client.list_services(params) |
| 58 | |
| 59 | # we could have a periodic job checkin between the 2 service |
| 60 | # lookups, so only compare binary lists. |
| 61 | s1 = map(lambda x: x['binary'], services) |
| 62 | s2 = map(lambda x: x['binary'], services_on_host) |
| 63 | |
| 64 | # sort the lists before comparing, to take out dependency |
| 65 | # on order. |
| 66 | self.assertEqual(sorted(s1), sorted(s2)) |
| 67 | |
ivan-zhu | a2c9cd5 | 2013-08-20 20:01:44 +0800 | [diff] [blame] | 68 | @attr(type='gate') |
| 69 | def test_get_service_by_service_and_host_name(self): |
| 70 | resp, services = self.client.list_services() |
| 71 | host_name = services[0]['host'] |
| 72 | binary_name = services[0]['binary'] |
| 73 | params = {'host': host_name, 'binary': binary_name} |
Ken'ichi Ohmichi | 986bf41 | 2014-03-06 04:06:21 +0900 | [diff] [blame] | 74 | |
ivan-zhu | a2c9cd5 | 2013-08-20 20:01:44 +0800 | [diff] [blame] | 75 | resp, services = self.client.list_services(params) |
Chris Yeoh | c266b28 | 2014-03-13 18:19:00 +1030 | [diff] [blame] | 76 | self.assertEqual(200, resp.status) |
ivan-zhu | a2c9cd5 | 2013-08-20 20:01:44 +0800 | [diff] [blame] | 77 | self.assertEqual(1, len(services)) |
| 78 | self.assertEqual(host_name, services[0]['host']) |
| 79 | self.assertEqual(binary_name, services[0]['binary']) |