Skip to content

Commit

Permalink
infra: change check for s3 bucket exists (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
avawang1 authored Oct 5, 2020
1 parent 71434b2 commit 9bc5f50
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions test/integ_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import boto3
import pytest
from botocore.exceptions import ClientError

from braket.aws.aws_session import AwsSession

Expand All @@ -36,15 +37,32 @@ def s3_resource(boto_session):


@pytest.fixture(scope="session")
def s3_bucket(s3_resource, boto_session):
def s3_client(boto_session):
return boto_session.client("s3")


@pytest.fixture(scope="session")
def account_id(boto_session):
return boto_session.client("sts").get_caller_identity()["Account"]


@pytest.fixture(scope="session")
def s3_bucket(s3_resource, s3_client, account_id, boto_session):
"""Create / get S3 bucket for tests"""

region_name = boto_session.region_name
account_id = boto_session.client("sts").get_caller_identity()["Account"]
bucket_name = f"amazon-braket-sdk-integ-tests-{account_id}"
bucket_name = f"amazon-braket-ocean-plugin-integ-tests-{account_id}"
bucket = s3_resource.Bucket(bucket_name)
if not bucket.creation_date:
bucket.create(ACL="private", CreateBucketConfiguration={"LocationConstraint": region_name})

try:
# Determine if bucket exists
s3_client.head_bucket(Bucket=bucket_name)
except ClientError as e:
error_code = e.response["Error"]["Code"]
if error_code == "404":
bucket.create(
ACL="private", CreateBucketConfiguration={"LocationConstraint": region_name}
)

return bucket_name

Expand Down

0 comments on commit 9bc5f50

Please sign in to comment.