Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d8dbc3a

Browse files
author
Takashi Matsuo
authored
[iam] fix: reuse the same custom role for read/update tests (GoogleCloudPlatform#3291)
* [iam] fix: reuse the same custom role for read/update tests fixes GoogleCloudPlatform#2885 fixes GoogleCloudPlatform#2886 This PR will reduce the number of temporary custom roles to half. Not a fundamental fix, but it will definitely mitigate the above issues. * only ignore HttpError 409
1 parent ae464b1 commit d8dbc3a

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

iam/api-client/custom_roles_test.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
GCLOUD_PROJECT = os.environ["GCLOUD_PROJECT"]
2323

24-
CUSTOM_ROLE_NAME = "pythonTestCustomRole" + str(uuid.uuid1().int)
24+
CUSTOM_ROLE_NAME = "pythonTestCustomRole"
2525
CUSTOM_ROLE_TITLE = "Python Test Custom Role"
2626
CUSTOM_ROLE_DESCRIPTION = "This is a python test custom role"
2727
CUSTOM_ROLE_PERMISSIONS = ["iam.roles.get"]
@@ -33,22 +33,23 @@
3333

3434
@pytest.fixture(scope="module")
3535
def test_custom_role():
36-
# section to create custom role to test policy updates.
37-
custom_roles.create_role(
38-
CUSTOM_ROLE_NAME,
39-
GCLOUD_PROJECT,
40-
CUSTOM_ROLE_TITLE,
41-
CUSTOM_ROLE_DESCRIPTION,
42-
CUSTOM_ROLE_PERMISSIONS,
43-
CUSTOM_ROLE_STAGE,
44-
)
45-
yield CUSTOM_ROLE_NAME
46-
47-
# Delete the custom role
36+
# This custom role is reused in read/update tests.
4837
try:
49-
custom_roles.delete_role(CUSTOM_ROLE_NAME, GCLOUD_PROJECT)
50-
except googleapiclient.errors.HttpError:
51-
print("Custom role already deleted.")
38+
custom_roles.create_role(
39+
CUSTOM_ROLE_NAME,
40+
GCLOUD_PROJECT,
41+
CUSTOM_ROLE_TITLE,
42+
CUSTOM_ROLE_DESCRIPTION,
43+
CUSTOM_ROLE_PERMISSIONS,
44+
CUSTOM_ROLE_STAGE,
45+
)
46+
except googleapiclient.errors.HttpError as e:
47+
if "HttpError 409" not in str(e):
48+
raise e
49+
# Ignore error since we just reuse the same custom role.
50+
print('Re-using the custom role "{}".'.format(CUSTOM_ROLE_NAME))
51+
yield CUSTOM_ROLE_NAME
52+
# we don't delete this custom role for future tests.
5253

5354

5455
@pytest.fixture(scope="function")

0 commit comments

Comments
 (0)