Skip to content

Commit 566987e

Browse files
Guojian ShaoTerryHowe
authored andcommitted
add functional tests for identity v3
add functional tests for endpoint, region and service. Change-Id: I504878811dc8f9fcb2295cbf7419885959d9c1f6 Implements: blueprint identity-functional-tests
1 parent bbe71eb commit 566987e

5 files changed

Lines changed: 279 additions & 11 deletions

File tree

‎functional/tests/identity/v3/test_catalog.py‎

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,20 @@ def test_catalog_show(self):
2424
"""test catalog show command
2525
2626
The output example:
27-
+-----------+-------------------------------------------+
28-
| Field | Value |
29-
+-----------+-------------------------------------------+
30-
| endpoints | test1 |
31-
| | publicURL: http://localhost:5000/v2.0 |
32-
| | internalURL: http://localhost:5000/v2.0 |
33-
| | adminURL: http://localhost:5000/v2.0 |
34-
| | |
35-
| name | keystone |
36-
| type | identity |
37-
+-----------+-------------------------------------------+
27+
+-----------+----------------------------------------+
28+
| Field | Value |
29+
+-----------+----------------------------------------+
30+
| endpoints | test1 |
31+
| | public: http://localhost:5000/v2.0 |
32+
| | test1 |
33+
| | internal: http://localhost:5000/v2.0 |
34+
| | test1 |
35+
| | admin: http://localhost:35357/v2.0 |
36+
| | |
37+
| id | e1e68b5ba21a43a39ff1cf58e736c3aa |
38+
| name | keystone |
39+
| type | identity |
40+
+-----------+----------------------------------------+
3841
"""
3942
raw_output = self.openstack('catalog show %s' % 'identity')
4043
items = self.parse_show(raw_output)
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
13+
from tempest_lib.common.utils import data_utils
14+
15+
from functional.tests.identity.v3 import test_identity
16+
17+
18+
class EndpointTests(test_identity.IdentityTests):
19+
20+
def test_endpoint_create(self):
21+
self._create_dummy_endpoint(interface='public')
22+
self._create_dummy_endpoint(interface='admin')
23+
self._create_dummy_endpoint(interface='internal')
24+
25+
def test_endpoint_delete(self):
26+
endpoint_id = self._create_dummy_endpoint(add_clean_up=False)
27+
raw_output = self.openstack(
28+
'endpoint delete %s' % endpoint_id)
29+
self.assertEqual(0, len(raw_output))
30+
31+
def test_endpoint_list(self):
32+
endpoint_id = self._create_dummy_endpoint()
33+
raw_output = self.openstack('endpoint list')
34+
self.assertInOutput(endpoint_id, raw_output)
35+
items = self.parse_listing(raw_output)
36+
self.assert_table_structure(items, self.ENDPOINT_LIST_HEADERS)
37+
38+
def test_endpoint_set(self):
39+
endpoint_id = self._create_dummy_endpoint()
40+
new_endpoint_url = data_utils.rand_url()
41+
raw_output = self.openstack(
42+
'endpoint set '
43+
'--interface %(interface)s '
44+
'--url %(url)s '
45+
'--disable '
46+
'%(endpoint_id)s' % {'interface': 'admin',
47+
'url': new_endpoint_url,
48+
'endpoint_id': endpoint_id})
49+
self.assertEqual(0, len(raw_output))
50+
raw_output = self.openstack('endpoint show %s' % endpoint_id)
51+
endpoint = self.parse_show_as_object(raw_output)
52+
self.assertEqual('admin', endpoint['interface'])
53+
self.assertEqual(new_endpoint_url, endpoint['url'])
54+
self.assertEqual('False', endpoint['enabled'])
55+
56+
def test_endpoint_show(self):
57+
endpoint_id = self._create_dummy_endpoint()
58+
raw_output = self.openstack('endpoint show %s' % endpoint_id)
59+
items = self.parse_show(raw_output)
60+
self.assert_show_fields(items, self.ENDPOINT_FIELDS)

