blob: 182b24cc7247c0b65911b9b1f561fefa3c0d5654 [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
Sean Dague1937d092013-05-17 16:36:38 -040016from tempest.api.identity import base
Ken'ichi Ohmichi7bd25752017-03-10 10:45:39 -080017from tempest.lib.common.utils import data_utils
Ken'ichi Ohmichieeabdd22017-01-27 17:46:00 -080018from tempest.lib import decorators
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -050019from tempest.lib import exceptions as lib_exc
rajalakshmi-ganesanefc8bd72012-05-30 17:52:11 +053020
21
Matthew Treinishdb2c5972014-01-31 22:18:59 +000022class ServicesTestJSON(base.BaseIdentityV2AdminTest):
zhuflb9358202020-04-27 16:12:52 +080023 """Test identity services via v2 API"""
rajalakshmi-ganesanefc8bd72012-05-30 17:52:11 +053024
Attila Fazekas97a47082013-12-17 15:15:27 +010025 def _del_service(self, service_id):
26 # Deleting the service created in this method
Daniel Mellado72f24ec2015-12-21 10:26:42 +000027 self.services_client.delete_service(service_id)
Attila Fazekas97a47082013-12-17 15:15:27 +010028 # Checking whether service is deleted successfully
Daniel Mellado72f24ec2015-12-21 10:26:42 +000029 self.assertRaises(lib_exc.NotFound, self.services_client.show_service,
Attila Fazekas97a47082013-12-17 15:15:27 +010030 service_id)
31
Ken'ichi Ohmichieeabdd22017-01-27 17:46:00 -080032 @decorators.idempotent_id('84521085-c6e6-491c-9a08-ec9f70f90110')
rajalakshmi-ganesanefc8bd72012-05-30 17:52:11 +053033 def test_create_get_delete_service(self):
zhuflb9358202020-04-27 16:12:52 +080034 """Test verifies the identity service create/get/delete via v2 API"""
Sean Dague46c4a2b2013-01-03 17:54:17 -050035 # GET Service
Attila Fazekas97a47082013-12-17 15:15:27 +010036 # Creating a Service
Ken'ichi Ohmichi96508472015-03-23 01:43:42 +000037 name = data_utils.rand_name('service')
ghanshyam6ce39212016-06-15 13:20:11 +090038 s_type = data_utils.rand_name('type')
Ken'ichi Ohmichi96508472015-03-23 01:43:42 +000039 description = data_utils.rand_name('description')
Daniel Mellado72f24ec2015-12-21 10:26:42 +000040 service_data = self.services_client.create_service(
ghanshyam6ce39212016-06-15 13:20:11 +090041 name=name, type=s_type,
42 description=description)['OS-KSADM:service']
Béla Vancsics64862f72016-11-08 09:12:31 +010043 self.assertIsNotNone(service_data['id'])
Attila Fazekas97a47082013-12-17 15:15:27 +010044 self.addCleanup(self._del_service, service_data['id'])
Attila Fazekas97a47082013-12-17 15:15:27 +010045 # Verifying response body of create service
Attila Fazekas97a47082013-12-17 15:15:27 +010046 self.assertIn('name', service_data)
47 self.assertEqual(name, service_data['name'])
48 self.assertIn('type', service_data)
ghanshyam6ce39212016-06-15 13:20:11 +090049 self.assertEqual(s_type, service_data['type'])
Attila Fazekas97a47082013-12-17 15:15:27 +010050 self.assertIn('description', service_data)
51 self.assertEqual(description, service_data['description'])
52 # Get service
Daniel Mellado72f24ec2015-12-21 10:26:42 +000053 fetched_service = (
54 self.services_client.show_service(service_data['id'])
55 ['OS-KSADM:service'])
Attila Fazekas97a47082013-12-17 15:15:27 +010056 # verifying the existence of service created
57 self.assertIn('id', fetched_service)
58 self.assertEqual(fetched_service['id'], service_data['id'])
59 self.assertIn('name', fetched_service)
60 self.assertEqual(fetched_service['name'], service_data['name'])
61 self.assertIn('type', fetched_service)
62 self.assertEqual(fetched_service['type'], service_data['type'])
63 self.assertIn('description', fetched_service)
64 self.assertEqual(fetched_service['description'],
65 service_data['description'])
Vincent Hou6b8a7b72012-08-25 01:24:33 +080066
Ken'ichi Ohmichieeabdd22017-01-27 17:46:00 -080067 @decorators.idempotent_id('5d3252c8-e555-494b-a6c8-e11d7335da42')
Gong Zhangcb6b8862014-02-20 15:14:05 +080068 def test_create_service_without_description(self):
zhuflb9358202020-04-27 16:12:52 +080069 """Test creating identity service without description via v2 API
70
71 Create a service only with name and type.
72 """
Ken'ichi Ohmichi96508472015-03-23 01:43:42 +000073 name = data_utils.rand_name('service')
ghanshyam6ce39212016-06-15 13:20:11 +090074 s_type = data_utils.rand_name('type')
75 service = self.services_client.create_service(
76 name=name, type=s_type)['OS-KSADM:service']
Gong Zhangcb6b8862014-02-20 15:14:05 +080077 self.assertIn('id', service)
Gong Zhangcb6b8862014-02-20 15:14:05 +080078 self.addCleanup(self._del_service, service['id'])
79 self.assertIn('name', service)
80 self.assertEqual(name, service['name'])
81 self.assertIn('type', service)
ghanshyam6ce39212016-06-15 13:20:11 +090082 self.assertEqual(s_type, service['type'])
Gong Zhangcb6b8862014-02-20 15:14:05 +080083
Jordan Pittier3b46d272017-04-12 16:17:28 +020084 @decorators.attr(type='smoke')
Ken'ichi Ohmichieeabdd22017-01-27 17:46:00 -080085 @decorators.idempotent_id('34ea6489-012d-4a86-9038-1287cadd5eca')
umamohanb51ad002013-01-24 18:13:15 +000086 def test_list_services(self):
zhuflb9358202020-04-27 16:12:52 +080087 """Test Create/List/Verify/Delete of identity service via v2 API"""
umamohanb51ad002013-01-24 18:13:15 +000088 services = []
Sirushti Murugesan12dc9732016-07-13 22:49:17 +053089 for _ in range(3):
Ken'ichi Ohmichi96508472015-03-23 01:43:42 +000090 name = data_utils.rand_name('service')
ghanshyam6ce39212016-06-15 13:20:11 +090091 s_type = data_utils.rand_name('type')
Ken'ichi Ohmichi96508472015-03-23 01:43:42 +000092 description = data_utils.rand_name('description')
ghanshyam6ce39212016-06-15 13:20:11 +090093
Daniel Mellado72f24ec2015-12-21 10:26:42 +000094 service = self.services_client.create_service(
ghanshyam6ce39212016-06-15 13:20:11 +090095 name=name, type=s_type,
96 description=description)['OS-KSADM:service']
zhuflf824fcf2018-11-14 15:44:18 +080097 self.addCleanup(self.services_client.delete_service, service['id'])
umamohanb51ad002013-01-24 18:13:15 +000098 services.append(service)
Sirushti Murugesan935f2cc2016-07-12 19:48:24 +053099 service_ids = [svc['id'] for svc in services]
umamohanb51ad002013-01-24 18:13:15 +0000100
101 # List and Verify Services
Daniel Mellado72f24ec2015-12-21 10:26:42 +0000102 body = self.services_client.list_services()['OS-KSADM:services']
Matthew Treinishc795b9e2014-06-09 17:01:10 -0400103 found = [serv for serv in body if serv['id'] in service_ids]
umamohanb51ad002013-01-24 18:13:15 +0000104 self.assertEqual(len(found), len(services), 'Services not found')