Skip to content
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

Commit 141f7ac

Browse files
authored
chore: skip hmac tests until b/493225655 is fixed (#1771)
Skipping hmac tests if they fail with a 412 PreconditionFailed. This is occurring because the testing project python-docs-samples-tests has the constraints/iam.disableServiceAccountKeyCreation Organization Policy enforced.
1 parent 35b39b6 commit 141f7ac

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

samples/snippets/hmac_samples_test.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
set in order to run.
1818
"""
1919

20-
2120
import os
2221

2322
import google.api_core.exceptions
@@ -51,9 +50,18 @@ def new_hmac_key():
5150
5251
NOTE: Due to the module scope, test order in this file is significant
5352
"""
54-
hmac_key, secret = STORAGE_CLIENT.create_hmac_key(
55-
service_account_email=SERVICE_ACCOUNT_EMAIL, project_id=PROJECT_ID
56-
)
53+
try:
54+
hmac_key, secret = STORAGE_CLIENT.create_hmac_key(
55+
service_account_email=SERVICE_ACCOUNT_EMAIL, project_id=PROJECT_ID
56+
)
57+
except google.api_core.exceptions.PreconditionFailed as e:
58+
# Check if the failure is due to the Organization Policy constraint
59+
if "constraints/iam.disableServiceAccountKeyCreation" in str(e):
60+
pytest.skip(
61+
"Temporary skip: HMAC key creation is disabled by organization policy "
62+
"on project python-docs-samples-tests. See b/493225655."
63+
)
64+
raise
5765
yield hmac_key
5866
# Re-fetch the key metadata in case state has changed during the test.
5967
hmac_key = STORAGE_CLIENT.get_hmac_key_metadata(
@@ -77,9 +85,16 @@ def test_list_keys(capsys, new_hmac_key):
7785

7886

7987
def test_create_key(capsys):
80-
hmac_key = storage_create_hmac_key.create_key(
81-
PROJECT_ID, SERVICE_ACCOUNT_EMAIL
82-
)
88+
try:
89+
hmac_key = storage_create_hmac_key.create_key(PROJECT_ID, SERVICE_ACCOUNT_EMAIL)
90+
except google.api_core.exceptions.PreconditionFailed as e:
91+
if "constraints/iam.disableServiceAccountKeyCreation" in str(e):
92+
pytest.skip(
93+
"Temporary skip: HMAC key creation is disabled by organization policy "
94+
"on project python-docs-samples-tests. See b/493225655."
95+
)
96+
raise
97+
8398
hmac_key.state = "INACTIVE"
8499
hmac_key.update()
85100
hmac_key.delete()

0 commit comments

Comments
 (0)