‎functional/tests/identity/v3/test_identity.py‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ class IdentityTests(test.TestCase):
3131
PROJECT_FIELDS = ['description', 'id', 'domain_id',
3232
'enabled', 'name', 'parent_id', 'links']
3333
ROLE_FIELDS = ['id', 'name', 'links']
34+
SERVICE_FIELDS = ['id', 'enabled', 'name', 'type', 'description']
35+
REGION_FIELDS = ['description', 'enabled', 'parent_region',
36+
'region', 'url']
37+
ENDPOINT_FIELDS = ['id', 'region', 'region_id', 'service_id',
38+
'service_name', 'service_type', 'enabled',
39+
'interface', 'url']
40+
41+
REGION_LIST_HEADERS = ['Region', 'Parent Region', 'Description', 'URL']
42+
ENDPOINT_LIST_HEADERS = ['ID', 'Region', 'Service Name', 'Service Type',
43+
'Enabled', 'Interface', 'URL']
3444

3545
@classmethod
3646
def setUpClass(cls):
@@ -68,7 +78,9 @@ def setUpClass(cls):
6878

6979
@classmethod
7080
def tearDownClass(cls):
81+
# delete dummy project
7182
cls.openstack('project delete %s' % cls.project_name)
83+
# disable and delete dummy domain
7284
cls.openstack('domain set --disable %s' % cls.domain_name)
7385
cls.openstack('domain delete %s' % cls.domain_name)
7486

