blob: 36d6c3db4e0371a77a8655d1bbff97f93ecdb69c [file] [log] [blame]
Matthew Treinishc791ac42014-07-16 09:15:23 -04001# Copyright 2014 Hewlett-Packard Development Company, L.P.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
15import hashlib
16import os
Matthew Treinishc791ac42014-07-16 09:15:23 -040017
18import mock
Doug Hellmann583ce2c2015-03-11 14:55:46 +000019from oslo_concurrency.fixture import lockutils as lockutils_fixtures
20from oslo_config import cfg
Matthew Treinishc791ac42014-07-16 09:15:23 -040021from oslotest import mockpatch
Andrea Frittoli (andreaf)848e3482015-10-12 14:17:21 +010022import shutil
Matthew Treinish1c517a22015-04-23 11:39:44 -040023import six
Matthew Treinishc791ac42014-07-16 09:15:23 -040024
Matthew Treinishf83f35c2015-04-10 11:59:11 -040025from tempest.common import cred_provider
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -070026from tempest.common import preprov_creds
Matthew Treinishc791ac42014-07-16 09:15:23 -040027from tempest import config
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -050028from tempest.lib import auth
29from tempest.lib import exceptions as lib_exc
30from tempest.lib.services.identity.v2 import token_client
Matthew Treinishc791ac42014-07-16 09:15:23 -040031from tempest.tests import fake_config
Jordan Pittier41129042016-03-29 21:21:16 +020032from tempest.tests.lib import base
Jordan Pittier00f25962016-03-18 17:10:07 +010033from tempest.tests.lib import fake_identity
Matthew Treinishc791ac42014-07-16 09:15:23 -040034
35
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -070036class TestPreProvisionedCredentials(base.TestCase):
Matthew Treinishc791ac42014-07-16 09:15:23 -040037
Andrea Frittoli (andreaf)32d0de12015-10-09 14:43:53 +010038 fixed_params = {'name': 'test class',
Andrea Frittoli (andreaf)29491a72015-10-13 11:24:17 +010039 'identity_version': 'v2',
Andrea Frittoli (andreaf)848e3482015-10-12 14:17:21 +010040 'test_accounts_file': 'fake_accounts_file',
41 'accounts_lock_dir': 'fake_locks_dir',
42 'admin_role': 'admin',
43 'object_storage_operator_role': 'operator',
44 'object_storage_reseller_admin_role': 'reseller'}
Andrea Frittoli (andreaf)32d0de12015-10-09 14:43:53 +010045
Matthew Treinishc791ac42014-07-16 09:15:23 -040046 def setUp(self):
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -070047 super(TestPreProvisionedCredentials, self).setUp()
Matthew Treinishc791ac42014-07-16 09:15:23 -040048 self.useFixture(fake_config.ConfigFixture())
49 self.stubs.Set(config, 'TempestConfigPrivate', fake_config.FakePrivate)
Ken'ichi Ohmichi96e72792015-09-09 04:05:41 +000050 self.stubs.Set(token_client.TokenClient, 'raw_request',
Matthew Treinishf83f35c2015-04-10 11:59:11 -040051 fake_identity._fake_v2_response)
Doug Hellmann583ce2c2015-03-11 14:55:46 +000052 self.useFixture(lockutils_fixtures.ExternalLockFixture())
Matthew Treinishc791ac42014-07-16 09:15:23 -040053 self.test_accounts = [
54 {'username': 'test_user1', 'tenant_name': 'test_tenant1',
55 'password': 'p'},
56 {'username': 'test_user2', 'tenant_name': 'test_tenant2',
57 'password': 'p'},
58 {'username': 'test_user3', 'tenant_name': 'test_tenant3',
59 'password': 'p'},
60 {'username': 'test_user4', 'tenant_name': 'test_tenant4',
61 'password': 'p'},
62 {'username': 'test_user5', 'tenant_name': 'test_tenant5',
63 'password': 'p'},
64 {'username': 'test_user6', 'tenant_name': 'test_tenant6',
Matthew Treinish976e8df2014-12-19 14:21:54 -050065 'password': 'p', 'roles': ['role1', 'role2']},
66 {'username': 'test_user7', 'tenant_name': 'test_tenant7',
67 'password': 'p', 'roles': ['role2', 'role3']},
68 {'username': 'test_user8', 'tenant_name': 'test_tenant8',
69 'password': 'p', 'roles': ['role4', 'role1']},
70 {'username': 'test_user9', 'tenant_name': 'test_tenant9',
71 'password': 'p', 'roles': ['role1', 'role2', 'role3', 'role4']},
72 {'username': 'test_user10', 'tenant_name': 'test_tenant10',
73 'password': 'p', 'roles': ['role1', 'role2', 'role3', 'role4']},
74 {'username': 'test_user11', 'tenant_name': 'test_tenant11',
75 'password': 'p', 'roles': [cfg.CONF.identity.admin_role]},
76 {'username': 'test_user12', 'tenant_name': 'test_tenant12',
77 'password': 'p', 'roles': [cfg.CONF.identity.admin_role]},
Matthew Treinishc791ac42014-07-16 09:15:23 -040078 ]
Matthew Treinisha59bd0c2015-04-20 12:02:48 -040079 self.accounts_mock = self.useFixture(mockpatch.Patch(
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -070080 'tempest.common.preprov_creds.read_accounts_yaml',
Matthew Treinishc791ac42014-07-16 09:15:23 -040081 return_value=self.test_accounts))
Matthew Treinishb19eeb82014-09-04 09:57:46 -040082 self.useFixture(mockpatch.Patch('os.path.isfile', return_value=True))
Matthew Treinishc791ac42014-07-16 09:15:23 -040083
Andrea Frittoli (andreaf)848e3482015-10-12 14:17:21 +010084 def tearDown(self):
85 super(TestPreProvisionedCredentials, self).tearDown()
86 shutil.rmtree(self.fixed_params['accounts_lock_dir'],
87 ignore_errors=True)
88
Matthew Treinishc791ac42014-07-16 09:15:23 -040089 def _get_hash_list(self, accounts_list):
90 hash_list = []
91 for account in accounts_list:
92 hash = hashlib.md5()
Matthew Treinish1c517a22015-04-23 11:39:44 -040093 hash.update(six.text_type(account).encode('utf-8'))
Matthew Treinish976e8df2014-12-19 14:21:54 -050094 temp_hash = hash.hexdigest()
95 hash_list.append(temp_hash)
Matthew Treinishc791ac42014-07-16 09:15:23 -040096 return hash_list
97
98 def test_get_hash(self):
Ken'ichi Ohmichi96e72792015-09-09 04:05:41 +000099 self.stubs.Set(token_client.TokenClient, 'raw_request',
Matthew Treinishc791ac42014-07-16 09:15:23 -0400100 fake_identity._fake_v2_response)
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -0700101 test_account_class = preprov_creds.PreProvisionedCredentialProvider(
Andrea Frittoli (andreaf)32d0de12015-10-09 14:43:53 +0100102 **self.fixed_params)
Matthew Treinishc791ac42014-07-16 09:15:23 -0400103 hash_list = self._get_hash_list(self.test_accounts)
104 test_cred_dict = self.test_accounts[3]
ghanshyam5ff763f2015-02-18 16:15:58 +0900105 test_creds = auth.get_credentials(fake_identity.FAKE_AUTH_URL,
106 **test_cred_dict)
Matthew Treinishc791ac42014-07-16 09:15:23 -0400107 results = test_account_class.get_hash(test_creds)
108 self.assertEqual(hash_list[3], results)
109
110 def test_get_hash_dict(self):
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -0700111 test_account_class = preprov_creds.PreProvisionedCredentialProvider(
Andrea Frittoli (andreaf)32d0de12015-10-09 14:43:53 +0100112 **self.fixed_params)
Andrea Frittoli (andreaf)29491a72015-10-13 11:24:17 +0100113 hash_dict = test_account_class.get_hash_dict(
114 self.test_accounts, self.fixed_params['admin_role'])
Matthew Treinishc791ac42014-07-16 09:15:23 -0400115 hash_list = self._get_hash_list(self.test_accounts)
116 for hash in hash_list:
Matthew Treinish976e8df2014-12-19 14:21:54 -0500117 self.assertIn(hash, hash_dict['creds'].keys())
118 self.assertIn(hash_dict['creds'][hash], self.test_accounts)
Matthew Treinishc791ac42014-07-16 09:15:23 -0400119
120 def test_create_hash_file_previous_file(self):
121 # Emulate the lock existing on the filesystem
122 self.useFixture(mockpatch.Patch('os.path.isfile', return_value=True))
Matthew Treinish53d0dc02015-04-24 15:57:27 -0400123 with mock.patch('six.moves.builtins.open', mock.mock_open(),
124 create=True):
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -0700125 test_account_class = (
126 preprov_creds.PreProvisionedCredentialProvider(
Andrea Frittoli (andreaf)32d0de12015-10-09 14:43:53 +0100127 **self.fixed_params))
Matthew Treinishc791ac42014-07-16 09:15:23 -0400128 res = test_account_class._create_hash_file('12345')
129 self.assertFalse(res, "_create_hash_file should return False if the "
130 "pseudo-lock file already exists")
131
132 def test_create_hash_file_no_previous_file(self):
133 # Emulate the lock not existing on the filesystem
134 self.useFixture(mockpatch.Patch('os.path.isfile', return_value=False))
Matthew Treinish53d0dc02015-04-24 15:57:27 -0400135 with mock.patch('six.moves.builtins.open', mock.mock_open(),
136 create=True):
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -0700137 test_account_class = (
138 preprov_creds.PreProvisionedCredentialProvider(
Andrea Frittoli (andreaf)32d0de12015-10-09 14:43:53 +0100139 **self.fixed_params))
Matthew Treinishc791ac42014-07-16 09:15:23 -0400140 res = test_account_class._create_hash_file('12345')
141 self.assertTrue(res, "_create_hash_file should return True if the "
142 "pseudo-lock doesn't already exist")
143
Doug Hellmann583ce2c2015-03-11 14:55:46 +0000144 @mock.patch('oslo_concurrency.lockutils.lock')
Matthew Treinishc791ac42014-07-16 09:15:23 -0400145 def test_get_free_hash_no_previous_accounts(self, lock_mock):
146 # Emulate no pre-existing lock
147 self.useFixture(mockpatch.Patch('os.path.isdir', return_value=False))
148 hash_list = self._get_hash_list(self.test_accounts)
149 mkdir_mock = self.useFixture(mockpatch.Patch('os.mkdir'))
150 self.useFixture(mockpatch.Patch('os.path.isfile', return_value=False))
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -0700151 test_account_class = preprov_creds.PreProvisionedCredentialProvider(
Andrea Frittoli (andreaf)32d0de12015-10-09 14:43:53 +0100152 **self.fixed_params)
Matthew Treinish53d0dc02015-04-24 15:57:27 -0400153 with mock.patch('six.moves.builtins.open', mock.mock_open(),
Matthew Treinishc791ac42014-07-16 09:15:23 -0400154 create=True) as open_mock:
155 test_account_class._get_free_hash(hash_list)
Andrea Frittoli (andreaf)848e3482015-10-12 14:17:21 +0100156 lock_path = os.path.join(self.fixed_params['accounts_lock_dir'],
157 hash_list[0])
Matthew Treinishc791ac42014-07-16 09:15:23 -0400158 open_mock.assert_called_once_with(lock_path, 'w')
Andrea Frittoli (andreaf)848e3482015-10-12 14:17:21 +0100159 mkdir_path = os.path.join(self.fixed_params['accounts_lock_dir'])
Matthew Treinishc791ac42014-07-16 09:15:23 -0400160 mkdir_mock.mock.assert_called_once_with(mkdir_path)
161
Doug Hellmann583ce2c2015-03-11 14:55:46 +0000162 @mock.patch('oslo_concurrency.lockutils.lock')
Matthew Treinishc791ac42014-07-16 09:15:23 -0400163 def test_get_free_hash_no_free_accounts(self, lock_mock):
164 hash_list = self._get_hash_list(self.test_accounts)
165 # Emulate pre-existing lock dir
166 self.useFixture(mockpatch.Patch('os.path.isdir', return_value=True))
167 # Emulate all lcoks in list are in use
168 self.useFixture(mockpatch.Patch('os.path.isfile', return_value=True))
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -0700169 test_account_class = preprov_creds.PreProvisionedCredentialProvider(
Andrea Frittoli (andreaf)32d0de12015-10-09 14:43:53 +0100170 **self.fixed_params)
Matthew Treinish53d0dc02015-04-24 15:57:27 -0400171 with mock.patch('six.moves.builtins.open', mock.mock_open(),
172 create=True):
Andrea Frittoli (andreaf)848e3482015-10-12 14:17:21 +0100173 self.assertRaises(lib_exc.InvalidCredentials,
Matthew Treinish4041b262015-02-27 11:18:54 -0500174 test_account_class._get_free_hash, hash_list)
Matthew Treinishc791ac42014-07-16 09:15:23 -0400175
Doug Hellmann583ce2c2015-03-11 14:55:46 +0000176 @mock.patch('oslo_concurrency.lockutils.lock')
Matthew Treinishc791ac42014-07-16 09:15:23 -0400177 def test_get_free_hash_some_in_use_accounts(self, lock_mock):
178 # Emulate no pre-existing lock
179 self.useFixture(mockpatch.Patch('os.path.isdir', return_value=True))
180 hash_list = self._get_hash_list(self.test_accounts)
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -0700181 test_account_class = preprov_creds.PreProvisionedCredentialProvider(
Andrea Frittoli (andreaf)32d0de12015-10-09 14:43:53 +0100182 **self.fixed_params)
Matthew Treinishc791ac42014-07-16 09:15:23 -0400183
184 def _fake_is_file(path):
185 # Fake isfile() to return that the path exists unless a specific
186 # hash is in the path
187 if hash_list[3] in path:
188 return False
189 return True
190
191 self.stubs.Set(os.path, 'isfile', _fake_is_file)
Matthew Treinish53d0dc02015-04-24 15:57:27 -0400192 with mock.patch('six.moves.builtins.open', mock.mock_open(),
Matthew Treinishc791ac42014-07-16 09:15:23 -0400193 create=True) as open_mock:
194 test_account_class._get_free_hash(hash_list)
Andrea Frittoli (andreaf)848e3482015-10-12 14:17:21 +0100195 lock_path = os.path.join(self.fixed_params['accounts_lock_dir'],
196 hash_list[3])
Matthew Treinish4041b262015-02-27 11:18:54 -0500197 open_mock.assert_has_calls([mock.call(lock_path, 'w')])
Matthew Treinishc791ac42014-07-16 09:15:23 -0400198
Doug Hellmann583ce2c2015-03-11 14:55:46 +0000199 @mock.patch('oslo_concurrency.lockutils.lock')
Matthew Treinishc791ac42014-07-16 09:15:23 -0400200 def test_remove_hash_last_account(self, lock_mock):
201 hash_list = self._get_hash_list(self.test_accounts)
202 # Pretend the pseudo-lock is there
203 self.useFixture(mockpatch.Patch('os.path.isfile', return_value=True))
204 # Pretend the lock dir is empty
205 self.useFixture(mockpatch.Patch('os.listdir', return_value=[]))
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -0700206 test_account_class = preprov_creds.PreProvisionedCredentialProvider(
Andrea Frittoli (andreaf)32d0de12015-10-09 14:43:53 +0100207 **self.fixed_params)
Matthew Treinishc791ac42014-07-16 09:15:23 -0400208 remove_mock = self.useFixture(mockpatch.Patch('os.remove'))
209 rmdir_mock = self.useFixture(mockpatch.Patch('os.rmdir'))
210 test_account_class.remove_hash(hash_list[2])
Andrea Frittoli (andreaf)848e3482015-10-12 14:17:21 +0100211 hash_path = os.path.join(self.fixed_params['accounts_lock_dir'],
Matthew Treinishc791ac42014-07-16 09:15:23 -0400212 hash_list[2])
Andrea Frittoli (andreaf)848e3482015-10-12 14:17:21 +0100213 lock_path = self.fixed_params['accounts_lock_dir']
Matthew Treinishc791ac42014-07-16 09:15:23 -0400214 remove_mock.mock.assert_called_once_with(hash_path)
215 rmdir_mock.mock.assert_called_once_with(lock_path)
216
Doug Hellmann583ce2c2015-03-11 14:55:46 +0000217 @mock.patch('oslo_concurrency.lockutils.lock')
Matthew Treinishc791ac42014-07-16 09:15:23 -0400218 def test_remove_hash_not_last_account(self, lock_mock):
219 hash_list = self._get_hash_list(self.test_accounts)
220 # Pretend the pseudo-lock is there
221 self.useFixture(mockpatch.Patch('os.path.isfile', return_value=True))
222 # Pretend the lock dir is empty
223 self.useFixture(mockpatch.Patch('os.listdir', return_value=[
224 hash_list[1], hash_list[4]]))
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -0700225 test_account_class = preprov_creds.PreProvisionedCredentialProvider(
Andrea Frittoli (andreaf)32d0de12015-10-09 14:43:53 +0100226 **self.fixed_params)
Matthew Treinishc791ac42014-07-16 09:15:23 -0400227 remove_mock = self.useFixture(mockpatch.Patch('os.remove'))
228 rmdir_mock = self.useFixture(mockpatch.Patch('os.rmdir'))
229 test_account_class.remove_hash(hash_list[2])
Andrea Frittoli (andreaf)848e3482015-10-12 14:17:21 +0100230 hash_path = os.path.join(self.fixed_params['accounts_lock_dir'],
Matthew Treinishc791ac42014-07-16 09:15:23 -0400231 hash_list[2])
232 remove_mock.mock.assert_called_once_with(hash_path)
233 rmdir_mock.mock.assert_not_called()
Matthew Treinish09f17832014-08-15 15:22:50 -0400234
235 def test_is_multi_user(self):
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -0700236 test_accounts_class = preprov_creds.PreProvisionedCredentialProvider(
Andrea Frittoli (andreaf)32d0de12015-10-09 14:43:53 +0100237 **self.fixed_params)
Matthew Treinish09f17832014-08-15 15:22:50 -0400238 self.assertTrue(test_accounts_class.is_multi_user())
239
240 def test_is_not_multi_user(self):
241 self.test_accounts = [self.test_accounts[0]]
242 self.useFixture(mockpatch.Patch(
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -0700243 'tempest.common.preprov_creds.read_accounts_yaml',
Matthew Treinish09f17832014-08-15 15:22:50 -0400244 return_value=self.test_accounts))
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -0700245 test_accounts_class = preprov_creds.PreProvisionedCredentialProvider(
Andrea Frittoli (andreaf)32d0de12015-10-09 14:43:53 +0100246 **self.fixed_params)
Matthew Treinish09f17832014-08-15 15:22:50 -0400247 self.assertFalse(test_accounts_class.is_multi_user())
Andrea Frittolib1c23fc2014-09-03 13:40:08 +0100248
Matthew Treinish976e8df2014-12-19 14:21:54 -0500249 def test__get_creds_by_roles_one_role(self):
250 self.useFixture(mockpatch.Patch(
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -0700251 'tempest.common.preprov_creds.read_accounts_yaml',
Matthew Treinish976e8df2014-12-19 14:21:54 -0500252 return_value=self.test_accounts))
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -0700253 test_accounts_class = preprov_creds.PreProvisionedCredentialProvider(
Andrea Frittoli (andreaf)32d0de12015-10-09 14:43:53 +0100254 **self.fixed_params)
Matthew Treinish976e8df2014-12-19 14:21:54 -0500255 hashes = test_accounts_class.hash_dict['roles']['role4']
256 temp_hash = hashes[0]
257 get_free_hash_mock = self.useFixture(mockpatch.PatchObject(
258 test_accounts_class, '_get_free_hash', return_value=temp_hash))
259 # Test a single role returns all matching roles
260 test_accounts_class._get_creds(roles=['role4'])
261 calls = get_free_hash_mock.mock.mock_calls
262 self.assertEqual(len(calls), 1)
263 args = calls[0][1][0]
264 for i in hashes:
265 self.assertIn(i, args)
266
267 def test__get_creds_by_roles_list_role(self):
268 self.useFixture(mockpatch.Patch(
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -0700269 'tempest.common.preprov_creds.read_accounts_yaml',
Matthew Treinish976e8df2014-12-19 14:21:54 -0500270 return_value=self.test_accounts))
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -0700271 test_accounts_class = preprov_creds.PreProvisionedCredentialProvider(
Andrea Frittoli (andreaf)32d0de12015-10-09 14:43:53 +0100272 **self.fixed_params)
Matthew Treinish976e8df2014-12-19 14:21:54 -0500273 hashes = test_accounts_class.hash_dict['roles']['role4']
274 hashes2 = test_accounts_class.hash_dict['roles']['role2']
275 hashes = list(set(hashes) & set(hashes2))
276 temp_hash = hashes[0]
277 get_free_hash_mock = self.useFixture(mockpatch.PatchObject(
278 test_accounts_class, '_get_free_hash', return_value=temp_hash))
279 # Test an intersection of multiple roles
280 test_accounts_class._get_creds(roles=['role2', 'role4'])
281 calls = get_free_hash_mock.mock.mock_calls
282 self.assertEqual(len(calls), 1)
283 args = calls[0][1][0]
284 for i in hashes:
285 self.assertIn(i, args)
286
287 def test__get_creds_by_roles_no_admin(self):
288 self.useFixture(mockpatch.Patch(
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -0700289 'tempest.common.preprov_creds.read_accounts_yaml',
Matthew Treinish976e8df2014-12-19 14:21:54 -0500290 return_value=self.test_accounts))
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -0700291 test_accounts_class = preprov_creds.PreProvisionedCredentialProvider(
Andrea Frittoli (andreaf)32d0de12015-10-09 14:43:53 +0100292 **self.fixed_params)
Matthew Treinish1c517a22015-04-23 11:39:44 -0400293 hashes = list(test_accounts_class.hash_dict['creds'].keys())
Matthew Treinish976e8df2014-12-19 14:21:54 -0500294 admin_hashes = test_accounts_class.hash_dict['roles'][
295 cfg.CONF.identity.admin_role]
296 temp_hash = hashes[0]
297 get_free_hash_mock = self.useFixture(mockpatch.PatchObject(
298 test_accounts_class, '_get_free_hash', return_value=temp_hash))
299 # Test an intersection of multiple roles
300 test_accounts_class._get_creds()
301 calls = get_free_hash_mock.mock.mock_calls
302 self.assertEqual(len(calls), 1)
303 args = calls[0][1][0]
Matthew Treinisha59bd0c2015-04-20 12:02:48 -0400304 self.assertEqual(len(args), 10)
Matthew Treinish976e8df2014-12-19 14:21:54 -0500305 for i in admin_hashes:
306 self.assertNotIn(i, args)
307
Matthew Treinishf83f35c2015-04-10 11:59:11 -0400308 def test_networks_returned_with_creds(self):
Matthew Treinisha59bd0c2015-04-20 12:02:48 -0400309 test_accounts = [
310 {'username': 'test_user13', 'tenant_name': 'test_tenant13',
311 'password': 'p', 'resources': {'network': 'network-1'}},
312 {'username': 'test_user14', 'tenant_name': 'test_tenant14',
313 'password': 'p', 'roles': ['role-7', 'role-11'],
314 'resources': {'network': 'network-2'}}]
Matthew Treinishf83f35c2015-04-10 11:59:11 -0400315 self.useFixture(mockpatch.Patch(
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -0700316 'tempest.common.preprov_creds.read_accounts_yaml',
Matthew Treinisha59bd0c2015-04-20 12:02:48 -0400317 return_value=test_accounts))
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -0700318 test_accounts_class = preprov_creds.PreProvisionedCredentialProvider(
Andrea Frittoli (andreaf)32d0de12015-10-09 14:43:53 +0100319 **self.fixed_params)
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -0500320 with mock.patch('tempest.lib.services.compute.networks_client.'
Ken'ichi Ohmichia6287072015-07-02 02:43:15 +0000321 'NetworksClient.list_networks',
ghanshyamf0f7cfc2015-08-24 16:21:18 +0900322 return_value={'networks': [{'name': 'network-2',
323 'id': 'fake-id',
324 'label': 'network-2'}]}):
Matthew Treinishf83f35c2015-04-10 11:59:11 -0400325 creds = test_accounts_class.get_creds_by_roles(['role-7'])
Shuquan Huang29e9cab2015-12-30 22:43:49 +0800326 self.assertIsInstance(creds, cred_provider.TestResources)
Matthew Treinishf83f35c2015-04-10 11:59:11 -0400327 network = creds.network
328 self.assertIsNotNone(network)
329 self.assertIn('name', network)
330 self.assertIn('id', network)
331 self.assertEqual('fake-id', network['id'])
332 self.assertEqual('network-2', network['name'])