|
16 | 16 | import json
|
17 | 17 | import os
|
18 | 18 | import random
|
| 19 | +from subprocess import CalledProcessError |
19 | 20 | import time
|
20 | 21 |
|
| 22 | +import backoff |
| 23 | +from google.auth.exceptions import RefreshError |
21 | 24 | from google.oauth2 import service_account
|
22 | 25 | import googleapiclient.discovery
|
23 |
| -from retrying import retry |
24 | 26 |
|
25 | 27 | from service_account_ssh import main
|
26 | 28 |
|
@@ -84,22 +86,21 @@ def test_main(capsys):
|
84 | 86 | 'oslogin', 'v1', cache_discovery=False, credentials=credentials)
|
85 | 87 | account = 'users/' + account_email
|
86 | 88 |
|
87 |
| - @retry(wait_exponential_multiplier=1000, wait_exponential_max=300000, |
88 |
| - stop_max_attempt_number=10) |
| 89 | + # More exceptions could be raised, keeping track of ones I could |
| 90 | + # find for now. |
| 91 | + @backoff.on_exception(backoff.expo, |
| 92 | + (CalledProcessError, |
| 93 | + RefreshError), |
| 94 | + max_tries=5) |
89 | 95 | def ssh_login():
|
90 | 96 | main(cmd, project, test_id, zone, oslogin, account, hostname)
|
91 | 97 | out, _ = capsys.readouterr()
|
92 | 98 | assert_value = 'Linux {test_id}'.format(test_id=test_id)
|
93 | 99 | assert assert_value in out
|
94 | 100 |
|
95 | 101 | # Test SSH to the instance.
|
96 |
| - try: |
97 |
| - ssh_login() |
98 |
| - except Exception: |
99 |
| - raise Exception('SSH to the test instance failed.') |
100 |
| - |
101 |
| - finally: |
102 |
| - cleanup_resources(compute, iam, project, test_id, zone, account_email) |
| 102 | + ssh_login() |
| 103 | + cleanup_resources(compute, iam, project, test_id, zone, account_email) |
103 | 104 |
|
104 | 105 |
|
105 | 106 | def setup_resources(
|
|
0 commit comments