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,7 +41,9 @@ 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):
try:
buckets = self.conn.get_all_buckets() buckets = self.conn.get_all_buckets()
if not buckets: if not buckets:
break break
@@ -48,12 +51,17 @@ class Connection(object):
for obj in bucket.list(): for obj in bucket.list():
try: try:
bucket.delete_key(obj.name) bucket.delete_key(obj.name)
except (NoSuchKey): except NoSuchKey:
pass pass
try: try:
self.conn.delete_bucket(bucket.name) self.conn.delete_bucket(bucket.name)
except (NoSuchBucket): except NoSuchBucket:
pass pass
except (BotoClientError, S3ResponseError) as e:
exceptions.append(e)
if exceptions:
# 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):