Skip to content

Commit 1ea34fc

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "add functional tests for identity v2"
2 parents dc3ff5e + e76de2c commit 1ea34fc

7 files changed

Lines changed: 462 additions & 88 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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.v2 import test_identity
14+
15+
16+
class CatalogTests(test_identity.IdentityTests):
17+
18+
def test_catalog_list(self):
19+
raw_output = self.openstack('catalog list')
20+
items = self.parse_listing(raw_output)
21+
self.assert_table_structure(items, self.CATALOG_LIST_HEADERS)
22+
23+
def test_catalog_show(self):
24+
"""test catalog show command
25+
26+
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+
+-----------+-------------------------------------------+
38+
"""
39+
raw_output = self.openstack('catalog show %s' % 'identity')
40+
items = self.parse_show(raw_output)
41+
# items may have multiple endpoint urls with empty key
42+
self.assert_show_fields(items, ['endpoints', 'name', 'type', ''])
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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.v2 import test_identity
14+
15+
16+
class EC2CredentialsTests(test_identity.IdentityTests):
17+
18+
def test_ec2_credentials_create(self):
19+
self._create_dummy_ec2_credentials()
20+
21+
def test_ec2_credentials_delete(self):
22+
access_key = self._create_dummy_ec2_credentials(add_clean_up=False)
23+
raw_output = self.openstack(
24+
'ec2 credentials delete %s' % access_key,
25+
)
26+
self.assertEqual(0, len(raw_output))
27+
28+
def test_ec2_credentials_list(self):
29+
self._create_dummy_ec2_credentials()
30+
raw_output = self.openstack('ec2 credentials list')
31+
items = self.parse_listing(raw_output)
32+
self.assert_table_structure(items, self.EC2_CREDENTIALS_LIST_HEADERS)
33+
34+
def test_ec2_credentials_show(self):
35+
access_key = self._create_dummy_ec2_credentials()
36+
show_output = self.openstack(
37+
'ec2 credentials show %s' % access_key,
38+
)
39+
items = self.parse_show(show_output)
40+
self.assert_show_fields(items, self.EC2_CREDENTIALS_FIELDS)

functional/tests/identity/v2/test_identity.py

Lines changed: 103 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
# License for the specific language governing permissions and limitations
1111
# under the License.
1212

13-
from functional.common import exceptions
13+
from tempest_lib.common.utils import data_utils
14+
1415
from functional.common import test
1516

1617
BASIC_LIST_HEADERS = ['ID', 'Name']
@@ -19,96 +20,110 @@
1920
class IdentityTests(test.TestCase):
2021
"""Functional tests for Identity commands. """
2122

