blob: 592648814a616fc5498e06c75d8b3d76496eefee [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
29 resp, _ = self.client.delete_service(service_id)
Ken'ichi Ohmichiaa8974e2014-03-18 17:19:07 +090030 self.assertEqual(204, resp.status)
Attila Fazekas97a47082013-12-17 15:15:27 +010031 # Checking whether service is deleted successfully
32 self.assertRaises(exceptions.NotFound, self.client.get_service,
33 service_id)
34
Matthew Treinish5c660ab2014-05-18 21:14:36 -040035 @test.attr(type='smoke')
rajalakshmi-ganesanefc8bd72012-05-30 17:52:11 +053036 def test_create_get_delete_service(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -050037 # GET Service
Attila Fazekas97a47082013-12-17 15:15:27 +010038 # Creating a Service
39 name = data_utils.rand_name('service-')
40 type = data_utils.rand_name('type--')
41 description = data_utils.rand_name('description-')
42 resp, service_data = self.client.create_service(
43 name, type, description=description)
44 self.assertFalse(service_data['id'] is None)
45 self.addCleanup(self._del_service, service_data['id'])
Ken'ichi Ohmichiaa8974e2014-03-18 17:19:07 +090046 self.assertEqual(200, resp.status)
Attila Fazekas97a47082013-12-17 15:15:27 +010047 # Verifying response body of create service
48 self.assertIn('id', service_data)
49 self.assertIn('name', service_data)
50 self.assertEqual(name, service_data['name'])
51 self.assertIn('type', service_data)
52 self.assertEqual(type, service_data['type'])
53 self.assertIn('description', service_data)
54 self.assertEqual(description, service_data['description'])
55 # Get service
56 resp, fetched_service = self.client.get_service(service_data['id'])
Ken'ichi Ohmichiaa8974e2014-03-18 17:19:07 +090057 self.assertEqual(200, resp.status)
Attila Fazekas97a47082013-12-17 15:15:27 +010058 # verifying the existence of service created
59 self.assertIn('id', fetched_service)
60 self.assertEqual(fetched_service['id'], service_data['id'])
61 self.assertIn('name', fetched_service)
62 self.assertEqual(fetched_service['name'], service_data['name'])
63 self.assertIn('type', fetched_service)
64 self.assertEqual(fetched_service['type'], service_data['type'])
65 self.assertIn('description', fetched_service)
66 self.assertEqual(fetched_service['description'],
67 service_data['description'])
Vincent Hou6b8a7b72012-08-25 01:24:33 +080068
Matthew Treinish5c660ab2014-05-18 21:14:36 -040069 @test.attr(type='gate')
Gong Zhangcb6b8862014-02-20 15:14:05 +080070 def test_create_service_without_description(self):
71 # Create a service only with name and type
72 name = data_utils.rand_name('service-')
73 type = data_utils.rand_name('type--')
74 resp, service = self.client.create_service(name, type)
75 self.assertIn('id', service)
76 self.assertTrue('200', resp['status'])
77 self.addCleanup(self._del_service, service['id'])
78 self.assertIn('name', service)
79 self.assertEqual(name, service['name'])
80 self.assertIn('type', service)
81 self.assertEqual(type, service['type'])
82
Matthew Treinish5c660ab2014-05-18 21:14:36 -040083 @test.attr(type='smoke')
umamohanb51ad002013-01-24 18:13:15 +000084 def test_list_services(self):
85 # Create, List, Verify and Delete Services
86 services = []
llg821243b20502014-02-22 10:32:49 +080087 for _ in moves.xrange(3):
Masayuki Igawa259c1132013-10-31 17:48:44 +090088 name = data_utils.rand_name('service-')
89 type = data_utils.rand_name('type--')
90 description = data_utils.rand_name('description-')
umamohanb51ad002013-01-24 18:13:15 +000091 resp, service = self.client.create_service(
92 name, type, description=description)
93 services.append(service)
94 service_ids = map(lambda x: x['id'], services)
95
David Kranzce2c8b72013-03-18 10:53:25 -040096 def delete_services():
97 for service_id in service_ids:
98 self.client.delete_service(service_id)
99
100 self.addCleanup(delete_services)
umamohanb51ad002013-01-24 18:13:15 +0000101 # List and Verify Services
102 resp, body = self.client.list_services()
Ken'ichi Ohmichiaa8974e2014-03-18 17:19:07 +0900103 self.assertEqual(200, resp.status)
Matthew Treinishc795b9e2014-06-09 17:01:10 -0400104 found = [serv for serv in body if serv['id'] in service_ids]
umamohanb51ad002013-01-24 18:13:15 +0000105 self.assertEqual(len(found), len(services), 'Services not found')
106
Vincent Hou6b8a7b72012-08-25 01:24:33 +0800107
Attila Fazekas0d0c6162013-02-24 09:14:23 +0100108class ServicesTestXML(ServicesTestJSON):
109 _interface = 'xml'