Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functions for checkout service #6

Merged
merged 15 commits into from
Nov 17, 2017
Merged

Functions for checkout service #6

merged 15 commits into from
Nov 17, 2017

Conversation

amork
Copy link
Contributor

@amork amork commented Nov 16, 2017

New functions to support checkout service requirements:

  1. check for an existence of a bucket in S3
  2. get region associated with a bucket

Testing
Added 2 new unit tests for TEST and Fixture buckets

TODO:
Implement Google version of these functions Issue

"""
Checks if bucket with specified name exists.
:param bucket: the bucket to be checked.
:return: true if specified bucket exists in the AZ.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AZ?

"""
exists = True
try:
self.s3.meta.client.head_bucket(Bucket=bucket)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just self.s3_client.head_bucket(Bucket=bucket)?

@@ -277,3 +278,30 @@ def find_next_missing_parts(
if parts_resp['IsTruncated'] and search_start == parts_resp['NextPartNumberMarker']:
# finished examining the results of this batch, move onto the next one
break

def check_bucket_exists(self, bucket: str) -> bool:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a bit of a misnomer. This tests if the bucket is accessible, not if it exists.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if bucket is not accessible I'm also checking the error code.
If it was a 404 error, then the bucket does not exist.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah you are right. I misread the documentation!

Thanks!

"""
Get region associated with a specified bucket name.
:param bucket: the bucket to be checked.
:return: region, Note that underying AWS API returns None for default US-East-1,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/underying/underlying/

Ensure that the ``check_bucket_exists`` method returns true for FIXTURE AND TEST buckets.
"""
handle = self.handle # type: BlobStore
self.assertEqual(handle.check_bucket_exists(self.test_fixtures_bucket), True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There needs to be a negative test as well.

Ensure that the ``get_bucket_region`` method returns true for FIXTURE and TEST buckets.
"""
handle = self.handle # type: BlobStore
self.assertEqual(handle.get_bucket_region(self.test_fixtures_bucket), 'us-east-1')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There needs to be a non-us-east-1 test as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great idea, do you have any recommendations as far as buckets available in the context of the test?

"""
Checks if bucket with specified name exists.
:param bucket: the bucket to be checked.
:return: true if specified bucket exists in the AZ.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AZ?

"""
Get region associated with a specified bucket name.
:param bucket: the bucket to be checked.
:return: region, Note that underying AWS API returns None for default US-East-1,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not belong here.

@amork amork merged commit d4b2e2d into master Nov 17, 2017
@amork amork deleted the rkisin-checkout-functions branch November 17, 2017 00:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants