Skip to content

Commit ce121d4

Browse files
author
Takashi Matsuo
authored
fix: add retry around ssh test (GoogleCloudPlatform#3287)
fixes GoogleCloudPlatform#3112 This will very likely fix the above issue.
1 parent 5c134ec commit ce121d4

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

compute/oslogin/requirements-test.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
pytest==5.3.2
22
mock==3.0.5
3+
retrying==1.3.3

compute/oslogin/service_account_ssh_test.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,19 @@
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License.
1313

14-
import os
15-
import time
16-
import random
1714
import base64
1815
import json
16+
import os
17+
import random
18+
import time
19+
1920
import googleapiclient.discovery
2021
from google.oauth2 import service_account
22+
from retrying import retry
23+
2124
from service_account_ssh import main
2225

26+
2327
'''
2428
The service account that runs this test must have the following roles:
2529
- roles/compute.instanceAdmin.v1
@@ -79,15 +83,17 @@ def test_main(capsys):
7983
'oslogin', 'v1', cache_discovery=False, credentials=credentials)
8084
account = 'users/' + account_email
8185

82-
# Give OS Login some time to catch up.
83-
time.sleep(120)
84-
85-
# Test SSH to the instance.
86-
try:
86+
@retry(wait_exponential_multiplier=1000, wait_exponential_max=300000,
87+
stop_max_attempt_number=10)
88+
def ssh_login():
8789
main(cmd, project, test_id, zone, oslogin, account, hostname)
8890
out, _ = capsys.readouterr()
8991
assert_value = 'Linux {test_id}'.format(test_id=test_id)
9092
assert assert_value in out
93+
94+
# Test SSH to the instance.
95+
try:
96+
ssh_login()
9197
except Exception:
9298
raise Exception('SSH to the test instance failed.')
9399

0 commit comments

Comments
 (0)