@@ -173,3 +185,69 @@ def _create_dummy_project(self, add_clean_up=True):
173185
'%(name)s' % {'domain': self.domain_name,
174186
'name': project_name})
175187
return project_name
188+
189+
def _create_dummy_region(self, parent_region=None, add_clean_up=True):
190+
region_id = data_utils.rand_name('TestRegion')
191+
description = data_utils.rand_name('description')
192+
url = data_utils.rand_url()
193+
parent_region_arg = ''
194+
if parent_region is not None:
195+
parent_region_arg = '--parent-region %s' % parent_region
196+
raw_output = self.openstack(
197+
'region create '
198+
'%(parent_region_arg)s '
199+
'--description %(description)s '
200+
'--url %(url)s '
201+
'%(id)s' % {'parent_region_arg': parent_region_arg,
202+
'description': description,
203+
'url': url,
204+
'id': region_id})
205+
items = self.parse_show(raw_output)
206+
self.assert_show_fields(items, self.REGION_FIELDS)
207+
if add_clean_up:
208+
self.addCleanup(self.openstack,
209+
'region delete %s' % region_id)
210+
return region_id
211+
212+
def _create_dummy_service(self, add_clean_up=True):
213+
service_name = data_utils.rand_name('TestService')
214+
description = data_utils.rand_name('description')
215+
type_name = data_utils.rand_name('TestType')
216+
raw_output = self.openstack(
217+
'service create '
218+
'--name %(name)s '
219+
'--description %(description)s '
220+
'--enable '
221+
'%(type)s' % {'name': service_name,
222+
'description': description,
223+
'type': type_name})
224+
items = self.parse_show(raw_output)
225+
self.assert_show_fields(items, self.SERVICE_FIELDS)
226+
if add_clean_up:
227+
service = self.parse_show_as_object(raw_output)
228+
self.addCleanup(self.openstack,
229+
'service delete %s' % service['id'])
230+
return service_name
231+
232+
def _create_dummy_endpoint(self, interface='public', add_clean_up=True):
233+
region_id = self._create_dummy_region()
234+
service_name = self._create_dummy_service()
235+
endpoint_url = data_utils.rand_url()
236+
raw_output = self.openstack(
237+
'endpoint create '
238+
'--region %(region)s '
239+
'--enable '
240+
'%(service)s '
241+
'%(interface)s '
242+
'%(url)s' % {'region': region_id,
243+
'service': service_name,
244+
'interface': interface,
245+
'url': endpoint_url})
246+
items = self.parse_show(raw_output)
247+
self.assert_show_fields(items, self.ENDPOINT_FIELDS)
248+
endpoint = self.parse_show_as_object(raw_output)
249+
if add_clean_up:
250+
self.addCleanup(
251+
self.openstack,
252+
'endpoint delete %s' % endpoint['id'])
253+
return endpoint['id']
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
13+
from functional.tests.identity.v3 import test_identity
14+
15+
16+
class RegionTests(test_identity.IdentityTests):
17+
18+
def test_region_create(self):
19+
self._create_dummy_region()
20+
21+
def test_region_create_with_parent_region(self):
22+
parent_region_id = self._create_dummy_region()
23+
self._create_dummy_region(parent_region=parent_region_id)
24+
25+
def test_region_delete(self):
26+
region_id = self._create_dummy_region(add_clean_up=False)
27+
raw_output = self.openstack('region delete %s' % region_id)
28+
self.assertEqual(0, len(raw_output))
29+
30+
def test_region_list(self):
31+
raw_output = self.openstack('region list')
32+
items = self.parse_listing(raw_output)
33+
self.assert_table_structure(items, self.REGION_LIST_HEADERS)
34+
35+
def test_region_set(self):
36+
# prepare region with parent-region
37+
parent_region_id = self._create_dummy_region()
38+
new_parent_region_id = self._create_dummy_region()
39+
region_id = self._create_dummy_region(parent_region_id)
40+
# check region details
41+
raw_output = self.openstack('region show %s' % region_id)
42+
region = self.parse_show_as_object(raw_output)
43+
self.assertEqual(parent_region_id, region['parent_region'])
44+
self.assertEqual(region_id, region['region'])
45+
# update parent-region
46+
raw_output = self.openstack(
47+
'region set '
48+
'--parent-region %(parent_region)s '
49+
'%(region)s' % {'parent_region': new_parent_region_id,
50+
'region': region_id})
51+
self.assertEqual(0, len(raw_output))
52+
# check updated region details
53+
raw_output = self.openstack('region show %s' % region_id)
54+
region = self.parse_show_as_object(raw_output)
55+
self.assertEqual(new_parent_region_id, region['parent_region'])
56+
self.assertEqual(region_id, region['region'])
57+
58+
def test_region_show(self):
59+
region_id = self._create_dummy_region()
60+
raw_output = self.openstack('region show %s' % region_id)
61+
region = self.parse_show_as_object(raw_output)
62+
self.assertEqual(region_id, region['region'])
63+
self.assertEqual('None', region['parent_region'])
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
13+
from tempest_lib.common.utils import data_utils
14+
15+
from functional.tests.identity.v3 import test_identity
16+
17+
18+
class ServiceTests(test_identity.IdentityTests):
19+
20+
def test_service_create(self):
21+
self._create_dummy_service()
22+
23+
def test_service_delete(self):
24+
service_name = self._create_dummy_service(add_clean_up=False)
25+
raw_output = self.openstack('service delete %s' % service_name)
26+
self.assertEqual(0, len(raw_output))
27+
28+
def test_service_list(self):
29+
self._create_dummy_service()
30+
raw_output = self.openstack('service list')
31+
items = self.parse_listing(raw_output)
32+
self.assert_table_structure(items, test_identity.BASIC_LIST_HEADERS)
33+
34+
def test_service_set(self):
35+
service_name = self._create_dummy_service()
36+
# set service
37+
new_service_name = data_utils.rand_name('NewTestService')
38+
new_service_description = data_utils.rand_name('description')
39+
new_service_type = data_utils.rand_name('NewTestType')
40+
raw_output = self.openstack(
41+
'service set '
42+
'--type %(type)s '
43+
'--name %(name)s '
44+
'--description %(description)s '
45+
'--disable '
46+
'%(service)s' % {'type': new_service_type,
47+
'name': new_service_name,
48+
'description': new_service_description,
49+
'service': service_name})
50+
self.assertEqual(0, len(raw_output))
51+
# get service details
52+
raw_output = self.openstack('service show %s' % new_service_name)
53+
# assert service details
54+
service = self.parse_show_as_object(raw_output)
55+
self.assertEqual(new_service_type, service['type'])
56+
self.assertEqual(new_service_name, service['name'])
57+
self.assertEqual(new_service_description, service['description'])
58+
59+
def test_service_show(self):
60+
service_name = self._create_dummy_service()
61+
raw_output = self.openstack(
62+
'service show %s' % service_name)
63+
items = self.parse_show(raw_output)
64+
self.assert_show_fields(items, self.SERVICE_FIELDS)

0 commit comments

Comments
 (0)