Skip to content

Commit

Permalink
patch(pytest_plugins/microceph): Add retry if microceph not ready (#175)
Browse files Browse the repository at this point in the history
Fixes #171 (on self-hosted runners, microceph is not ready before we
create bucket)
  • Loading branch information
carlcsaposs-canonical committed May 14, 2024
1 parent f86cfdf commit e7c618e
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions python/pytest_plugins/microceph/pytest_microceph/_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import logging
import os
import subprocess
import time

import boto3
import botocore.exceptions
import pytest


Expand Down Expand Up @@ -43,12 +45,22 @@ def microceph():
key_id = key["access_key"]
secret_key = key["secret_key"]
logger.info("Creating microceph bucket")
boto3.client(
"s3",
endpoint_url="http://localhost",
aws_access_key_id=key_id,
aws_secret_access_key=secret_key,
).create_bucket(Bucket=_BUCKET)
for attempt in range(3):
try:
boto3.client(
"s3",
endpoint_url="http://localhost",
aws_access_key_id=key_id,
aws_secret_access_key=secret_key,
).create_bucket(Bucket=_BUCKET)
except botocore.exceptions.EndpointConnectionError:
if attempt == 2:
raise
# microceph is not ready yet
logger.info("Unable to connect to microceph via S3. Retrying")
time.sleep(1)
else:
break
logger.info("Set up microceph")
return ConnectionInformation(key_id, secret_key, _BUCKET)

Expand Down

0 comments on commit e7c618e

Please sign in to comment.