Enable reset to retry up to RETRAY_COUNT

Current reset on Connection class in the functional test would
give up just once when a request fails with something like as
ResponseError. This patch enable the reset method to retry up to
RETRAY_COUNT.

Change-Id: I853a5b8c8fefe1000b8cb88cdace59ed94e8583e
This commit is contained in:
Kota Tsuyuzaki
2015-03-09 15:42:50 -07:00
parent 4db166333e
commit c2e5dc8c9f

View File

@@ -14,7 +14,8 @@
# limitations under the License. # limitations under the License.
import os import os
from boto.s3.connection import S3Connection, OrdinaryCallingFormat from boto.s3.connection import S3Connection, OrdinaryCallingFormat, \
BotoClientError, S3ResponseError
from swift3.response import NoSuchKey, NoSuchBucket from swift3.response import NoSuchKey, NoSuchBucket
RETRY_COUNT = 3 RETRY_COUNT = 3
@@ -40,20 +41,27 @@ class Connection(object):
calling_format=OrdinaryCallingFormat()) calling_format=OrdinaryCallingFormat())
def reset(self): def reset(self):
exceptions = []
for i in range(RETRY_COUNT): for i in range(RETRY_COUNT):
buckets = self.conn.get_all_buckets() try:
if not buckets: buckets = self.conn.get_all_buckets()
break if not buckets:
for bucket in buckets: break
for obj in bucket.list(): for bucket in buckets:
for obj in bucket.list():
try:
bucket.delete_key(obj.name)
except NoSuchKey:
pass
try: try:
bucket.delete_key(obj.name) self.conn.delete_bucket(bucket.name)
except (NoSuchKey): except NoSuchBucket:
pass pass
try: except (BotoClientError, S3ResponseError) as e:
self.conn.delete_bucket(bucket.name) exceptions.append(e)
except (NoSuchBucket): if exceptions:
pass # raise the first exception
raise exceptions.pop(0)
def make_request(self, method, bucket='', obj='', headers=None, body='', def make_request(self, method, bucket='', obj='', headers=None, body='',
query=None): query=None):