blob: af38afcdc72a18def6aacb2294f3bab59abe55d2 [file] [log] [blame]
ZhiQiang Fan39f97222013-09-20 04:49:44 +08001# Copyright 2012 OpenStack Foundation
rajalakshmi-ganesanefc8bd72012-05-30 17:52:11 +05302# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
llg821243b20502014-02-22 10:32:49 +080016from six import moves
Masayuki Igawabfa07602015-01-20 18:47:17 +090017from tempest_lib import exceptions as lib_exc
rajalakshmi-ganesanefc8bd72012-05-30 17:52:11 +053018
Sean Dague1937d092013-05-17 16:36:38 -040019from tempest.api.identity import base
Masayuki Igawa259c1132013-10-31 17:48:44 +090020from tempest.common.utils import data_utils
Matthew Treinish5c660ab2014-05-18 21:14:36 -040021from tempest import test
rajalakshmi-ganesanefc8bd72012-05-30 17:52:11 +053022
23
Matthew Treinishdb2c5972014-01-31 22:18:59 +000024class ServicesTestJSON(base.BaseIdentityV2AdminTest):
rajalakshmi-ganesanefc8bd72012-05-30 17:52:11 +053025
Attila Fazekas97a47082013-12-17 15:15:27 +010026 def _del_service(self, service_id):
27 # Deleting the service created in this method
David Kranze9d2f422014-07-02 13:57:41 -040028 self.client.delete_service(service_id)
Attila Fazekas97a47082013-12-17 15:15:27 +010029 # Checking whether service is deleted successfully
Masayuki Igawabfa07602015-01-20 18:47:17 +090030 self.assertRaises(lib_exc.NotFound, self.client.get_service,
Attila Fazekas97a47082013-12-17 15:15:27 +010031 service_id)
32
Matthew Treinish5c660ab2014-05-18 21:14:36 -040033 @test.attr(type='smoke')
rajalakshmi-ganesanefc8bd72012-05-30 17:52:11 +053034 def test_create_get_delete_service(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -050035 # GET Service
Attila Fazekas97a47082013-12-17 15:15:27 +010036 # Creating a Service
37 name = data_utils.rand_name('service-')
38 type = data_utils.rand_name('type--')
39 description = data_utils.rand_name('description-')
David Kranzb7afa922014-12-30 10:56:26 -050040 service_data = self.client.create_service(
Attila Fazekas97a47082013-12-17 15:15:27 +010041 name, type, description=description)
42 self.assertFalse(service_data['id'] is None)
43 self.addCleanup(self._del_service, service_data['id'])
Attila Fazekas97a47082013-12-17 15:15:27 +010044 # Verifying response body of create service
45 self.assertIn('id', service_data)
46 self.assertIn('name', service_data)
47 self.assertEqual(name, service_data['name'])
48 self.assertIn('type', service_data)
49 self.assertEqual(type, service_data['type'])
50 self.assertIn('description', service_data)
51 self.assertEqual(description, service_data['description'])
52 # Get service
David Kranzb7afa922014-12-30 10:56:26 -050053 fetched_service = self.client.get_service(service_data['id'])
Attila Fazekas97a47082013-12-17 15:15:27 +010054 # verifying the existence of service created
55 self.assertIn('id', fetched_service)
56 self.assertEqual(fetched_service['id'], service_data['id'])
57 self.assertIn('name', fetched_service)
58 self.assertEqual(fetched_service['name'], service_data['name'])
59 self.assertIn('type', fetched_service)
60 self.assertEqual(fetched_service['type'], service_data['type'])
61 self.assertIn('description', fetched_service)
62 self.assertEqual(fetched_service['description'],
63 service_data['description'])
Vincent Hou6b8a7b72012-08-25 01:24:33 +080064
Matthew Treinish5c660ab2014-05-18 21:14:36 -040065 @test.attr(type='gate')
Gong Zhangcb6b8862014-02-20 15:14:05 +080066 def test_create_service_without_description(self):
67 # Create a service only with name and type
68 name = data_utils.rand_name('service-')
69 type = data_utils.rand_name('type--')
David Kranzb7afa922014-12-30 10:56:26 -050070 service = self.client.create_service(name, type)
Gong Zhangcb6b8862014-02-20 15:14:05 +080071 self.assertIn('id', service)
Gong Zhangcb6b8862014-02-20 15:14:05 +080072 self.addCleanup(self._del_service, service['id'])
73 self.assertIn('name', service)
74 self.assertEqual(name, service['name'])
75 self.assertIn('type', service)
76 self.assertEqual(type, service['type'])
77
Matthew Treinish5c660ab2014-05-18 21:14:36 -040078 @test.attr(type='smoke')
umamohanb51ad002013-01-24 18:13:15 +000079 def test_list_services(self):
80 # Create, List, Verify and Delete Services
81 services = []
llg821243b20502014-02-22 10:32:49 +080082 for _ in moves.xrange(3):
Masayuki Igawa259c1132013-10-31 17:48:44 +090083 name = data_utils.rand_name('service-')
84 type = data_utils.rand_name('type--')
85 description = data_utils.rand_name('description-')
David Kranzb7afa922014-12-30 10:56:26 -050086 service = self.client.create_service(
umamohanb51ad002013-01-24 18:13:15 +000087 name, type, description=description)
88 services.append(service)
89 service_ids = map(lambda x: x['id'], services)
90
David Kranzce2c8b72013-03-18 10:53:25 -040091 def delete_services():
92 for service_id in service_ids:
93 self.client.delete_service(service_id)
94
95 self.addCleanup(delete_services)
umamohanb51ad002013-01-24 18:13:15 +000096 # List and Verify Services
David Kranzb7afa922014-12-30 10:56:26 -050097 body = self.client.list_services()
Matthew Treinishc795b9e2014-06-09 17:01:10 -040098 found = [serv for serv in body if serv['id'] in service_ids]
umamohanb51ad002013-01-24 18:13:15 +000099 self.assertEqual(len(found), len(services), 'Services not found')