blob: 7188e5fe4379957fc75569022f52df41314a6204 [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 base
32from tempest.tests import fake_config
Matthew Treinishf83f35c2015-04-10 11:59:11 -040033from tempest.tests import fake_http
Matthew Treinishc791ac42014-07-16 09:15:23 -040034from tempest.tests import fake_identity
35
36
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -070037class TestPreProvisionedCredentials(base.TestCase):
Matthew Treinishc791ac42014-07-16 09:15:23 -040038
Andrea Frittoli (andreaf)32d0de12015-10-09 14:43:53 +010039 fixed_params = {'name': 'test class',
Andrea Frittoli (andreaf)29491a72015-10-13 11:24:17 +010040 'identity_version': 'v2',
Andrea Frittoli (andreaf)848e3482015-10-12 14:17:21 +010041 'test_accounts_file': 'fake_accounts_file',
42 'accounts_lock_dir': 'fake_locks_dir',
43 'admin_role': 'admin',
44 'object_storage_operator_role': 'operator',
45 'object_storage_reseller_admin_role': 'reseller'}
Andrea Frittoli (andreaf)32d0de12015-10-09 14:43:53 +010046
Matthew Treinishc791ac42014-07-16 09:15:23 -040047 def setUp(self):
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -070048 super(TestPreProvisionedCredentials, self).setUp()
Matthew Treinishc791ac42014-07-16 09:15:23 -040049 self.useFixture(fake_config.ConfigFixture())
50 self.stubs.Set(config, 'TempestConfigPrivate', fake_config.FakePrivate)
Matthew Treinishf83f35c2015-04-10 11:59:11 -040051 self.fake_http = fake_http.fake_httplib2(return_type=200)
Ken'ichi Ohmichi96e72792015-09-09 04:05:41 +000052 self.stubs.Set(token_client.TokenClient, 'raw_request',
Matthew Treinishf83f35c2015-04-10 11:59:11 -040053 fake_identity._fake_v2_response)
Doug Hellmann583ce2c2015-03-11 14:55:46 +000054 self.useFixture(lockutils_fixtures.ExternalLockFixture())
Matthew Treinishc791ac42014-07-16 09:15:23 -040055 self.test_accounts = [
56 {'username': 'test_user1', 'tenant_name': 'test_tenant1',
57 'password': 'p'},
58 {'username': 'test_user2', 'tenant_name': 'test_tenant2',
59 'password': 'p'},
60 {'username': 'test_user3', 'tenant_name': 'test_tenant3',
61 'password': 'p'},
62 {'username': 'test_user4', 'tenant_name': 'test_tenant4',
63 'password': 'p'},
64 {'username': 'test_user5', 'tenant_name': 'test_tenant5',
65 'password': 'p'},
66 {'username': 'test_user6', 'tenant_name': 'test_tenant6',
Matthew Treinish976e8df2014-12-19 14:21:54 -050067 'password': 'p', 'roles': ['role1', 'role2']},
68 {'username': 'test_user7', 'tenant_name': 'test_tenant7',
69 'password': 'p', 'roles': ['role2', 'role3']},
70 {'username': 'test_user8', 'tenant_name': 'test_tenant8',
71 'password': 'p', 'roles': ['role4', 'role1']},
72 {'username': 'test_user9', 'tenant_name': 'test_tenant9',
73 'password': 'p', 'roles': ['role1', 'role2', 'role3', 'role4']},
74 {'username': 'test_user10', 'tenant_name': 'test_tenant10',
75 'password': 'p', 'roles': ['role1', 'role2', 'role3', 'role4']},
76 {'username': 'test_user11', 'tenant_name': 'test_tenant11',
77 'password': 'p', 'roles': [cfg.CONF.identity.admin_role]},
78 {'username': 'test_user12', 'tenant_name': 'test_tenant12',
79 'password': 'p', 'roles': [cfg.CONF.identity.admin_role]},
Matthew Treinishc791ac42014-07-16 09:15:23 -040080 ]
Matthew Treinisha59bd0c2015-04-20 12:02:48 -040081 self.accounts_mock = self.useFixture(mockpatch.Patch(
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -070082 'tempest.common.preprov_creds.read_accounts_yaml',
Matthew Treinishc791ac42014-07-16 09:15:23 -040083 return_value=self.test_accounts))
Matthew Treinishb19eeb82014-09-04 09:57:46 -040084 self.useFixture(mockpatch.Patch('os.path.isfile', return_value=True))
Matthew Treinishc791ac42014-07-16 09:15:23 -040085
Andrea Frittoli (andreaf)848e3482015-10-12 14:17:21 +010086 def tearDown(self):
87 super(TestPreProvisionedCredentials, self).tearDown()
88 shutil.rmtree(self.fixed_params['accounts_lock_dir'],
89 ignore_errors=True)
90
Matthew Treinishc791ac42014-07-16 09:15:23 -040091 def _get_hash_list(self, accounts_list):
92 hash_list = []
93 for account in accounts_list:
94 hash = hashlib.md5()
Matthew Treinish1c517a22015-04-23 11:39:44 -040095 hash.update(six.text_type(account).encode('utf-8'))
Matthew Treinish976e8df2014-12-19 14:21:54 -050096 temp_hash = hash.hexdigest()
97 hash_list.append(temp_hash)
Matthew Treinishc791ac42014-07-16 09:15:23 -040098 return hash_list
99
100 def test_get_hash(self):
Ken'ichi Ohmichi96e72792015-09-09 04:05:41 +0000101 self.stubs.Set(token_client.TokenClient, 'raw_request',
Matthew Treinishc791ac42014-07-16 09:15:23 -0400102 fake_identity._fake_v2_response)
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -0700103 test_account_class = preprov_creds.PreProvisionedCredentialProvider(
Andrea Frittoli (andreaf)32d0de12015-10-09 14:43:53 +0100104 **self.fixed_params)
Matthew Treinishc791ac42014-07-16 09:15:23 -0400105 hash_list = self._get_hash_list(self.test_accounts)
106 test_cred_dict = self.test_accounts[3]
ghanshyam5ff763f2015-02-18 16:15:58 +0900107 test_creds = auth.get_credentials(fake_identity.FAKE_AUTH_URL,
108 **test_cred_dict)
Matthew Treinishc791ac42014-07-16 09:15:23 -0400109 results = test_account_class.get_hash(test_creds)
110 self.assertEqual(hash_list[3], results)
111
112 def test_get_hash_dict(self):
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -0700113 test_account_class = preprov_creds.PreProvisionedCredentialProvider(
Andrea Frittoli (andreaf)32d0de12015-10-09 14:43:53 +0100114 **self.fixed_params)
Andrea Frittoli (andreaf)29491a72015-10-13 11:24:17 +0100115 hash_dict = test_account_class.get_hash_dict(
116 self.test_accounts, self.fixed_params['admin_role'])
Matthew Treinishc791ac42014-07-16 09:15:23 -0400117 hash_list = self._get_hash_list(self.test_accounts)
118 for hash in hash_list:
Matthew Treinish976e8df2014-12-19 14:21:54 -0500119 self.assertIn(hash, hash_dict['creds'].keys())
120 self.assertIn(hash_dict['creds'][hash], self.test_accounts)
Matthew Treinishc791ac42014-07-16 09:15:23 -0400121
122 def test_create_hash_file_previous_file(self):
123 # Emulate the lock existing on the filesystem
124 self.useFixture(mockpatch.Patch('os.path.isfile', return_value=True))
Matthew Treinish53d0dc02015-04-24 15:57:27 -0400125 with mock.patch('six.moves.builtins.open', mock.mock_open(),
126 create=True):
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -0700127 test_account_class = (
128 preprov_creds.PreProvisionedCredentialProvider(
Andrea Frittoli (andreaf)32d0de12015-10-09 14:43:53 +0100129 **self.fixed_params))
Matthew Treinishc791ac42014-07-16 09:15:23 -0400130 res = test_account_class._create_hash_file('12345')
131 self.assertFalse(res, "_create_hash_file should return False if the "
132 "pseudo-lock file already exists")
133
134 def test_create_hash_file_no_previous_file(self):
135 # Emulate the lock not existing on the filesystem
136 self.useFixture(mockpatch.Patch('os.path.isfile', return_value=False))
Matthew Treinish53d0dc02015-04-24 15:57:27 -0400137 with mock.patch('six.moves.builtins.open', mock.mock_open(),
138 create=True):
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -0700139 test_account_class = (
140 preprov_creds.PreProvisionedCredentialProvider(
Andrea Frittoli (andreaf)32d0de12015-10-09 14:43:53 +0100141 **self.fixed_params))
Matthew Treinishc791ac42014-07-16 09:15:23 -0400142 res = test_account_class._create_hash_file('12345')
143 self.assertTrue(res, "_create_hash_file should return True if the "
144 "pseudo-lock doesn't already exist")
145
Doug Hellmann583ce2c2015-03-11 14:55:46 +0000146 @mock.patch('oslo_concurrency.lockutils.lock')
Matthew Treinishc791ac42014-07-16 09:15:23 -0400147 def test_get_free_hash_no_previous_accounts(self, lock_mock):
148 # Emulate no pre-existing lock
149 self.useFixture(mockpatch.Patch('os.path.isdir', return_value=False))
150 hash_list = self._get_hash_list(self.test_accounts)
151 mkdir_mock = self.useFixture(mockpatch.Patch('os.mkdir'))
152 self.useFixture(mockpatch.Patch('os.path.isfile', return_value=False))
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -0700153 test_account_class = preprov_creds.PreProvisionedCredentialProvider(
Andrea Frittoli (andreaf)32d0de12015-10-09 14:43:53 +0100154 **self.fixed_params)
Matthew Treinish53d0dc02015-04-24 15:57:27 -0400155 with mock.patch('six.moves.builtins.open', mock.mock_open(),
Matthew Treinishc791ac42014-07-16 09:15:23 -0400156 create=True) as open_mock:
157 test_account_class._get_free_hash(hash_list)
Andrea Frittoli (andreaf)848e3482015-10-12 14:17:21 +0100158 lock_path = os.path.join(self.fixed_params['accounts_lock_dir'],
159 hash_list[0])
Matthew Treinishc791ac42014-07-16 09:15:23 -0400160 open_mock.assert_called_once_with(lock_path, 'w')
Andrea Frittoli (andreaf)848e3482015-10-12 14:17:21 +0100161 mkdir_path = os.path.join(self.fixed_params['accounts_lock_dir'])
Matthew Treinishc791ac42014-07-16 09:15:23 -0400162 mkdir_mock.mock.assert_called_once_with(mkdir_path)
163
Doug Hellmann583ce2c2015-03-11 14:55:46 +0000164 @mock.patch('oslo_concurrency.lockutils.lock')
Matthew Treinishc791ac42014-07-16 09:15:23 -0400165 def test_get_free_hash_no_free_accounts(self, lock_mock):
166 hash_list = self._get_hash_list(self.test_accounts)
167 # Emulate pre-existing lock dir
168 self.useFixture(mockpatch.Patch('os.path.isdir', return_value=True))
169 # Emulate all lcoks in list are in use
170 self.useFixture(mockpatch.Patch('os.path.isfile', return_value=True))
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -0700171 test_account_class = preprov_creds.PreProvisionedCredentialProvider(
Andrea Frittoli (andreaf)32d0de12015-10-09 14:43:53 +0100172 **self.fixed_params)
Matthew Treinish53d0dc02015-04-24 15:57:27 -0400173 with mock.patch('six.moves.builtins.open', mock.mock_open(),
174 create=True):
Andrea Frittoli (andreaf)848e3482015-10-12 14:17:21 +0100175 self.assertRaises(lib_exc.InvalidCredentials,
Matthew Treinish4041b262015-02-27 11:18:54 -0500176 test_account_class._get_free_hash, hash_list)
Matthew Treinishc791ac42014-07-16 09:15:23 -0400177
Doug Hellmann583ce2c2015-03-11 14:55:46 +0000178 @mock.patch('oslo_concurrency.lockutils.lock')
Matthew Treinishc791ac42014-07-16 09:15:23 -0400179 def test_get_free_hash_some_in_use_accounts(self, lock_mock):
180 # Emulate no pre-existing lock
181 self.useFixture(mockpatch.Patch('os.path.isdir', return_value=True))
182 hash_list = self._get_hash_list(self.test_accounts)
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -0700183 test_account_class = preprov_creds.PreProvisionedCredentialProvider(
Andrea Frittoli (andreaf)32d0de12015-10-09 14:43:53 +0100184 **self.fixed_params)
Matthew Treinishc791ac42014-07-16 09:15:23 -0400185
186 def _fake_is_file(path):
187 # Fake isfile() to return that the path exists unless a specific
188 # hash is in the path
189 if hash_list[3] in path:
190 return False
191 return True
192
193 self.stubs.Set(os.path, 'isfile', _fake_is_file)
Matthew Treinish53d0dc02015-04-24 15:57:27 -0400194 with mock.patch('six.moves.builtins.open', mock.mock_open(),
Matthew Treinishc791ac42014-07-16 09:15:23 -0400195 create=True) as open_mock:
196 test_account_class._get_free_hash(hash_list)
Andrea Frittoli (andreaf)848e3482015-10-12 14:17:21 +0100197 lock_path = os.path.join(self.fixed_params['accounts_lock_dir'],
198 hash_list[3])
Matthew Treinish4041b262015-02-27 11:18:54 -0500199 open_mock.assert_has_calls([mock.call(lock_path, 'w')])
Matthew Treinishc791ac42014-07-16 09:15:23 -0400200
Doug Hellmann583ce2c2015-03-11 14:55:46 +0000201 @mock.patch('oslo_concurrency.lockutils.lock')
Matthew Treinishc791ac42014-07-16 09:15:23 -0400202 def test_remove_hash_last_account(self, lock_mock):
203 hash_list = self._get_hash_list(self.test_accounts)
204 # Pretend the pseudo-lock is there
205 self.useFixture(mockpatch.Patch('os.path.isfile', return_value=True))
206 # Pretend the lock dir is empty
207 self.useFixture(mockpatch.Patch('os.listdir', return_value=[]))
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -0700208 test_account_class = preprov_creds.PreProvisionedCredentialProvider(
Andrea Frittoli (andreaf)32d0de12015-10-09 14:43:53 +0100209 **self.fixed_params)
Matthew Treinishc791ac42014-07-16 09:15:23 -0400210 remove_mock = self.useFixture(mockpatch.Patch('os.remove'))
211 rmdir_mock = self.useFixture(mockpatch.Patch('os.rmdir'))
212 test_account_class.remove_hash(hash_list[2])
Andrea Frittoli (andreaf)848e3482015-10-12 14:17:21 +0100213 hash_path = os.path.join(self.fixed_params['accounts_lock_dir'],
Matthew Treinishc791ac42014-07-16 09:15:23 -0400214 hash_list[2])
Andrea Frittoli (andreaf)848e3482015-10-12 14:17:21 +0100215 lock_path = self.fixed_params['accounts_lock_dir']
Matthew Treinishc791ac42014-07-16 09:15:23 -0400216 remove_mock.mock.assert_called_once_with(hash_path)
217 rmdir_mock.mock.assert_called_once_with(lock_path)
218
Doug Hellmann583ce2c2015-03-11 14:55:46 +0000219 @mock.patch('oslo_concurrency.lockutils.lock')
Matthew Treinishc791ac42014-07-16 09:15:23 -0400220 def test_remove_hash_not_last_account(self, lock_mock):
221 hash_list = self._get_hash_list(self.test_accounts)
222 # Pretend the pseudo-lock is there
223 self.useFixture(mockpatch.Patch('os.path.isfile', return_value=True))
224 # Pretend the lock dir is empty
225 self.useFixture(mockpatch.Patch('os.listdir', return_value=[
226 hash_list[1], hash_list[4]]))
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -0700227 test_account_class = preprov_creds.PreProvisionedCredentialProvider(
Andrea Frittoli (andreaf)32d0de12015-10-09 14:43:53 +0100228 **self.fixed_params)
Matthew Treinishc791ac42014-07-16 09:15:23 -0400229 remove_mock = self.useFixture(mockpatch.Patch('os.remove'))
230 rmdir_mock = self.useFixture(mockpatch.Patch('os.rmdir'))
231 test_account_class.remove_hash(hash_list[2])
Andrea Frittoli (andreaf)848e3482015-10-12 14:17:21 +0100232 hash_path = os.path.join(self.fixed_params['accounts_lock_dir'],
Matthew Treinishc791ac42014-07-16 09:15:23 -0400233 hash_list[2])
234 remove_mock.mock.assert_called_once_with(hash_path)
235 rmdir_mock.mock.assert_not_called()
Matthew Treinish09f17832014-08-15 15:22:50 -0400236
237 def test_is_multi_user(self):
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -0700238 test_accounts_class = preprov_creds.PreProvisionedCredentialProvider(
Andrea Frittoli (andreaf)32d0de12015-10-09 14:43:53 +0100239 **self.fixed_params)
Matthew Treinish09f17832014-08-15 15:22:50 -0400240 self.assertTrue(test_accounts_class.is_multi_user())
241
242 def test_is_not_multi_user(self):
243 self.test_accounts = [self.test_accounts[0]]
244 self.useFixture(mockpatch.Patch(
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -0700245 'tempest.common.preprov_creds.read_accounts_yaml',
Matthew Treinish09f17832014-08-15 15:22:50 -0400246 return_value=self.test_accounts))
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -0700247 test_accounts_class = preprov_creds.PreProvisionedCredentialProvider(
Andrea Frittoli (andreaf)32d0de12015-10-09 14:43:53 +0100248 **self.fixed_params)
Matthew Treinish09f17832014-08-15 15:22:50 -0400249 self.assertFalse(test_accounts_class.is_multi_user())
Andrea Frittolib1c23fc2014-09-03 13:40:08 +0100250
Matthew Treinish976e8df2014-12-19 14:21:54 -0500251 def test__get_creds_by_roles_one_role(self):
252 self.useFixture(mockpatch.Patch(
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -0700253 'tempest.common.preprov_creds.read_accounts_yaml',
Matthew Treinish976e8df2014-12-19 14:21:54 -0500254 return_value=self.test_accounts))
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -0700255 test_accounts_class = preprov_creds.PreProvisionedCredentialProvider(
Andrea Frittoli (andreaf)32d0de12015-10-09 14:43:53 +0100256 **self.fixed_params)
Matthew Treinish976e8df2014-12-19 14:21:54 -0500257 hashes = test_accounts_class.hash_dict['roles']['role4']
258 temp_hash = hashes[0]
259 get_free_hash_mock = self.useFixture(mockpatch.PatchObject(
260 test_accounts_class, '_get_free_hash', return_value=temp_hash))
261 # Test a single role returns all matching roles
262 test_accounts_class._get_creds(roles=['role4'])
263 calls = get_free_hash_mock.mock.mock_calls
264 self.assertEqual(len(calls), 1)
265 args = calls[0][1][0]
266 for i in hashes:
267 self.assertIn(i, args)
268
269 def test__get_creds_by_roles_list_role(self):
270 self.useFixture(mockpatch.Patch(
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -0700271 'tempest.common.preprov_creds.read_accounts_yaml',
Matthew Treinish976e8df2014-12-19 14:21:54 -0500272 return_value=self.test_accounts))
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -0700273 test_accounts_class = preprov_creds.PreProvisionedCredentialProvider(
Andrea Frittoli (andreaf)32d0de12015-10-09 14:43:53 +0100274 **self.fixed_params)
Matthew Treinish976e8df2014-12-19 14:21:54 -0500275 hashes = test_accounts_class.hash_dict['roles']['role4']
276 hashes2 = test_accounts_class.hash_dict['roles']['role2']
277 hashes = list(set(hashes) & set(hashes2))
278 temp_hash = hashes[0]
279 get_free_hash_mock = self.useFixture(mockpatch.PatchObject(
280 test_accounts_class, '_get_free_hash', return_value=temp_hash))
281 # Test an intersection of multiple roles
282 test_accounts_class._get_creds(roles=['role2', 'role4'])
283 calls = get_free_hash_mock.mock.mock_calls
284 self.assertEqual(len(calls), 1)
285 args = calls[0][1][0]
286 for i in hashes:
287 self.assertIn(i, args)
288
289 def test__get_creds_by_roles_no_admin(self):
290 self.useFixture(mockpatch.Patch(
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -0700291 'tempest.common.preprov_creds.read_accounts_yaml',
Matthew Treinish976e8df2014-12-19 14:21:54 -0500292 return_value=self.test_accounts))
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -0700293 test_accounts_class = preprov_creds.PreProvisionedCredentialProvider(
Andrea Frittoli (andreaf)32d0de12015-10-09 14:43:53 +0100294 **self.fixed_params)
Matthew Treinish1c517a22015-04-23 11:39:44 -0400295 hashes = list(test_accounts_class.hash_dict['creds'].keys())
Matthew Treinish976e8df2014-12-19 14:21:54 -0500296 admin_hashes = test_accounts_class.hash_dict['roles'][
297 cfg.CONF.identity.admin_role]
298 temp_hash = hashes[0]
299 get_free_hash_mock = self.useFixture(mockpatch.PatchObject(
300 test_accounts_class, '_get_free_hash', return_value=temp_hash))
301 # Test an intersection of multiple roles
302 test_accounts_class._get_creds()
303 calls = get_free_hash_mock.mock.mock_calls
304 self.assertEqual(len(calls), 1)
305 args = calls[0][1][0]
Matthew Treinisha59bd0c2015-04-20 12:02:48 -0400306 self.assertEqual(len(args), 10)
Matthew Treinish976e8df2014-12-19 14:21:54 -0500307 for i in admin_hashes:
308 self.assertNotIn(i, args)
309
Matthew Treinishf83f35c2015-04-10 11:59:11 -0400310 def test_networks_returned_with_creds(self):
Matthew Treinisha59bd0c2015-04-20 12:02:48 -0400311 test_accounts = [
312 {'username': 'test_user13', 'tenant_name': 'test_tenant13',
313 'password': 'p', 'resources': {'network': 'network-1'}},
314 {'username': 'test_user14', 'tenant_name': 'test_tenant14',
315 'password': 'p', 'roles': ['role-7', 'role-11'],
316 'resources': {'network': 'network-2'}}]
Matthew Treinishf83f35c2015-04-10 11:59:11 -0400317 self.useFixture(mockpatch.Patch(
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -0700318 'tempest.common.preprov_creds.read_accounts_yaml',
Matthew Treinisha59bd0c2015-04-20 12:02:48 -0400319 return_value=test_accounts))
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -0700320 test_accounts_class = preprov_creds.PreProvisionedCredentialProvider(
Andrea Frittoli (andreaf)32d0de12015-10-09 14:43:53 +0100321 **self.fixed_params)
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -0500322 with mock.patch('tempest.lib.services.compute.networks_client.'
Ken'ichi Ohmichia6287072015-07-02 02:43:15 +0000323 'NetworksClient.list_networks',
ghanshyamf0f7cfc2015-08-24 16:21:18 +0900324 return_value={'networks': [{'name': 'network-2',
325 'id': 'fake-id',
326 'label': 'network-2'}]}):
Matthew Treinishf83f35c2015-04-10 11:59:11 -0400327 creds = test_accounts_class.get_creds_by_roles(['role-7'])
328 self.assertTrue(isinstance(creds, cred_provider.TestResources))
329 network = creds.network
330 self.assertIsNotNone(network)
331 self.assertIn('name', network)
332 self.assertIn('id', network)
333 self.assertEqual('fake-id', network['id'])
334 self.assertEqual('network-2', network['name'])