Matthew Treinish | c791ac4 | 2014-07-16 09:15:23 -0400 | [diff] [blame] | 1 | # 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 | |
| 15 | import hashlib |
| 16 | import os |
Matthew Treinish | c791ac4 | 2014-07-16 09:15:23 -0400 | [diff] [blame] | 17 | |
| 18 | import mock |
Doug Hellmann | 583ce2c | 2015-03-11 14:55:46 +0000 | [diff] [blame] | 19 | from oslo_concurrency.fixture import lockutils as lockutils_fixtures |
Matthew Treinish | b503f03 | 2015-03-12 15:48:49 -0400 | [diff] [blame] | 20 | from oslo_concurrency import lockutils |
Doug Hellmann | 583ce2c | 2015-03-11 14:55:46 +0000 | [diff] [blame] | 21 | from oslo_config import cfg |
Matthew Treinish | c791ac4 | 2014-07-16 09:15:23 -0400 | [diff] [blame] | 22 | from oslotest import mockpatch |
| 23 | |
| 24 | from tempest import auth |
| 25 | from tempest.common import accounts |
Matthew Treinish | c791ac4 | 2014-07-16 09:15:23 -0400 | [diff] [blame] | 26 | from tempest import config |
| 27 | from tempest import exceptions |
Jamie Lennox | c429e6a | 2015-02-24 10:42:42 +1100 | [diff] [blame] | 28 | from tempest.services.identity.v2.json import token_client |
Matthew Treinish | c791ac4 | 2014-07-16 09:15:23 -0400 | [diff] [blame] | 29 | from tempest.tests import base |
| 30 | from tempest.tests import fake_config |
| 31 | from tempest.tests import fake_identity |
| 32 | |
| 33 | |
| 34 | class TestAccount(base.TestCase): |
| 35 | |
| 36 | def setUp(self): |
| 37 | super(TestAccount, self).setUp() |
| 38 | self.useFixture(fake_config.ConfigFixture()) |
| 39 | self.stubs.Set(config, 'TempestConfigPrivate', fake_config.FakePrivate) |
Doug Hellmann | 583ce2c | 2015-03-11 14:55:46 +0000 | [diff] [blame] | 40 | self.useFixture(lockutils_fixtures.ExternalLockFixture()) |
Matthew Treinish | c791ac4 | 2014-07-16 09:15:23 -0400 | [diff] [blame] | 41 | self.test_accounts = [ |
| 42 | {'username': 'test_user1', 'tenant_name': 'test_tenant1', |
| 43 | 'password': 'p'}, |
| 44 | {'username': 'test_user2', 'tenant_name': 'test_tenant2', |
| 45 | 'password': 'p'}, |
| 46 | {'username': 'test_user3', 'tenant_name': 'test_tenant3', |
| 47 | 'password': 'p'}, |
| 48 | {'username': 'test_user4', 'tenant_name': 'test_tenant4', |
| 49 | 'password': 'p'}, |
| 50 | {'username': 'test_user5', 'tenant_name': 'test_tenant5', |
| 51 | 'password': 'p'}, |
| 52 | {'username': 'test_user6', 'tenant_name': 'test_tenant6', |
Matthew Treinish | 976e8df | 2014-12-19 14:21:54 -0500 | [diff] [blame] | 53 | 'password': 'p', 'roles': ['role1', 'role2']}, |
| 54 | {'username': 'test_user7', 'tenant_name': 'test_tenant7', |
| 55 | 'password': 'p', 'roles': ['role2', 'role3']}, |
| 56 | {'username': 'test_user8', 'tenant_name': 'test_tenant8', |
| 57 | 'password': 'p', 'roles': ['role4', 'role1']}, |
| 58 | {'username': 'test_user9', 'tenant_name': 'test_tenant9', |
| 59 | 'password': 'p', 'roles': ['role1', 'role2', 'role3', 'role4']}, |
| 60 | {'username': 'test_user10', 'tenant_name': 'test_tenant10', |
| 61 | 'password': 'p', 'roles': ['role1', 'role2', 'role3', 'role4']}, |
| 62 | {'username': 'test_user11', 'tenant_name': 'test_tenant11', |
| 63 | 'password': 'p', 'roles': [cfg.CONF.identity.admin_role]}, |
| 64 | {'username': 'test_user12', 'tenant_name': 'test_tenant12', |
| 65 | 'password': 'p', 'roles': [cfg.CONF.identity.admin_role]}, |
Matthew Treinish | c791ac4 | 2014-07-16 09:15:23 -0400 | [diff] [blame] | 66 | ] |
| 67 | self.useFixture(mockpatch.Patch( |
| 68 | 'tempest.common.accounts.read_accounts_yaml', |
| 69 | return_value=self.test_accounts)) |
Aaron Rosen | 4807004 | 2015-03-30 16:17:11 -0700 | [diff] [blame^] | 70 | cfg.CONF.set_default('test_accounts_file', 'fake_path', group='auth') |
Matthew Treinish | b19eeb8 | 2014-09-04 09:57:46 -0400 | [diff] [blame] | 71 | self.useFixture(mockpatch.Patch('os.path.isfile', return_value=True)) |
Matthew Treinish | c791ac4 | 2014-07-16 09:15:23 -0400 | [diff] [blame] | 72 | |
| 73 | def _get_hash_list(self, accounts_list): |
| 74 | hash_list = [] |
| 75 | for account in accounts_list: |
| 76 | hash = hashlib.md5() |
| 77 | hash.update(str(account)) |
Matthew Treinish | 976e8df | 2014-12-19 14:21:54 -0500 | [diff] [blame] | 78 | temp_hash = hash.hexdigest() |
| 79 | hash_list.append(temp_hash) |
Matthew Treinish | c791ac4 | 2014-07-16 09:15:23 -0400 | [diff] [blame] | 80 | return hash_list |
| 81 | |
| 82 | def test_get_hash(self): |
ghanshyam | c0edda0 | 2015-02-06 15:51:40 +0900 | [diff] [blame] | 83 | self.stubs.Set(token_client.TokenClientJSON, 'raw_request', |
Matthew Treinish | c791ac4 | 2014-07-16 09:15:23 -0400 | [diff] [blame] | 84 | fake_identity._fake_v2_response) |
Andrea Frittoli | c328015 | 2015-02-26 12:42:34 +0000 | [diff] [blame] | 85 | test_account_class = accounts.Accounts('v2', 'test_name') |
Matthew Treinish | c791ac4 | 2014-07-16 09:15:23 -0400 | [diff] [blame] | 86 | hash_list = self._get_hash_list(self.test_accounts) |
| 87 | test_cred_dict = self.test_accounts[3] |
ghanshyam | 5ff763f | 2015-02-18 16:15:58 +0900 | [diff] [blame] | 88 | test_creds = auth.get_credentials(fake_identity.FAKE_AUTH_URL, |
| 89 | **test_cred_dict) |
Matthew Treinish | c791ac4 | 2014-07-16 09:15:23 -0400 | [diff] [blame] | 90 | results = test_account_class.get_hash(test_creds) |
| 91 | self.assertEqual(hash_list[3], results) |
| 92 | |
| 93 | def test_get_hash_dict(self): |
Andrea Frittoli | c328015 | 2015-02-26 12:42:34 +0000 | [diff] [blame] | 94 | test_account_class = accounts.Accounts('v2', 'test_name') |
Matthew Treinish | c791ac4 | 2014-07-16 09:15:23 -0400 | [diff] [blame] | 95 | hash_dict = test_account_class.get_hash_dict(self.test_accounts) |
| 96 | hash_list = self._get_hash_list(self.test_accounts) |
| 97 | for hash in hash_list: |
Matthew Treinish | 976e8df | 2014-12-19 14:21:54 -0500 | [diff] [blame] | 98 | self.assertIn(hash, hash_dict['creds'].keys()) |
| 99 | self.assertIn(hash_dict['creds'][hash], self.test_accounts) |
Matthew Treinish | c791ac4 | 2014-07-16 09:15:23 -0400 | [diff] [blame] | 100 | |
| 101 | def test_create_hash_file_previous_file(self): |
| 102 | # Emulate the lock existing on the filesystem |
| 103 | self.useFixture(mockpatch.Patch('os.path.isfile', return_value=True)) |
| 104 | with mock.patch('__builtin__.open', mock.mock_open(), create=True): |
Andrea Frittoli | c328015 | 2015-02-26 12:42:34 +0000 | [diff] [blame] | 105 | test_account_class = accounts.Accounts('v2', 'test_name') |
Matthew Treinish | c791ac4 | 2014-07-16 09:15:23 -0400 | [diff] [blame] | 106 | res = test_account_class._create_hash_file('12345') |
| 107 | self.assertFalse(res, "_create_hash_file should return False if the " |
| 108 | "pseudo-lock file already exists") |
| 109 | |
| 110 | def test_create_hash_file_no_previous_file(self): |
| 111 | # Emulate the lock not existing on the filesystem |
| 112 | self.useFixture(mockpatch.Patch('os.path.isfile', return_value=False)) |
| 113 | with mock.patch('__builtin__.open', mock.mock_open(), create=True): |
Andrea Frittoli | c328015 | 2015-02-26 12:42:34 +0000 | [diff] [blame] | 114 | test_account_class = accounts.Accounts('v2', 'test_name') |
Matthew Treinish | c791ac4 | 2014-07-16 09:15:23 -0400 | [diff] [blame] | 115 | res = test_account_class._create_hash_file('12345') |
| 116 | self.assertTrue(res, "_create_hash_file should return True if the " |
| 117 | "pseudo-lock doesn't already exist") |
| 118 | |
Doug Hellmann | 583ce2c | 2015-03-11 14:55:46 +0000 | [diff] [blame] | 119 | @mock.patch('oslo_concurrency.lockutils.lock') |
Matthew Treinish | c791ac4 | 2014-07-16 09:15:23 -0400 | [diff] [blame] | 120 | def test_get_free_hash_no_previous_accounts(self, lock_mock): |
| 121 | # Emulate no pre-existing lock |
| 122 | self.useFixture(mockpatch.Patch('os.path.isdir', return_value=False)) |
| 123 | hash_list = self._get_hash_list(self.test_accounts) |
| 124 | mkdir_mock = self.useFixture(mockpatch.Patch('os.mkdir')) |
| 125 | self.useFixture(mockpatch.Patch('os.path.isfile', return_value=False)) |
Andrea Frittoli | c328015 | 2015-02-26 12:42:34 +0000 | [diff] [blame] | 126 | test_account_class = accounts.Accounts('v2', 'test_name') |
Matthew Treinish | c791ac4 | 2014-07-16 09:15:23 -0400 | [diff] [blame] | 127 | with mock.patch('__builtin__.open', mock.mock_open(), |
| 128 | create=True) as open_mock: |
| 129 | test_account_class._get_free_hash(hash_list) |
Matthew Treinish | b503f03 | 2015-03-12 15:48:49 -0400 | [diff] [blame] | 130 | lock_path = os.path.join(lockutils.get_lock_path(accounts.CONF), |
Doug Hellmann | 583ce2c | 2015-03-11 14:55:46 +0000 | [diff] [blame] | 131 | 'test_accounts', |
Matthew Treinish | c791ac4 | 2014-07-16 09:15:23 -0400 | [diff] [blame] | 132 | hash_list[0]) |
| 133 | open_mock.assert_called_once_with(lock_path, 'w') |
Doug Hellmann | 583ce2c | 2015-03-11 14:55:46 +0000 | [diff] [blame] | 134 | mkdir_path = os.path.join(accounts.CONF.oslo_concurrency.lock_path, |
| 135 | 'test_accounts') |
Matthew Treinish | c791ac4 | 2014-07-16 09:15:23 -0400 | [diff] [blame] | 136 | mkdir_mock.mock.assert_called_once_with(mkdir_path) |
| 137 | |
Doug Hellmann | 583ce2c | 2015-03-11 14:55:46 +0000 | [diff] [blame] | 138 | @mock.patch('oslo_concurrency.lockutils.lock') |
Matthew Treinish | c791ac4 | 2014-07-16 09:15:23 -0400 | [diff] [blame] | 139 | def test_get_free_hash_no_free_accounts(self, lock_mock): |
| 140 | hash_list = self._get_hash_list(self.test_accounts) |
| 141 | # Emulate pre-existing lock dir |
| 142 | self.useFixture(mockpatch.Patch('os.path.isdir', return_value=True)) |
| 143 | # Emulate all lcoks in list are in use |
| 144 | self.useFixture(mockpatch.Patch('os.path.isfile', return_value=True)) |
Andrea Frittoli | c328015 | 2015-02-26 12:42:34 +0000 | [diff] [blame] | 145 | test_account_class = accounts.Accounts('v2', 'test_name') |
Matthew Treinish | 4041b26 | 2015-02-27 11:18:54 -0500 | [diff] [blame] | 146 | with mock.patch('__builtin__.open', mock.mock_open(), create=True): |
| 147 | self.assertRaises(exceptions.InvalidConfiguration, |
| 148 | test_account_class._get_free_hash, hash_list) |
Matthew Treinish | c791ac4 | 2014-07-16 09:15:23 -0400 | [diff] [blame] | 149 | |
Doug Hellmann | 583ce2c | 2015-03-11 14:55:46 +0000 | [diff] [blame] | 150 | @mock.patch('oslo_concurrency.lockutils.lock') |
Matthew Treinish | c791ac4 | 2014-07-16 09:15:23 -0400 | [diff] [blame] | 151 | def test_get_free_hash_some_in_use_accounts(self, lock_mock): |
| 152 | # Emulate no pre-existing lock |
| 153 | self.useFixture(mockpatch.Patch('os.path.isdir', return_value=True)) |
| 154 | hash_list = self._get_hash_list(self.test_accounts) |
Andrea Frittoli | c328015 | 2015-02-26 12:42:34 +0000 | [diff] [blame] | 155 | test_account_class = accounts.Accounts('v2', 'test_name') |
Matthew Treinish | c791ac4 | 2014-07-16 09:15:23 -0400 | [diff] [blame] | 156 | |
| 157 | def _fake_is_file(path): |
| 158 | # Fake isfile() to return that the path exists unless a specific |
| 159 | # hash is in the path |
| 160 | if hash_list[3] in path: |
| 161 | return False |
| 162 | return True |
| 163 | |
| 164 | self.stubs.Set(os.path, 'isfile', _fake_is_file) |
| 165 | with mock.patch('__builtin__.open', mock.mock_open(), |
| 166 | create=True) as open_mock: |
| 167 | test_account_class._get_free_hash(hash_list) |
Matthew Treinish | b503f03 | 2015-03-12 15:48:49 -0400 | [diff] [blame] | 168 | lock_path = os.path.join(lockutils.get_lock_path(accounts.CONF), |
Doug Hellmann | 583ce2c | 2015-03-11 14:55:46 +0000 | [diff] [blame] | 169 | 'test_accounts', |
Matthew Treinish | c791ac4 | 2014-07-16 09:15:23 -0400 | [diff] [blame] | 170 | hash_list[3]) |
Matthew Treinish | 4041b26 | 2015-02-27 11:18:54 -0500 | [diff] [blame] | 171 | open_mock.assert_has_calls([mock.call(lock_path, 'w')]) |
Matthew Treinish | c791ac4 | 2014-07-16 09:15:23 -0400 | [diff] [blame] | 172 | |
Doug Hellmann | 583ce2c | 2015-03-11 14:55:46 +0000 | [diff] [blame] | 173 | @mock.patch('oslo_concurrency.lockutils.lock') |
Matthew Treinish | c791ac4 | 2014-07-16 09:15:23 -0400 | [diff] [blame] | 174 | def test_remove_hash_last_account(self, lock_mock): |
| 175 | hash_list = self._get_hash_list(self.test_accounts) |
| 176 | # Pretend the pseudo-lock is there |
| 177 | self.useFixture(mockpatch.Patch('os.path.isfile', return_value=True)) |
| 178 | # Pretend the lock dir is empty |
| 179 | self.useFixture(mockpatch.Patch('os.listdir', return_value=[])) |
Andrea Frittoli | c328015 | 2015-02-26 12:42:34 +0000 | [diff] [blame] | 180 | test_account_class = accounts.Accounts('v2', 'test_name') |
Matthew Treinish | c791ac4 | 2014-07-16 09:15:23 -0400 | [diff] [blame] | 181 | remove_mock = self.useFixture(mockpatch.Patch('os.remove')) |
| 182 | rmdir_mock = self.useFixture(mockpatch.Patch('os.rmdir')) |
| 183 | test_account_class.remove_hash(hash_list[2]) |
Matthew Treinish | b503f03 | 2015-03-12 15:48:49 -0400 | [diff] [blame] | 184 | hash_path = os.path.join(lockutils.get_lock_path(accounts.CONF), |
Doug Hellmann | 583ce2c | 2015-03-11 14:55:46 +0000 | [diff] [blame] | 185 | 'test_accounts', |
Matthew Treinish | c791ac4 | 2014-07-16 09:15:23 -0400 | [diff] [blame] | 186 | hash_list[2]) |
Doug Hellmann | 583ce2c | 2015-03-11 14:55:46 +0000 | [diff] [blame] | 187 | lock_path = os.path.join(accounts.CONF.oslo_concurrency.lock_path, |
| 188 | 'test_accounts') |
Matthew Treinish | c791ac4 | 2014-07-16 09:15:23 -0400 | [diff] [blame] | 189 | remove_mock.mock.assert_called_once_with(hash_path) |
| 190 | rmdir_mock.mock.assert_called_once_with(lock_path) |
| 191 | |
Doug Hellmann | 583ce2c | 2015-03-11 14:55:46 +0000 | [diff] [blame] | 192 | @mock.patch('oslo_concurrency.lockutils.lock') |
Matthew Treinish | c791ac4 | 2014-07-16 09:15:23 -0400 | [diff] [blame] | 193 | def test_remove_hash_not_last_account(self, lock_mock): |
| 194 | hash_list = self._get_hash_list(self.test_accounts) |
| 195 | # Pretend the pseudo-lock is there |
| 196 | self.useFixture(mockpatch.Patch('os.path.isfile', return_value=True)) |
| 197 | # Pretend the lock dir is empty |
| 198 | self.useFixture(mockpatch.Patch('os.listdir', return_value=[ |
| 199 | hash_list[1], hash_list[4]])) |
Andrea Frittoli | c328015 | 2015-02-26 12:42:34 +0000 | [diff] [blame] | 200 | test_account_class = accounts.Accounts('v2', 'test_name') |
Matthew Treinish | c791ac4 | 2014-07-16 09:15:23 -0400 | [diff] [blame] | 201 | remove_mock = self.useFixture(mockpatch.Patch('os.remove')) |
| 202 | rmdir_mock = self.useFixture(mockpatch.Patch('os.rmdir')) |
| 203 | test_account_class.remove_hash(hash_list[2]) |
Matthew Treinish | b503f03 | 2015-03-12 15:48:49 -0400 | [diff] [blame] | 204 | hash_path = os.path.join(lockutils.get_lock_path(accounts.CONF), |
Doug Hellmann | 583ce2c | 2015-03-11 14:55:46 +0000 | [diff] [blame] | 205 | 'test_accounts', |
Matthew Treinish | c791ac4 | 2014-07-16 09:15:23 -0400 | [diff] [blame] | 206 | hash_list[2]) |
| 207 | remove_mock.mock.assert_called_once_with(hash_path) |
| 208 | rmdir_mock.mock.assert_not_called() |
Matthew Treinish | 09f1783 | 2014-08-15 15:22:50 -0400 | [diff] [blame] | 209 | |
| 210 | def test_is_multi_user(self): |
Andrea Frittoli | c328015 | 2015-02-26 12:42:34 +0000 | [diff] [blame] | 211 | test_accounts_class = accounts.Accounts('v2', 'test_name') |
Matthew Treinish | 09f1783 | 2014-08-15 15:22:50 -0400 | [diff] [blame] | 212 | self.assertTrue(test_accounts_class.is_multi_user()) |
| 213 | |
| 214 | def test_is_not_multi_user(self): |
| 215 | self.test_accounts = [self.test_accounts[0]] |
| 216 | self.useFixture(mockpatch.Patch( |
| 217 | 'tempest.common.accounts.read_accounts_yaml', |
| 218 | return_value=self.test_accounts)) |
Andrea Frittoli | c328015 | 2015-02-26 12:42:34 +0000 | [diff] [blame] | 219 | test_accounts_class = accounts.Accounts('v2', 'test_name') |
Matthew Treinish | 09f1783 | 2014-08-15 15:22:50 -0400 | [diff] [blame] | 220 | self.assertFalse(test_accounts_class.is_multi_user()) |
Andrea Frittoli | b1c23fc | 2014-09-03 13:40:08 +0100 | [diff] [blame] | 221 | |
Matthew Treinish | 976e8df | 2014-12-19 14:21:54 -0500 | [diff] [blame] | 222 | def test__get_creds_by_roles_one_role(self): |
| 223 | self.useFixture(mockpatch.Patch( |
| 224 | 'tempest.common.accounts.read_accounts_yaml', |
| 225 | return_value=self.test_accounts)) |
Andrea Frittoli | c328015 | 2015-02-26 12:42:34 +0000 | [diff] [blame] | 226 | test_accounts_class = accounts.Accounts('v2', 'test_name') |
Matthew Treinish | 976e8df | 2014-12-19 14:21:54 -0500 | [diff] [blame] | 227 | hashes = test_accounts_class.hash_dict['roles']['role4'] |
| 228 | temp_hash = hashes[0] |
| 229 | get_free_hash_mock = self.useFixture(mockpatch.PatchObject( |
| 230 | test_accounts_class, '_get_free_hash', return_value=temp_hash)) |
| 231 | # Test a single role returns all matching roles |
| 232 | test_accounts_class._get_creds(roles=['role4']) |
| 233 | calls = get_free_hash_mock.mock.mock_calls |
| 234 | self.assertEqual(len(calls), 1) |
| 235 | args = calls[0][1][0] |
| 236 | for i in hashes: |
| 237 | self.assertIn(i, args) |
| 238 | |
| 239 | def test__get_creds_by_roles_list_role(self): |
| 240 | self.useFixture(mockpatch.Patch( |
| 241 | 'tempest.common.accounts.read_accounts_yaml', |
| 242 | return_value=self.test_accounts)) |
Andrea Frittoli | c328015 | 2015-02-26 12:42:34 +0000 | [diff] [blame] | 243 | test_accounts_class = accounts.Accounts('v2', 'test_name') |
Matthew Treinish | 976e8df | 2014-12-19 14:21:54 -0500 | [diff] [blame] | 244 | hashes = test_accounts_class.hash_dict['roles']['role4'] |
| 245 | hashes2 = test_accounts_class.hash_dict['roles']['role2'] |
| 246 | hashes = list(set(hashes) & set(hashes2)) |
| 247 | temp_hash = hashes[0] |
| 248 | get_free_hash_mock = self.useFixture(mockpatch.PatchObject( |
| 249 | test_accounts_class, '_get_free_hash', return_value=temp_hash)) |
| 250 | # Test an intersection of multiple roles |
| 251 | test_accounts_class._get_creds(roles=['role2', 'role4']) |
| 252 | calls = get_free_hash_mock.mock.mock_calls |
| 253 | self.assertEqual(len(calls), 1) |
| 254 | args = calls[0][1][0] |
| 255 | for i in hashes: |
| 256 | self.assertIn(i, args) |
| 257 | |
| 258 | def test__get_creds_by_roles_no_admin(self): |
| 259 | self.useFixture(mockpatch.Patch( |
| 260 | 'tempest.common.accounts.read_accounts_yaml', |
| 261 | return_value=self.test_accounts)) |
Andrea Frittoli | c328015 | 2015-02-26 12:42:34 +0000 | [diff] [blame] | 262 | test_accounts_class = accounts.Accounts('v2', 'test_name') |
Matthew Treinish | 976e8df | 2014-12-19 14:21:54 -0500 | [diff] [blame] | 263 | hashes = test_accounts_class.hash_dict['creds'].keys() |
| 264 | admin_hashes = test_accounts_class.hash_dict['roles'][ |
| 265 | cfg.CONF.identity.admin_role] |
| 266 | temp_hash = hashes[0] |
| 267 | get_free_hash_mock = self.useFixture(mockpatch.PatchObject( |
| 268 | test_accounts_class, '_get_free_hash', return_value=temp_hash)) |
| 269 | # Test an intersection of multiple roles |
| 270 | test_accounts_class._get_creds() |
| 271 | calls = get_free_hash_mock.mock.mock_calls |
| 272 | self.assertEqual(len(calls), 1) |
| 273 | args = calls[0][1][0] |
| 274 | self.assertEqual(len(args), 10) |
| 275 | for i in admin_hashes: |
| 276 | self.assertNotIn(i, args) |
| 277 | |
Andrea Frittoli | b1c23fc | 2014-09-03 13:40:08 +0100 | [diff] [blame] | 278 | |
| 279 | class TestNotLockingAccount(base.TestCase): |
| 280 | |
| 281 | def setUp(self): |
| 282 | super(TestNotLockingAccount, self).setUp() |
| 283 | self.useFixture(fake_config.ConfigFixture()) |
| 284 | self.stubs.Set(config, 'TempestConfigPrivate', fake_config.FakePrivate) |
Doug Hellmann | 583ce2c | 2015-03-11 14:55:46 +0000 | [diff] [blame] | 285 | self.useFixture(lockutils_fixtures.ExternalLockFixture()) |
Andrea Frittoli | b1c23fc | 2014-09-03 13:40:08 +0100 | [diff] [blame] | 286 | self.test_accounts = [ |
| 287 | {'username': 'test_user1', 'tenant_name': 'test_tenant1', |
| 288 | 'password': 'p'}, |
| 289 | {'username': 'test_user2', 'tenant_name': 'test_tenant2', |
| 290 | 'password': 'p'}, |
| 291 | {'username': 'test_user3', 'tenant_name': 'test_tenant3', |
| 292 | 'password': 'p'}, |
| 293 | ] |
| 294 | self.useFixture(mockpatch.Patch( |
| 295 | 'tempest.common.accounts.read_accounts_yaml', |
| 296 | return_value=self.test_accounts)) |
| 297 | cfg.CONF.set_default('test_accounts_file', '', group='auth') |
Matthew Treinish | b19eeb8 | 2014-09-04 09:57:46 -0400 | [diff] [blame] | 298 | self.useFixture(mockpatch.Patch('os.path.isfile', return_value=True)) |
Andrea Frittoli | b1c23fc | 2014-09-03 13:40:08 +0100 | [diff] [blame] | 299 | |
Matthew Treinish | fc7cd8f | 2015-03-30 11:51:55 -0400 | [diff] [blame] | 300 | def test_get_creds_roles_nonlocking_invalid(self): |
Andrea Frittoli | c328015 | 2015-02-26 12:42:34 +0000 | [diff] [blame] | 301 | test_accounts_class = accounts.NotLockingAccounts('v2', 'test_name') |
Andrea Frittoli | b1c23fc | 2014-09-03 13:40:08 +0100 | [diff] [blame] | 302 | self.assertRaises(exceptions.InvalidConfiguration, |
Matthew Treinish | fc7cd8f | 2015-03-30 11:51:55 -0400 | [diff] [blame] | 303 | test_accounts_class.get_creds_by_roles, |
| 304 | ['fake_role']) |