Skip to content

Commit

Permalink
Merge pull request #355 from shaon/master_wait_for_bucket
Browse files Browse the repository at this point in the history
added wait_for_result poll for create/delete bucket
  • Loading branch information
shaon committed Jul 31, 2015
2 parents ca6f663 + 4ee520e commit 2a69234
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions eucaops/s3ops.py
Expand Up @@ -112,7 +112,7 @@ def get_s3_path(self):
s3_path = "/".join(s3_url.split("/")[3:])
return s3_path

def create_bucket(self,bucket_name):
def create_bucket(self, bucket_name):
"""
Create a bucket. If the bucket already exists and you have
access to it, no error will be returned by AWS.
Expand All @@ -124,18 +124,24 @@ def create_bucket(self,bucket_name):
# bucket exists and we have access to it or None.
bucket = self.get_bucket_by_name(bucket_name)
if bucket:
self.debug( 'Bucket (%s) already exists' % bucket_name )
self.debug('Bucket (%s) already exists' % bucket_name)
else:
# Let's try to create the bucket. This will fail if
# the bucket has already been created by someone else.
try:
bucket = self.s3.create_bucket(bucket_name)
except self.s3.provider.storage_create_error, e:
raise S3opsException( 'Bucket (%s) is owned by another user' % bucket_name )
if not self.get_bucket_by_name(bucket.name):
raise S3opsException("Bucket could not be found after creation")
raise S3opsException('Bucket (%s) is owned by another user' % bucket_name)

def does_bucket_exist():
try:
self.s3.get_bucket(bucket_name)
return True
except S3ResponseError:
return False
self.wait_for_result(does_bucket_exist, True, timeout=120, poll_wait=5)
self.debug("Created bucket: " + bucket_name)
self.test_resources["buckets"].append(bucket)
self.debug("Created bucket: " + bucket_name)
return bucket

def delete_bucket(self, bucket):
Expand All @@ -152,8 +158,14 @@ def delete_bucket(self, bucket):
except self.s3.provider.storage_create_error, e:
raise S3opsException( 'Bucket (%s) is owned by another user' % bucket_name )
### Check if the bucket still exists
if self.get_bucket_by_name(bucket_name):
raise S3opsException('Bucket (%s) still exists after delete operation' % bucket_name )

def does_bucket_exist():
try:
self.s3.get_bucket(bucket_name)
return True
except S3ResponseError:
return False
self.wait_for_result(does_bucket_exist, False, timeout=120, poll_wait=5)

def get_bucket_by_name(self, bucket_name):
"""
Expand Down Expand Up @@ -564,6 +576,4 @@ def show_buckets(self, buckets=None, format_size=True, printme=True):
if printme:
self.debug("\n{0}\n".format(str(main_table)))
else:
return main_table


return main_table

0 comments on commit 2a69234

Please sign in to comment.