|
10 | 10 | # License for the specific language governing permissions and limitations |
11 | 11 | # under the License. |
12 | 12 |
|
13 | | -from functional.common import exceptions |
| 13 | +from tempest_lib.common.utils import data_utils |
| 14 | + |
14 | 15 | from functional.common import test |
15 | 16 |
|
16 | 17 | BASIC_LIST_HEADERS = ['ID', 'Name'] |
|
19 | 20 | class IdentityTests(test.TestCase): |
20 | 21 | """Functional tests for Identity commands. """ |
21 | 22 |
|
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}) |
45 | 65 | 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}) |
51 | 88 | items = self.parse_show(raw_output) |
52 | 89 | 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) |
70 | 99 | 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') |
75 | 111 | 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 | | - ) |
114 | 112 | 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'] |
0 commit comments