blob: a9782a9b3fbb3418d00fb37075680e5f8cdc1078 [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
rajalakshmi-ganesanefc8bd72012-05-30 17:52:11 +053017
Sean Dague1937d092013-05-17 16:36:38 -040018from tempest.api.identity import base
Masayuki Igawa259c1132013-10-31 17:48:44 +090019from tempest.common.utils import data_utils
Matthew Treinisha83a16e2012-12-07 13:44:02 -050020from tempest import exceptions
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):
Attila Fazekas0d0c6162013-02-24 09:14:23 +010025 _interface = 'json'
rajalakshmi-ganesanefc8bd72012-05-30 17:52:11 +053026
Attila Fazekas97a47082013-12-17 15:15:27 +010027 def _del_service(self, service_id):
28 # Deleting the service created in this method
David Kranze9d2f422014-07-02 13:57:41 -040029 self.client.delete_service(service_id)
Attila Fazekas97a47082013-12-17 15:15:27 +010030 # Checking whether service is deleted successfully
31 self.assertRaises(exceptions.NotFound, self.client.get_service,
32 service_id)
33
Matthew Treinish5c660ab2014-05-18 21:14:36 -040034 @test.attr(type='smoke')
rajalakshmi-ganesanefc8bd72012-05-30 17:52:11 +053035 def test_create_get_delete_service(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -050036 # GET Service
Attila Fazekas97a47082013-12-17 15:15:27 +010037 # Creating a Service
38 name = data_utils.rand_name('service-')
39 type = data_utils.rand_name('type--')
40 description = data_utils.rand_name('description-')
David Kranze9d2f422014-07-02 13:57:41 -040041 _, service_data = self.client.create_service(
Attila Fazekas97a47082013-12-17 15:15:27 +010042 name, type, description=description)
43 self.assertFalse(service_data['id'] is None)
44 self.addCleanup(self._del_service, service_data['id'])
Attila Fazekas97a47082013-12-17 15:15:27 +010045 # Verifying response body of create service
46 self.assertIn('id', service_data)
47 self.assertIn('name', service_data)
48 self.assertEqual(name, service_data['name'])
49 self.assertIn('type', service_data)
50 self.assertEqual(type, service_data['type'])
51 self.assertIn('description', service_data)
52 self.assertEqual(description, service_data['description'])
53 # Get service
David Kranze9d2f422014-07-02 13:57:41 -040054 _, fetched_service = self.client.get_service(service_data['id'])
Attila Fazekas97a47082013-12-17 15:15:27 +010055 # verifying the existence of service created
56 self.assertIn('id', fetched_service)
57 self.assertEqual(fetched_service['id'], service_data['id'])
58 self.assertIn('name', fetched_service)
59 self.assertEqual(fetched_service['name'], service_data['name'])
60 self.assertIn('type', fetched_service)
61 self.assertEqual(fetched_service['type'], service_data['type'])
62 self.assertIn('description', fetched_service)
63 self.assertEqual(fetched_service['description'],
64 service_data['description'])
Vincent Hou6b8a7b72012-08-25 01:24:33 +080065
Matthew Treinish5c660ab2014-05-18 21:14:36 -040066 @test.attr(type='gate')
Gong Zhangcb6b8862014-02-20 15:14:05 +080067 def test_create_service_without_description(self):
68 # Create a service only with name and type
69 name = data_utils.rand_name('service-')
70 type = data_utils.rand_name('type--')
David Kranze9d2f422014-07-02 13:57:41 -040071 _, service = self.client.create_service(name, type)
Gong Zhangcb6b8862014-02-20 15:14:05 +080072 self.assertIn('id', service)
Gong Zhangcb6b8862014-02-20 15:14:05 +080073 self.addCleanup(self._del_service, service['id'])
74 self.assertIn('name', service)
75 self.assertEqual(name, service['name'])
76 self.assertIn('type', service)
77 self.assertEqual(type, service['type'])
78
Matthew Treinish5c660ab2014-05-18 21:14:36 -040079 @test.attr(type='smoke')
umamohanb51ad002013-01-24 18:13:15 +000080 def test_list_services(self):
81 # Create, List, Verify and Delete Services
82 services = []
llg821243b20502014-02-22 10:32:49 +080083 for _ in moves.xrange(3):
Masayuki Igawa259c1132013-10-31 17:48:44 +090084 name = data_utils.rand_name('service-')
85 type = data_utils.rand_name('type--')
86 description = data_utils.rand_name('description-')
David Kranze9d2f422014-07-02 13:57:41 -040087 _, service = self.client.create_service(
umamohanb51ad002013-01-24 18:13:15 +000088 name, type, description=description)
89 services.append(service)
90 service_ids = map(lambda x: x['id'], services)
91
David Kranzce2c8b72013-03-18 10:53:25 -040092 def delete_services():
93 for service_id in service_ids:
94 self.client.delete_service(service_id)
95
96 self.addCleanup(delete_services)
umamohanb51ad002013-01-24 18:13:15 +000097 # List and Verify Services
David Kranze9d2f422014-07-02 13:57:41 -040098 _, body = self.client.list_services()
Matthew Treinishc795b9e2014-06-09 17:01:10 -040099 found = [serv for serv in body if serv['id'] in service_ids]
umamohanb51ad002013-01-24 18:13:15 +0000100 self.assertEqual(len(found), len(services), 'Services not found')
101
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800102
Attila Fazekas0d0c6162013-02-24 09:14:23 +0100103class ServicesTestXML(ServicesTestJSON):
104 _interface = 'xml'