Skip to content

Commit ee5d30b

Browse files
committed
Use timeout ladder
Signed-off-by: Matthias Büchse <[email protected]>
1 parent 9185160 commit ee5d30b

File tree

1 file changed

+16
-31
lines changed

1 file changed

+16
-31
lines changed

Tests/iaas/volume-backup/volume-backup-tester.py

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,34 +27,29 @@
2727
# used by the cleanup routine to identify resources that can be safely deleted
2828
DEFAULT_PREFIX = "scs-test-"
2929

30-
# timeout in seconds for resource availability checks
31-
# (e.g. a volume becoming available)
32-
WAIT_TIMEOUT = 80
33-
3430

3531
def wait_for_resource(
3632
get_func: typing.Callable[[str], openstack.resource.Resource],
3733
resource_id: str,
3834
expected_status=("available", ),
39-
timeout=WAIT_TIMEOUT,
35+
timeouts=(2, 3, 5, 10, 15, 25, 50),
4036
) -> None:
4137
seconds_waited = 0
42-
wait_delay = 0.5
38+
timeout_iter = iter(timeouts)
4339
resource = get_func(resource_id)
4440
while resource is None or resource.status not in expected_status:
45-
time.sleep(wait_delay)
46-
seconds_waited += wait_delay
47-
wait_delay += 0.1
48-
if seconds_waited >= timeout:
41+
wait_delay = next(timeout_iter, None)
42+
if wait_delay is None:
4943
raise RuntimeError(
5044
f"Timed out after {seconds_waited} s: waiting for resource {resource_id} "
5145
f"to be in status {expected_status} (current: {resource and resource.status})"
5246
)
47+
time.sleep(wait_delay)
48+
seconds_waited += wait_delay
5349
resource = get_func(resource_id)
5450

5551

56-
def test_backup(conn: openstack.connection.Connection,
57-
prefix=DEFAULT_PREFIX, timeout=WAIT_TIMEOUT) -> None:
52+
def test_backup(conn: openstack.connection.Connection, prefix=DEFAULT_PREFIX) -> None:
5853
"""Execute volume backup tests on the connection
5954
6055
This will create an empty volume, a backup of that empty volume and then
@@ -77,7 +72,7 @@ def test_backup(conn: openstack.connection.Connection,
7772
f"↳ waiting for volume with ID '{volume_id}' to reach status "
7873
f"'available' ..."
7974
)
80-
wait_for_resource(conn.block_storage.get_volume, volume_id, timeout=timeout)
75+
wait_for_resource(conn.block_storage.get_volume, volume_id)
8176
logging.info("Create empty volume: PASS")
8277

8378
# CREATE BACKUP
@@ -90,7 +85,7 @@ def test_backup(conn: openstack.connection.Connection,
9085
raise RuntimeError("Retrieving backup by ID failed")
9186

9287
logging.info(f"↳ waiting for backup '{backup_id}' to become available ...")
93-
wait_for_resource(conn.block_storage.get_backup, backup_id, timeout=timeout)
88+
wait_for_resource(conn.block_storage.get_backup, backup_id)
9489
logging.info("Create backup from volume: PASS")
9590

9691
# RESTORE BACKUP
@@ -102,19 +97,18 @@ def test_backup(conn: openstack.connection.Connection,
10297
f"↳ waiting for restoration target volume '{restored_volume_name}' "
10398
f"to be created ..."
10499
)
105-
wait_for_resource(conn.block_storage.find_volume, restored_volume_name, timeout=timeout)
100+
wait_for_resource(conn.block_storage.find_volume, restored_volume_name)
106101
# wait for the volume restoration to finish
107102
logging.info(
108103
f"↳ waiting for restoration target volume '{restored_volume_name}' "
109104
f"to reach 'available' status ..."
110105
)
111106
volume_id = conn.block_storage.find_volume(restored_volume_name).id
112-
wait_for_resource(conn.block_storage.get_volume, volume_id, timeout=timeout)
107+
wait_for_resource(conn.block_storage.get_volume, volume_id)
113108
logging.info("Restore volume from backup: PASS")
114109

115110

116-
def cleanup(conn: openstack.connection.Connection, prefix=DEFAULT_PREFIX,
117-
timeout=WAIT_TIMEOUT) -> bool:
111+
def cleanup(conn: openstack.connection.Connection, prefix=DEFAULT_PREFIX) -> bool:
118112
"""
119113
Looks up volume and volume backup resources matching the given prefix and
120114
deletes them.
@@ -135,7 +129,6 @@ def cleanup(conn: openstack.connection.Connection, prefix=DEFAULT_PREFIX,
135129
conn.block_storage.get_backup,
136130
backup.id,
137131
expected_status=("available", "error"),
138-
timeout=timeout,
139132
)
140133
logging.info(f"↳ deleting volume backup '{backup.id}' ...")
141134
conn.block_storage.delete_backup(backup.id)
@@ -157,7 +150,7 @@ def cleanup(conn: openstack.connection.Connection, prefix=DEFAULT_PREFIX,
157150
) > 0:
158151
time.sleep(1.0)
159152
seconds_waited += 1
160-
if seconds_waited >= timeout:
153+
if seconds_waited >= 100:
161154
cleanup_issues += 1
162155
logging.warning(
163156
f"Timeout reached while waiting for all backups with prefix "
@@ -175,7 +168,6 @@ def cleanup(conn: openstack.connection.Connection, prefix=DEFAULT_PREFIX,
175168
conn.block_storage.get_volume,
176169
volume.id,
177170
expected_status=("available", "error"),
178-
timeout=timeout,
179171
)
180172
logging.info(f"↳ deleting volume '{volume.id}' ...")
181173
conn.block_storage.delete_volume(volume.id)
@@ -220,13 +212,6 @@ def main():
220212
f"and/or cleaned up by this script within the configured domains "
221213
f"(default: '{DEFAULT_PREFIX}')"
222214
)
223-
parser.add_argument(
224-
"--timeout", type=int,
225-
default=WAIT_TIMEOUT,
226-
help=f"Timeout in seconds for operations waiting for resources to "
227-
f"become available such as creating volumes and volume backups "
228-
f"(default: '{WAIT_TIMEOUT}')"
229-
)
230215
parser.add_argument(
231216
"--cleanup-only", action="store_true",
232217
help="Instead of executing tests, cleanup all resources "
@@ -249,20 +234,20 @@ def main():
249234
password = getpass.getpass("Enter password: ") if args.ask else None
250235

251236
with openstack.connect(cloud, password=password) as conn:
252-
if not cleanup(conn, prefix=args.prefix, timeout=args.timeout):
237+
if not cleanup(conn, prefix=args.prefix):
253238
raise RuntimeError("Initial cleanup failed")
254239
if args.cleanup_only:
255240
logging.info("Cleanup-only run finished.")
256241
return
257242
try:
258-
test_backup(conn, prefix=args.prefix, timeout=args.timeout)
243+
test_backup(conn, prefix=args.prefix)
259244
except BaseException:
260245
print('volume-backup-check: FAIL')
261246
raise
262247
else:
263248
print('volume-backup-check: PASS')
264249
finally:
265-
cleanup(conn, prefix=args.prefix, timeout=args.timeout)
250+
cleanup(conn, prefix=args.prefix)
266251

267252

268253
if __name__ == "__main__":

0 commit comments

Comments
 (0)