Skip to content

Commit 08d175c

Browse files
authored
Add a sleep for the service account to propagate. (GoogleCloudPlatform#6895)
I suspect that sometimes this method fails because there is a race condition when creating the new servie account. Adding a service account is not a LRO, but it's also no atomic. The information about the new account needs a moment to propagate through the system. Closes GoogleCloudPlatform#6894 ## Description Fixes #<ISSUE-NUMBER> Note: It's a good idea to open an issue first for discussion. ## Checklist - [x] I have followed [Sample Guidelines from AUTHORING_GUIDE.MD](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/AUTHORING_GUIDE.md) - [x] README is updated to include [all relevant information](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/AUTHORING_GUIDE.md#readme-file) - [x] **Tests** pass: `nox -s py-3.6` (see [Test Environment Setup](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/AUTHORING_GUIDE.md#test-environment-setup)) - [x] **Lint** pass: `nox -s lint` (see [Test Environment Setup](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/AUTHORING_GUIDE.md#test-environment-setup)) - [ ] These samples need a new **API enabled** in testing projects to pass (let us know which ones) - [ ] These samples need a new/updated **env vars** in testing projects set to pass (let us know which ones) - [x] Please **merge** this PR for me once it is approved. - [ ] This sample adds a new sample directory, and I updated the [CODEOWNERS file](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/.github/CODEOWNERS) with the codeowners for this sample
1 parent 47f939e commit 08d175c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

compute/oslogin/service_account_ssh_test.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
# Copyright 2019, Google, Inc.
1+
# Copyright 2019 Google LLC
2+
#
23
# Licensed under the Apache License, Version 2.0 (the "License");
34
# you may not use this file except in compliance with the License.
45
# You may obtain a copy of the License at
56
#
6-
# http://www.apache.org/licenses/LICENSE-2.0
7+
# https://www.apache.org/licenses/LICENSE-2.0
78
#
89
# Unless required by applicable law or agreed to in writing, software
910
# distributed under the License is distributed on an "AS IS" BASIS,
@@ -112,6 +113,10 @@ def setup_resources(
112113
'accountId': test_id
113114
}).execute()
114115

116+
# Wait for the creation to propagate through the system, so the
117+
# following calls don't fail sometimes.
118+
time.sleep(5)
119+
115120
# Grant the service account access to itself.
116121
iam.projects().serviceAccounts().setIamPolicy(
117122
resource='projects/' + project + '/serviceAccounts/' + account_email,

0 commit comments

Comments
 (0)