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.
import os
from boto.s3.connection import S3Connection, OrdinaryCallingFormat
from boto.s3.connection import S3Connection, OrdinaryCallingFormat, \
BotoClientError, S3ResponseError
from swift3.response import NoSuchKey, NoSuchBucket
RETRY_COUNT = 3
@@ -40,20 +41,27 @@ class Connection(object):
calling_format=OrdinaryCallingFormat())
def reset(self):
exceptions = []
for i in range(RETRY_COUNT):
buckets = self.conn.get_all_buckets()
if not buckets:
break
for bucket in buckets:
for obj in bucket.list():
try:
buckets = self.conn.get_all_buckets()
if not buckets:
break
for bucket in buckets:
for obj in bucket.list():
try:
bucket.delete_key(obj.name)
except NoSuchKey:
pass
try:
bucket.delete_key(obj.name)
except (NoSuchKey):
self.conn.delete_bucket(bucket.name)
except NoSuchBucket:
pass
try:
self.conn.delete_bucket(bucket.name)
except (NoSuchBucket):
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='',
query=None):