From a59bd0c7d0f7c3666eb0eb40e36ce981c8e089f0 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Mon, 20 Apr 2015 12:02:48 -0400 Subject: Fix test accounts unit test race with networks Previously the unit tests for the accounts providers were assuming that all tests would be run in order. This was causing an occasional failure when 1 of 2 accounts with a network in the fake accounts list were used for a test not mocking the network clients. This commit addresses this issue by changing the fake test list in setUp to not use accounts with networks. Then the test which does test accounts with networks will do a cleanup on the mock from setup and use it's own accounts list. Closes-Bug: #1446309 Change-Id: Id7eedc4f9063f33287c945ed72edd59f52d80952 --- tempest/tests/common/test_accounts.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/tempest/tests/common/test_accounts.py b/tempest/tests/common/test_accounts.py index b17667540..b4048ba99 100644 --- a/tempest/tests/common/test_accounts.py +++ b/tempest/tests/common/test_accounts.py @@ -68,13 +68,8 @@ class TestAccount(base.TestCase): 'password': 'p', 'roles': [cfg.CONF.identity.admin_role]}, {'username': 'test_user12', 'tenant_name': 'test_tenant12', 'password': 'p', 'roles': [cfg.CONF.identity.admin_role]}, - {'username': 'test_user13', 'tenant_name': 'test_tenant13', - 'password': 'p', 'resources': {'network': 'network-1'}}, - {'username': 'test_user14', 'tenant_name': 'test_tenant14', - 'password': 'p', 'roles': ['role-7', 'role-11'], - 'resources': {'network': 'network-2'}}, ] - self.useFixture(mockpatch.Patch( + self.accounts_mock = self.useFixture(mockpatch.Patch( 'tempest.common.accounts.read_accounts_yaml', return_value=self.test_accounts)) cfg.CONF.set_default('test_accounts_file', 'fake_path', group='auth') @@ -281,14 +276,22 @@ class TestAccount(base.TestCase): calls = get_free_hash_mock.mock.mock_calls self.assertEqual(len(calls), 1) args = calls[0][1][0] - self.assertEqual(len(args), 12) + self.assertEqual(len(args), 10) for i in admin_hashes: self.assertNotIn(i, args) def test_networks_returned_with_creds(self): + test_accounts = [ + {'username': 'test_user13', 'tenant_name': 'test_tenant13', + 'password': 'p', 'resources': {'network': 'network-1'}}, + {'username': 'test_user14', 'tenant_name': 'test_tenant14', + 'password': 'p', 'roles': ['role-7', 'role-11'], + 'resources': {'network': 'network-2'}}] + # Clear previous mock using self.test_accounts + self.accounts_mock.cleanUp() self.useFixture(mockpatch.Patch( 'tempest.common.accounts.read_accounts_yaml', - return_value=self.test_accounts)) + return_value=test_accounts)) test_accounts_class = accounts.Accounts('v2', 'test_name') with mock.patch('tempest.services.compute.json.networks_client.' 'NetworksClientJSON.list_networks', -- cgit v1.2.1