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 |
Masayuki Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 18 | from tempest import test |
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): |
Leo Toyoda | 3ae31e1 | 2013-04-19 11:19:57 +0900 | [diff] [blame] | 22 | |
| 23 | """ |
| 24 | Tests Services API. List and Enable/Disable require admin privileges. |
| 25 | """ |
| 26 | |
Leo Toyoda | 3ae31e1 | 2013-04-19 11:19:57 +0900 | [diff] [blame] | 27 | @classmethod |
| 28 | def setUpClass(cls): |
| 29 | super(ServicesAdminTestJSON, cls).setUpClass() |
| 30 | cls.client = cls.os_adm.services_client |
Leo Toyoda | 3ae31e1 | 2013-04-19 11:19:57 +0900 | [diff] [blame] | 31 | |
Masayuki Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 32 | @test.attr(type='gate') |
Leo Toyoda | 3ae31e1 | 2013-04-19 11:19:57 +0900 | [diff] [blame] | 33 | def test_list_services(self): |
Leo Toyoda | 3ae31e1 | 2013-04-19 11:19:57 +0900 | [diff] [blame] | 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) |
Liu, Zhi Kun | d42c991 | 2013-07-18 23:03:57 +0800 | [diff] [blame] | 36 | self.assertNotEqual(0, len(services)) |
Leo Toyoda | 3ae31e1 | 2013-04-19 11:19:57 +0900 | [diff] [blame] | 37 | |
Masayuki Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 38 | @test.attr(type='gate') |
Liu, Zhi Kun | d42c991 | 2013-07-18 23:03:57 +0800 | [diff] [blame] | 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) |
Liu, Zhi Kun | d42c991 | 2013-07-18 23:03:57 +0800 | [diff] [blame] | 44 | self.assertNotEqual(0, len(services)) |
| 45 | for service in services: |
| 46 | self.assertEqual(binary_name, service['binary']) |
| 47 | |
Masayuki Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 48 | @test.attr(type='gate') |
Liu, Zhi Kun | d42c991 | 2013-07-18 23:03:57 +0800 | [diff] [blame] | 49 | def test_get_service_by_host_name(self): |
| 50 | resp, services = self.client.list_services() |
| 51 | host_name = services[0]['host'] |
| 52 | services_on_host = [service for service in services if |
| 53 | service['host'] == host_name] |
| 54 | params = {'host': host_name} |
Ken'ichi Ohmichi | 986bf41 | 2014-03-06 04:06:21 +0900 | [diff] [blame] | 55 | |
Liu, Zhi Kun | d42c991 | 2013-07-18 23:03:57 +0800 | [diff] [blame] | 56 | resp, services = self.client.list_services(params) |
Sean Dague | 3b61649 | 2013-07-26 15:04:12 -0400 | [diff] [blame] | 57 | |
| 58 | # we could have a periodic job checkin between the 2 service |
| 59 | # lookups, so only compare binary lists. |
| 60 | s1 = map(lambda x: x['binary'], services) |
| 61 | s2 = map(lambda x: x['binary'], services_on_host) |
Sumanth Nagadavalli | 3142220 | 2013-07-31 10:54:21 +0530 | [diff] [blame] | 62 | |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 63 | # sort the lists before comparing, to take out dependency |
| 64 | # on order. |
Sumanth Nagadavalli | 3142220 | 2013-07-31 10:54:21 +0530 | [diff] [blame] | 65 | self.assertEqual(sorted(s1), sorted(s2)) |
Liu, Zhi Kun | d42c991 | 2013-07-18 23:03:57 +0800 | [diff] [blame] | 66 | |
Masayuki Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 67 | @test.attr(type='gate') |
Liu, Zhi Kun | d42c991 | 2013-07-18 23:03:57 +0800 | [diff] [blame] | 68 | def test_get_service_by_service_and_host_name(self): |
| 69 | resp, services = self.client.list_services() |
| 70 | host_name = services[0]['host'] |
| 71 | binary_name = services[0]['binary'] |
| 72 | params = {'host': host_name, 'binary': binary_name} |
Ken'ichi Ohmichi | 986bf41 | 2014-03-06 04:06:21 +0900 | [diff] [blame] | 73 | |
Liu, Zhi Kun | d42c991 | 2013-07-18 23:03:57 +0800 | [diff] [blame] | 74 | resp, services = self.client.list_services(params) |
Chris Yeoh | c266b28 | 2014-03-13 18:19:00 +1030 | [diff] [blame] | 75 | self.assertEqual(200, resp.status) |
Liu, Zhi Kun | d42c991 | 2013-07-18 23:03:57 +0800 | [diff] [blame] | 76 | self.assertEqual(1, len(services)) |
| 77 | self.assertEqual(host_name, services[0]['host']) |
| 78 | self.assertEqual(binary_name, services[0]['binary']) |
| 79 | |
Leo Toyoda | 3ae31e1 | 2013-04-19 11:19:57 +0900 | [diff] [blame] | 80 | |
| 81 | class ServicesAdminTestXML(ServicesAdminTestJSON): |
| 82 | _interface = 'xml' |