Leo Toyoda | 3ae31e1 | 2013-04-19 11:19:57 +0900 | [diff] [blame] | 1 | # Copyright 2013 NEC Corporation |
Liu, Zhi Kun | d42c991 | 2013-07-18 23:03:57 +0800 | [diff] [blame] | 2 | # Copyright 2013 IBM Corp. |
Leo Toyoda | 3ae31e1 | 2013-04-19 11:19:57 +0900 | [diff] [blame] | 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 | |
Sean Dague | 1937d09 | 2013-05-17 16:36:38 -0400 | [diff] [blame] | 17 | from tempest.api.compute import base |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 18 | from tempest.lib import decorators |
Leo Toyoda | 3ae31e1 | 2013-04-19 11:19:57 +0900 | [diff] [blame] | 19 | |
| 20 | |
ivan-zhu | f2b0050 | 2013-10-18 10:06:52 +0800 | [diff] [blame] | 21 | class ServicesAdminTestJSON(base.BaseV2ComputeAdminTest): |
Ken'ichi Ohmichi | 88363cb | 2015-11-19 08:00:54 +0000 | [diff] [blame] | 22 | """Tests Services API. List and Enable/Disable require admin privileges.""" |
Leo Toyoda | 3ae31e1 | 2013-04-19 11:19:57 +0900 | [diff] [blame] | 23 | |
Leo Toyoda | 3ae31e1 | 2013-04-19 11:19:57 +0900 | [diff] [blame] | 24 | @classmethod |
Rohan Kanade | 60b7309 | 2015-02-04 17:58:19 +0530 | [diff] [blame] | 25 | def setup_clients(cls): |
| 26 | super(ServicesAdminTestJSON, cls).setup_clients() |
Leo Toyoda | 3ae31e1 | 2013-04-19 11:19:57 +0900 | [diff] [blame] | 27 | cls.client = cls.os_adm.services_client |
Leo Toyoda | 3ae31e1 | 2013-04-19 11:19:57 +0900 | [diff] [blame] | 28 | |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 29 | @decorators.idempotent_id('5be41ef4-53d1-41cc-8839-5c2a48a1b283') |
Leo Toyoda | 3ae31e1 | 2013-04-19 11:19:57 +0900 | [diff] [blame] | 30 | def test_list_services(self): |
ghanshyam | 0de0284 | 2015-08-24 17:47:41 +0900 | [diff] [blame] | 31 | services = self.client.list_services()['services'] |
Liu, Zhi Kun | d42c991 | 2013-07-18 23:03:57 +0800 | [diff] [blame] | 32 | self.assertNotEqual(0, len(services)) |
Leo Toyoda | 3ae31e1 | 2013-04-19 11:19:57 +0900 | [diff] [blame] | 33 | |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 34 | @decorators.idempotent_id('f345b1ec-bc6e-4c38-a527-3ca2bc00bef5') |
Liu, Zhi Kun | d42c991 | 2013-07-18 23:03:57 +0800 | [diff] [blame] | 35 | def test_get_service_by_service_binary_name(self): |
| 36 | binary_name = 'nova-compute' |
ghanshyam | 0de0284 | 2015-08-24 17:47:41 +0900 | [diff] [blame] | 37 | services = self.client.list_services(binary=binary_name)['services'] |
Liu, Zhi Kun | d42c991 | 2013-07-18 23:03:57 +0800 | [diff] [blame] | 38 | self.assertNotEqual(0, len(services)) |
| 39 | for service in services: |
| 40 | self.assertEqual(binary_name, service['binary']) |
| 41 | |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 42 | @decorators.idempotent_id('affb42d5-5b4b-43c8-8b0b-6dca054abcca') |
Liu, Zhi Kun | d42c991 | 2013-07-18 23:03:57 +0800 | [diff] [blame] | 43 | def test_get_service_by_host_name(self): |
ghanshyam | 0de0284 | 2015-08-24 17:47:41 +0900 | [diff] [blame] | 44 | services = self.client.list_services()['services'] |
Liu, Zhi Kun | d42c991 | 2013-07-18 23:03:57 +0800 | [diff] [blame] | 45 | host_name = services[0]['host'] |
| 46 | services_on_host = [service for service in services if |
| 47 | service['host'] == host_name] |
Ken'ichi Ohmichi | 986bf41 | 2014-03-06 04:06:21 +0900 | [diff] [blame] | 48 | |
ghanshyam | 0de0284 | 2015-08-24 17:47:41 +0900 | [diff] [blame] | 49 | services = self.client.list_services(host=host_name)['services'] |
Sean Dague | 3b61649 | 2013-07-26 15:04:12 -0400 | [diff] [blame] | 50 | |
| 51 | # we could have a periodic job checkin between the 2 service |
| 52 | # lookups, so only compare binary lists. |
| 53 | s1 = map(lambda x: x['binary'], services) |
| 54 | s2 = map(lambda x: x['binary'], services_on_host) |
Sumanth Nagadavalli | 3142220 | 2013-07-31 10:54:21 +0530 | [diff] [blame] | 55 | |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 56 | # sort the lists before comparing, to take out dependency |
| 57 | # on order. |
Sumanth Nagadavalli | 3142220 | 2013-07-31 10:54:21 +0530 | [diff] [blame] | 58 | self.assertEqual(sorted(s1), sorted(s2)) |
Liu, Zhi Kun | d42c991 | 2013-07-18 23:03:57 +0800 | [diff] [blame] | 59 | |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 60 | @decorators.idempotent_id('39397f6f-37b8-4234-8671-281e44c74025') |
Liu, Zhi Kun | d42c991 | 2013-07-18 23:03:57 +0800 | [diff] [blame] | 61 | def test_get_service_by_service_and_host_name(self): |
ghanshyam | 0de0284 | 2015-08-24 17:47:41 +0900 | [diff] [blame] | 62 | services = self.client.list_services()['services'] |
Liu, Zhi Kun | d42c991 | 2013-07-18 23:03:57 +0800 | [diff] [blame] | 63 | host_name = services[0]['host'] |
| 64 | binary_name = services[0]['binary'] |
Ken'ichi Ohmichi | 986bf41 | 2014-03-06 04:06:21 +0900 | [diff] [blame] | 65 | |
Ken'ichi Ohmichi | 118776d | 2015-07-01 08:15:00 +0000 | [diff] [blame] | 66 | services = self.client.list_services(host=host_name, |
ghanshyam | 0de0284 | 2015-08-24 17:47:41 +0900 | [diff] [blame] | 67 | binary=binary_name)['services'] |
Liu, Zhi Kun | d42c991 | 2013-07-18 23:03:57 +0800 | [diff] [blame] | 68 | self.assertEqual(1, len(services)) |
| 69 | self.assertEqual(host_name, services[0]['host']) |
| 70 | self.assertEqual(binary_name, services[0]['binary']) |