Member role may already exist
The tests that first setup the v3 Member role may be getting into a race
condition where the Member role is attempted to be created by multiple
workers. This change ignores the conflict because the Member role is not
test specific so it can only be created once when no domain id is
provided. The create_user_role call already checks if the role exists,
but we have seen multiple threads attempt to create the role almost
simultaneously leading to a conflict on the second request.
Closes-Bug: #1596250
Co-Authored-By: Alex Schultz <aschultz@mirantis.com>
Co-Authored-By: Matthew Treinish <mtreinish@kortar.org>
Change-Id: Ic96f622a2fa00e2fd0cb3ebb22e3df000bac5345
diff --git a/tempest/common/dynamic_creds.py b/tempest/common/dynamic_creds.py
index b0c01f5..c9b9db1 100644
--- a/tempest/common/dynamic_creds.py
+++ b/tempest/common/dynamic_creds.py
@@ -159,7 +159,10 @@
# it must beassigned a role on the project. So we need to ensure that
# our newly created user has a role on the newly created project.
if self.identity_version == 'v3' and not role_assigned:
- self.creds_client.create_user_role('Member')
+ try:
+ self.creds_client.create_user_role('Member')
+ except lib_exc.Conflict:
+ LOG.warning('Member role already exists, ignoring conflict.')
self.creds_client.assign_user_role(user, project, 'Member')
creds = self.creds_client.get_credentials(user, project, user_password)
diff --git a/tempest/tests/common/test_dynamic_creds.py b/tempest/tests/common/test_dynamic_creds.py
index e97f65f..7a8637f 100644
--- a/tempest/tests/common/test_dynamic_creds.py
+++ b/tempest/tests/common/test_dynamic_creds.py
@@ -21,6 +21,7 @@
from tempest import config
from tempest import exceptions
from tempest.lib.common import rest_client
+from tempest.lib import exceptions as lib_exc
from tempest.lib.services.identity.v2 import token_client as v2_token_client
from tempest.lib.services.identity.v3 import token_client as v3_token_client
from tempest.lib.services.network import routers_client
@@ -635,3 +636,15 @@
return_value=(rest_client.ResponseBody
(200, {'project': {'id': id, 'name': name}}))))
return project_fix
+
+ @mock.patch('tempest.lib.common.rest_client.RestClient')
+ def test_member_role_creation_with_duplicate(self, rest_client_mock):
+ creds = dynamic_creds.DynamicCredentialProvider(**self.fixed_params)
+ creds.creds_client = mock.MagicMock()
+ creds.creds_client.create_user_role.side_effect = lib_exc.Conflict
+ with mock.patch('tempest.common.dynamic_creds.LOG') as log_mock:
+ creds._create_creds()
+ log_mock.warning.assert_called_once_with(
+ "Member role already exists, ignoring conflict.")
+ creds.creds_client.assign_user_role.assert_called_once_with(
+ mock.ANY, mock.ANY, 'Member')