Merge "Made internal client handle failed requests better"
This commit is contained in:
commit
89d4a51359
@ -186,7 +186,7 @@ class InternalClient(object):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
resp = self.make_request('HEAD', path, {}, acceptable_statuses)
|
resp = self.make_request('HEAD', path, {}, acceptable_statuses)
|
||||||
if resp.status_int // 100 != 2:
|
if not resp.status_int // 100 == 2:
|
||||||
return {}
|
return {}
|
||||||
metadata_prefix = metadata_prefix.lower()
|
metadata_prefix = metadata_prefix.lower()
|
||||||
metadata = {}
|
metadata = {}
|
||||||
@ -223,7 +223,7 @@ class InternalClient(object):
|
|||||||
'GET', '%s?format=json&marker=%s&end_marker=%s' %
|
'GET', '%s?format=json&marker=%s&end_marker=%s' %
|
||||||
(path, quote(marker), quote(end_marker)),
|
(path, quote(marker), quote(end_marker)),
|
||||||
{}, acceptable_statuses)
|
{}, acceptable_statuses)
|
||||||
if resp.status_int != 200:
|
if not resp.status_int == 200:
|
||||||
break
|
break
|
||||||
data = json.loads(resp.body)
|
data = json.loads(resp.body)
|
||||||
if not data:
|
if not data:
|
||||||
@ -334,6 +334,8 @@ class InternalClient(object):
|
|||||||
|
|
||||||
path = self.make_path(account)
|
path = self.make_path(account)
|
||||||
resp = self.make_request('HEAD', path, {}, acceptable_statuses)
|
resp = self.make_request('HEAD', path, {}, acceptable_statuses)
|
||||||
|
if not resp.status_int // 100 == 2:
|
||||||
|
return (0, 0)
|
||||||
return (int(resp.headers.get('x-account-container-count', 0)),
|
return (int(resp.headers.get('x-account-container-count', 0)),
|
||||||
int(resp.headers.get('x-account-object-count', 0)))
|
int(resp.headers.get('x-account-object-count', 0)))
|
||||||
|
|
||||||
@ -406,7 +408,7 @@ class InternalClient(object):
|
|||||||
|
|
||||||
path = self.make_path(account, container)
|
path = self.make_path(account, container)
|
||||||
resp = self.make_request('HEAD', path, {}, (2, HTTP_NOT_FOUND))
|
resp = self.make_request('HEAD', path, {}, (2, HTTP_NOT_FOUND))
|
||||||
return resp.status_int != HTTP_NOT_FOUND
|
return not resp.status_int == HTTP_NOT_FOUND
|
||||||
|
|
||||||
def create_container(
|
def create_container(
|
||||||
self, account, container, headers=None, acceptable_statuses=(2,)):
|
self, account, container, headers=None, acceptable_statuses=(2,)):
|
||||||
@ -596,8 +598,9 @@ class InternalClient(object):
|
|||||||
|
|
||||||
headers = headers or {}
|
headers = headers or {}
|
||||||
path = self.make_path(account, container, obj)
|
path = self.make_path(account, container, obj)
|
||||||
|
|
||||||
resp = self.make_request('GET', path, headers, acceptable_statuses)
|
resp = self.make_request('GET', path, headers, acceptable_statuses)
|
||||||
|
if not resp.status_int // 100 == 2:
|
||||||
|
return
|
||||||
|
|
||||||
last_part = ''
|
last_part = ''
|
||||||
compressed = obj.endswith('.gz')
|
compressed = obj.endswith('.gz')
|
||||||
|
@ -559,6 +559,7 @@ class TestInternalClient(unittest.TestCase):
|
|||||||
'x-account-container-count': containers,
|
'x-account-container-count': containers,
|
||||||
'x-account-object-count': objects,
|
'x-account-object-count': objects,
|
||||||
}
|
}
|
||||||
|
self.status_int = 200
|
||||||
|
|
||||||
class InternalClient(internal_client.InternalClient):
|
class InternalClient(internal_client.InternalClient):
|
||||||
def __init__(self, test, path, resp):
|
def __init__(self, test, path, resp):
|
||||||
@ -583,6 +584,29 @@ class TestInternalClient(unittest.TestCase):
|
|||||||
info = client.get_account_info(account)
|
info = client.get_account_info(account)
|
||||||
self.assertEquals((containers, objects), info)
|
self.assertEquals((containers, objects), info)
|
||||||
|
|
||||||
|
def test_get_account_info_404(self):
|
||||||
|
class Response(object):
|
||||||
|
def __init__(self):
|
||||||
|
self.headers = {
|
||||||
|
'x-account-container-count': 10,
|
||||||
|
'x-account-object-count': 100,
|
||||||
|
}
|
||||||
|
self.status_int = 404
|
||||||
|
|
||||||
|
class InternalClient(internal_client.InternalClient):
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def make_path(self, *a, **kw):
|
||||||
|
return 'some_path'
|
||||||
|
|
||||||
|
def make_request(self, *a, **kw):
|
||||||
|
return Response()
|
||||||
|
|
||||||
|
client = InternalClient()
|
||||||
|
info = client.get_account_info('some_account')
|
||||||
|
self.assertEquals((0, 0), info)
|
||||||
|
|
||||||
def test_get_account_metadata(self):
|
def test_get_account_metadata(self):
|
||||||
account, container, obj = path_parts()
|
account, container, obj = path_parts()
|
||||||
path = make_path(account)
|
path = make_path(account)
|
||||||
@ -805,6 +829,25 @@ class TestInternalClient(unittest.TestCase):
|
|||||||
ret_lines.append(line)
|
ret_lines.append(line)
|
||||||
self.assertEquals(lines, ret_lines)
|
self.assertEquals(lines, ret_lines)
|
||||||
|
|
||||||
|
def test_iter_object_lines_404(self):
|
||||||
|
class InternalClient(internal_client.InternalClient):
|
||||||
|
def __init__(self):
|
||||||
|
self.app = self.fake_app
|
||||||
|
self.user_agent = 'some_agent'
|
||||||
|
self.request_tries = 3
|
||||||
|
|
||||||
|
def fake_app(self, env, start_response):
|
||||||
|
start_response('404 Not Found', [])
|
||||||
|
return ['one\ntwo\nthree']
|
||||||
|
|
||||||
|
client = InternalClient()
|
||||||
|
lines = []
|
||||||
|
for line in client.iter_object_lines(
|
||||||
|
'some_account', 'some_container', 'some_object',
|
||||||
|
acceptable_statuses=(2, 404)):
|
||||||
|
lines.append(line)
|
||||||
|
self.assertEquals([], lines)
|
||||||
|
|
||||||
def test_set_object_metadata(self):
|
def test_set_object_metadata(self):
|
||||||
account, container, obj = path_parts()
|
account, container, obj = path_parts()
|
||||||
path = make_path(account, container, obj)
|
path = make_path(account, container, obj)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user