22-
USER_FIELDS = ['email', 'enabled', 'id', 'name', 'project_id', 'username']
23-
PROJECT_FIELDS = ['enabled', 'id', 'name', 'description']
24-
EC2_CREDENTIALS_FIELDS = [
25-
'access',
26-
'project_id',
27-
'secret',
28-
'trust_id',
29-
'user_id',
30-
]
31-
EC2_CREDENTIALS_LIST_HEADERS = [
32-
'Access',
33-
'Secret',
34-
'Project ID',
35-
'User ID',
36-
]
37-
38-
def test_user_list(self):
39-
raw_output = self.openstack('user list')
40-
items = self.parse_listing(raw_output)
41-
self.assert_table_structure(items, BASIC_LIST_HEADERS)
42-
43-
def test_user_show(self):
44-
raw_output = self.openstack('user show admin')
23+
USER_FIELDS = ['email', 'enabled', 'id', 'name', 'project_id',
24+
'username', 'domain_id', 'default_project_id']
25+
PROJECT_FIELDS = ['enabled', 'id', 'name', 'description', 'domain_id']
26+
TOKEN_FIELDS = ['expires', 'id', 'project_id', 'user_id']
27+
ROLE_FIELDS = ['id', 'name', 'links']
28+
29+
EC2_CREDENTIALS_FIELDS = ['access', 'project_id', 'secret',
30+
'trust_id', 'user_id']
31+
EC2_CREDENTIALS_LIST_HEADERS = ['Access', 'Secret',
32+
'Project ID', 'User ID']
33+
CATALOG_LIST_HEADERS = ['Name', 'Type', 'Endpoints']
34+
35+
@classmethod
36+
def setUpClass(cls):
37+
if hasattr(super(IdentityTests, cls), 'setUpClass'):
38+
super(IdentityTests, cls).setUpClass()
39+
40+
# create dummy project
41+
cls.project_name = data_utils.rand_name('TestProject')
42+
cls.project_description = data_utils.rand_name('description')
43+
cls.openstack(
44+
'project create '
45+
'--description %(description)s '
46+
'--enable '
47+
'%(name)s' % {'description': cls.project_description,
48+
'name': cls.project_name})
49+
50+
@classmethod
51+
def tearDownClass(cls):
52+
cls.openstack('project delete %s' % cls.project_name)
53+
54+
if hasattr(super(IdentityTests, cls), 'tearDownClass'):
55+
super(IdentityTests, cls).tearDownClass()
56+
57+
def _create_dummy_project(self, add_clean_up=True):
58+
project_name = data_utils.rand_name('TestProject')
59+
project_description = data_utils.rand_name('description')
60+
raw_output = self.openstack(
61+
'project create '
62+
'--description %(description)s '
63+
'--enable %(name)s' % {'description': project_description,
64+
'name': project_name})
4565
items = self.parse_show(raw_output)
46-
self.assert_show_fields(items, self.USER_FIELDS)
47-
48-
def test_user_create(self):
49-
raw_output = self.openstack('user create mjordan --password bulls'
50-
' --email hoops@example.com')
66+
self.assert_show_fields(items, self.PROJECT_FIELDS)
67+
project = self.parse_show_as_object(raw_output)
68+
if add_clean_up:
69+
self.addCleanup(
70+
self.openstack,
71+
'project delete %s' % project['id'])
72+
return project_name
73+
74+
def _create_dummy_user(self, add_clean_up=True):
75+
username = data_utils.rand_name('TestUser')
76+
password = data_utils.rand_name('password')
77+
email = data_utils.rand_name() + '@example.com'
78+
raw_output = self.openstack(
79+
'user create '
80+
'--project %(project)s '
81+
'--password %(password)s '
82+
'--email %(email)s '
83+
'--enable '
84+
'%(name)s' % {'project': self.project_name,
85+
'email': email,
86+
'password': password,
87+
'name': username})
5188
items = self.parse_show(raw_output)
5289
self.assert_show_fields(items, self.USER_FIELDS)
53-
54-
def test_user_delete(self):
55-
self.openstack('user create dummy')
56-
raw_output = self.openstack('user delete dummy')
57-
self.assertEqual(0, len(raw_output))
58-
59-
def test_bad_user_command(self):
60-
self.assertRaises(exceptions.CommandFailed,
61-
self.openstack, 'user unlist')
62-
63-
def test_project_list(self):
64-
raw_output = self.openstack('project list')
65-
items = self.parse_listing(raw_output)
66-
self.assert_table_structure(items, BASIC_LIST_HEADERS)
67-
68-
def test_project_show(self):
69-
raw_output = self.openstack('project show admin')
90+
if add_clean_up:
91+
self.addCleanup(
92+
self.openstack,
93+
'user delete %s' % self.parse_show_as_object(raw_output)['id'])
94+
return username
95+
96+
def _create_dummy_role(self, add_clean_up=True):
97+
role_name = data_utils.rand_name('TestRole')
98+
raw_output = self.openstack('role create %s' % role_name)
7099
items = self.parse_show(raw_output)
71-
self.assert_show_fields(items, self.PROJECT_FIELDS)
72-
73-
def test_project_create(self):
74-
raw_output = self.openstack('project create test-project')
100+
self.assert_show_fields(items, self.ROLE_FIELDS)
101+
role = self.parse_show_as_object(raw_output)
102+
self.assertEqual(role_name, role['name'])
103+
if add_clean_up:
104+
self.addCleanup(
105+
self.openstack,
106+
'role delete %s' % role['id'])
107+
return role_name
108+
109+
def _create_dummy_ec2_credentials(self, add_clean_up=True):
110+
raw_output = self.openstack('ec2 credentials create')
75111
items = self.parse_show(raw_output)
76-
self.assert_show_fields(items, self.PROJECT_FIELDS)
77-
78-
def test_project_delete(self):
79-
self.openstack('project create dummy-project')
80-
raw_output = self.openstack('project delete dummy-project')
81-
self.assertEqual(0, len(raw_output))
82-
83-
def test_ec2_credentials_create(self):
84-
create_output = self.openstack('ec2 credentials create')
85-
create_items = self.parse_show(create_output)
86-
self.openstack(
87-
'ec2 credentials delete %s' % create_items[0]['access'],
88-
)
89-
self.assert_show_fields(create_items, self.EC2_CREDENTIALS_FIELDS)
90-
91-
def test_ec2_credentials_delete(self):
92-
create_output = self.openstack('ec2 credentials create')
93-
create_items = self.parse_show(create_output)
94-
raw_output = self.openstack(
95-
'ec2 credentials delete %s' % create_items[0]['access'],
96-
)
97-
self.assertEqual(0, len(raw_output))
98-
99-
def test_ec2_credentials_list(self):
100-
raw_output = self.openstack('ec2 credentials list')
101-
items = self.parse_listing(raw_output)
102-
self.assert_table_structure(items, self.EC2_CREDENTIALS_LIST_HEADERS)
103-
104-
def test_ec2_credentials_show(self):
105-
create_output = self.openstack('ec2 credentials create')
106-
create_items = self.parse_show(create_output)
107-
show_output = self.openstack(
108-
'ec2 credentials show %s' % create_items[0]['access'],
109-
)
110-
items = self.parse_show(show_output)
111-
self.openstack(
112-
'ec2 credentials delete %s' % create_items[0]['access'],
113-
)
114112
self.assert_show_fields(items, self.EC2_CREDENTIALS_FIELDS)
113+
ec2_credentials = self.parse_show_as_object(raw_output)
114+
access_key = ec2_credentials['access']
115+
if add_clean_up:
116+
self.addCleanup(
117+
self.openstack,
118+
'ec2 credentials delete %s' % access_key)
119+
return access_key
120+
121+
def _create_dummy_token(self, add_clean_up=True):
122+
raw_output = self.openstack('token issue')
123+
items = self.parse_show(raw_output)
124+
self.assert_show_fields(items, self.TOKEN_FIELDS)
125+
token = self.parse_show_as_object(raw_output)
126+
if add_clean_up:
127+
self.addCleanup(self.openstack,
128+
'token revoke %s' % token['id'])
129+
return token['id']
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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.v2 import test_identity
16+
17+
18+
class ProjectTests(test_identity.IdentityTests):
19+
20+
def test_project_create(self):
21+
project_name = data_utils.rand_name('TestProject')
22+
description = data_utils.rand_name('description')
23+
raw_output = self.openstack(
24+
'project create '
25+
'--description %(description)s '
26+
'--enable '
27+
'--property k1=v1 '
28+
'--property k2=v2 '
29+
'%(name)s' % {'description': description,
30+
'name': project_name})
31+
self.addCleanup(
32+
self.openstack,
33+
'project delete %s' % project_name
34+
)
35+
items = self.parse_show(raw_output)
36+
show_fields = list(self.PROJECT_FIELDS)
37+
show_fields.extend(['k1', 'k2'])
38+
self.assert_show_fields(items, show_fields)
39+
project = self.parse_show_as_object(raw_output)
40+
self.assertEqual('v1', project['k1'])
41+
self.assertEqual('v2', project['k2'])
42+
43+
def test_project_delete(self):
44+
project_name = self._create_dummy_project(add_clean_up=False)
45+
raw_output = self.openstack(
46+
'project delete %s' % project_name)
47+
self.assertEqual(0, len(raw_output))
48+
49+
def test_project_list(self):
50+
raw_output = self.openstack('project list')
51+
items = self.parse_listing(raw_output)
52+
self.assert_table_structure(items, test_identity.BASIC_LIST_HEADERS)
53+
54+
def test_project_set(self):
55+
project_name = self._create_dummy_project()
56+
new_project_name = data_utils.rand_name('NewTestProject')
57+
raw_output = self.openstack(
58+
'project set '
59+
'--name %(new_name)s '
60+
'--disable '
61+
'--property k0=v0 '
62+
'%(name)s' % {'new_name': new_project_name,
63+
'name': project_name})
64+
self.assertEqual(0, len(raw_output))
65+
# check project details
66+
raw_output = self.openstack(
67+
'project show %s' % new_project_name
68+
)
69+
items = self.parse_show(raw_output)
70+
fields = list(self.PROJECT_FIELDS)
71+
fields.extend(['k0'])
72+
self.assert_show_fields(items, fields)
73+
project = self.parse_show_as_object(raw_output)
74+
self.assertEqual(new_project_name, project['name'])
75+
self.assertEqual('False', project['enabled'])
76+
self.assertEqual('v0', project['k0'])
77+
78+
def test_project_show(self):
79+
project_name = self._create_dummy_project()
80+
raw_output = self.openstack(
81+
'project show %s' % project_name
82+
)
83+
items = self.parse_show(raw_output)
84+
self.assert_show_fields(items, self.PROJECT_FIELDS)

0 commit comments

Comments
 (0)