Skip to content

[Bug]: Openshift setup needs updating. #21

@SamuelDBines

Description

@SamuelDBines

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

This behaviour is wrong as buckets after a failed will error because of the raise on line 67

for b in buckets:
try:
response = cos.create_bucket(
Bucket=f"{deployment_name}-{b}",
)
if response["ResponseMetadata"]["HTTPStatusCode"] == 200:
print(f"Bucket {deployment_name}-{b} created successfully \u2714")
else:
print(f"Potential error creating bucket {deployment_name}-{b} please check")
except:
print(f"Bucket {deployment_name}-{b} already exists or could not be created")
raise

Expected Behavior

Should check if bucket exists. If an error occurs then whole script should cancel out.

def bucket_exists(bucket_name: str):
    try: 
        cos.head_bucket(Bucket=bucket_name)
        return True
    except:
        print(f"Bucket does not exist: {bucket_name}")
        return False

bucket_errors = []
for b in buckets:
    bucket_name: str = f"{deployment_name}-{b}"
    try:
        # This takes longer due to IO but ensures errors are not because of existing buckets
        if bucket_exists(bucket_name=bucket_name):
            continue
        response = cos.create_bucket(
            Bucket=bucket_name,
        )
        if response["ResponseMetadata"]["HTTPStatusCode"] == 200:
            print(f"Bucket {bucket_name} created successfully \u2714")
        else:
            print(f"Potential error creating bucket {bucket_name} please check")
    except Exception as err:
        print(f"Bucket {bucket_name} already exists or could not be created")
        bucket_error = {
            'bucket': bucket_name,
            'err': err,
        }
        bucket_errors.append(bucket_error)
        # Raisng here will just cause it to break out the try catch and skip buckets after.
        # raise 

if len(bucket_errors) > 0:
    print("Warning: some buckets may have not been setup correctly causing problems with the deployment.")
    for b in bucket_errors:
        print(f"{b.bucket} - {b.err}")

Steps To Reproduce

No response

Environment

- mac m1
- python3

Anything else?

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions