Pep8 account and proxy server unit tests (10 of 12)

Change-Id: Ib83d164997b0d98be921c8b4857caa2429344aa4
Signed-off-by: Peter Portante <peter.portante@redhat.com>
This commit is contained in:
Peter Portante 2013-09-01 01:54:03 -04:00
parent 1d9213bed4
commit 6ae4e17af1
2 changed files with 224 additions and 170 deletions

View File

@ -32,7 +32,8 @@ class TestAccountController(unittest.TestCase):
"""Test swift.account.server.AccountController""" """Test swift.account.server.AccountController"""
def setUp(self): def setUp(self):
"""Set up for testing swift.account.server.AccountController""" """Set up for testing swift.account.server.AccountController"""
self.testdir = os.path.join(os.path.dirname(__file__), 'account_server') self.testdir = os.path.join(os.path.dirname(__file__),
'account_server')
self.controller = AccountController( self.controller = AccountController(
{'devices': self.testdir, 'mount_check': 'false'}) {'devices': self.testdir, 'mount_check': 'false'})
@ -89,7 +90,8 @@ class TestAccountController(unittest.TestCase):
'X-Bytes-Used': '0', 'X-Bytes-Used': '0',
'X-Timestamp': normalize_timestamp(0)}) 'X-Timestamp': normalize_timestamp(0)})
req.get_response(self.controller) req.get_response(self.controller)
req = Request.blank('/sda1/p/a/c1', req = Request.blank(
'/sda1/p/a/c1',
environ={'REQUEST_METHOD': 'PUT'}, environ={'REQUEST_METHOD': 'PUT'},
headers={'X-Put-Timestamp': '1', headers={'X-Put-Timestamp': '1',
'X-Delete-Timestamp': '2', 'X-Delete-Timestamp': '2',
@ -121,7 +123,8 @@ class TestAccountController(unittest.TestCase):
def test_DELETE_insufficient_storage(self): def test_DELETE_insufficient_storage(self):
self.controller = AccountController({'devices': self.testdir}) self.controller = AccountController({'devices': self.testdir})
req = Request.blank('/sda-null/p/a', environ={'REQUEST_METHOD': 'DELETE', req = Request.blank(
'/sda-null/p/a', environ={'REQUEST_METHOD': 'DELETE',
'HTTP_X_TIMESTAMP': '1'}) 'HTTP_X_TIMESTAMP': '1'})
resp = req.get_response(self.controller) resp = req.get_response(self.controller)
self.assertEquals(resp.status_int, 507) self.assertEquals(resp.status_int, 507)
@ -235,7 +238,8 @@ class TestAccountController(unittest.TestCase):
self.assertEquals(resp.status_int, 400) self.assertEquals(resp.status_int, 400)
def test_PUT_not_found(self): def test_PUT_not_found(self):
req = Request.blank('/sda1/p/a/c', environ={'REQUEST_METHOD': 'PUT'}, req = Request.blank(
'/sda1/p/a/c', environ={'REQUEST_METHOD': 'PUT'},
headers={'X-PUT-Timestamp': normalize_timestamp(1), headers={'X-PUT-Timestamp': normalize_timestamp(1),
'X-DELETE-Timestamp': normalize_timestamp(0), 'X-DELETE-Timestamp': normalize_timestamp(0),
'X-Object-Count': '1', 'X-Object-Count': '1',
@ -273,7 +277,8 @@ class TestAccountController(unittest.TestCase):
def test_PUT_GET_metadata(self): def test_PUT_GET_metadata(self):
# Set metadata header # Set metadata header
req = Request.blank('/sda1/p/a', environ={'REQUEST_METHOD': 'PUT'}, req = Request.blank(
'/sda1/p/a', environ={'REQUEST_METHOD': 'PUT'},
headers={'X-Timestamp': normalize_timestamp(1), headers={'X-Timestamp': normalize_timestamp(1),
'X-Account-Meta-Test': 'Value'}) 'X-Account-Meta-Test': 'Value'})
resp = req.get_response(self.controller) resp = req.get_response(self.controller)
@ -283,7 +288,8 @@ class TestAccountController(unittest.TestCase):
self.assertEquals(resp.status_int, 204) self.assertEquals(resp.status_int, 204)
self.assertEquals(resp.headers.get('x-account-meta-test'), 'Value') self.assertEquals(resp.headers.get('x-account-meta-test'), 'Value')
# Set another metadata header, ensuring old one doesn't disappear # Set another metadata header, ensuring old one doesn't disappear
req = Request.blank('/sda1/p/a', environ={'REQUEST_METHOD': 'POST'}, req = Request.blank(
'/sda1/p/a', environ={'REQUEST_METHOD': 'POST'},
headers={'X-Timestamp': normalize_timestamp(1), headers={'X-Timestamp': normalize_timestamp(1),
'X-Account-Meta-Test2': 'Value2'}) 'X-Account-Meta-Test2': 'Value2'})
resp = req.get_response(self.controller) resp = req.get_response(self.controller)
@ -294,7 +300,8 @@ class TestAccountController(unittest.TestCase):
self.assertEquals(resp.headers.get('x-account-meta-test'), 'Value') self.assertEquals(resp.headers.get('x-account-meta-test'), 'Value')
self.assertEquals(resp.headers.get('x-account-meta-test2'), 'Value2') self.assertEquals(resp.headers.get('x-account-meta-test2'), 'Value2')
# Update metadata header # Update metadata header
req = Request.blank('/sda1/p/a', environ={'REQUEST_METHOD': 'PUT'}, req = Request.blank(
'/sda1/p/a', environ={'REQUEST_METHOD': 'PUT'},
headers={'X-Timestamp': normalize_timestamp(3), headers={'X-Timestamp': normalize_timestamp(3),
'X-Account-Meta-Test': 'New Value'}) 'X-Account-Meta-Test': 'New Value'})
resp = req.get_response(self.controller) resp = req.get_response(self.controller)
@ -304,7 +311,8 @@ class TestAccountController(unittest.TestCase):
self.assertEquals(resp.status_int, 204) self.assertEquals(resp.status_int, 204)
self.assertEquals(resp.headers.get('x-account-meta-test'), 'New Value') self.assertEquals(resp.headers.get('x-account-meta-test'), 'New Value')
# Send old update to metadata header # Send old update to metadata header
req = Request.blank('/sda1/p/a', environ={'REQUEST_METHOD': 'PUT'}, req = Request.blank(
'/sda1/p/a', environ={'REQUEST_METHOD': 'PUT'},
headers={'X-Timestamp': normalize_timestamp(2), headers={'X-Timestamp': normalize_timestamp(2),
'X-Account-Meta-Test': 'Old Value'}) 'X-Account-Meta-Test': 'Old Value'})
resp = req.get_response(self.controller) resp = req.get_response(self.controller)
@ -314,7 +322,8 @@ class TestAccountController(unittest.TestCase):
self.assertEquals(resp.status_int, 204) self.assertEquals(resp.status_int, 204)
self.assertEquals(resp.headers.get('x-account-meta-test'), 'New Value') self.assertEquals(resp.headers.get('x-account-meta-test'), 'New Value')
# Remove metadata header (by setting it to empty) # Remove metadata header (by setting it to empty)
req = Request.blank('/sda1/p/a', environ={'REQUEST_METHOD': 'PUT'}, req = Request.blank(
'/sda1/p/a', environ={'REQUEST_METHOD': 'PUT'},
headers={'X-Timestamp': normalize_timestamp(4), headers={'X-Timestamp': normalize_timestamp(4),
'X-Account-Meta-Test': ''}) 'X-Account-Meta-Test': ''})
resp = req.get_response(self.controller) resp = req.get_response(self.controller)
@ -338,12 +347,14 @@ class TestAccountController(unittest.TestCase):
self.assertEquals(resp.status_int, 507) self.assertEquals(resp.status_int, 507)
def test_POST_HEAD_metadata(self): def test_POST_HEAD_metadata(self):
req = Request.blank('/sda1/p/a', environ={'REQUEST_METHOD': 'PUT'}, req = Request.blank(
'/sda1/p/a', environ={'REQUEST_METHOD': 'PUT'},
headers={'X-Timestamp': normalize_timestamp(1)}) headers={'X-Timestamp': normalize_timestamp(1)})
resp = req.get_response(self.controller) resp = req.get_response(self.controller)
self.assertEquals(resp.status_int, 201) self.assertEquals(resp.status_int, 201)
# Set metadata header # Set metadata header
req = Request.blank('/sda1/p/a', environ={'REQUEST_METHOD': 'POST'}, req = Request.blank(
'/sda1/p/a', environ={'REQUEST_METHOD': 'POST'},
headers={'X-Timestamp': normalize_timestamp(1), headers={'X-Timestamp': normalize_timestamp(1),
'X-Account-Meta-Test': 'Value'}) 'X-Account-Meta-Test': 'Value'})
resp = req.get_response(self.controller) resp = req.get_response(self.controller)
@ -353,7 +364,8 @@ class TestAccountController(unittest.TestCase):
self.assertEquals(resp.status_int, 204) self.assertEquals(resp.status_int, 204)
self.assertEquals(resp.headers.get('x-account-meta-test'), 'Value') self.assertEquals(resp.headers.get('x-account-meta-test'), 'Value')
# Update metadata header # Update metadata header
req = Request.blank('/sda1/p/a', environ={'REQUEST_METHOD': 'POST'}, req = Request.blank(
'/sda1/p/a', environ={'REQUEST_METHOD': 'POST'},
headers={'X-Timestamp': normalize_timestamp(3), headers={'X-Timestamp': normalize_timestamp(3),
'X-Account-Meta-Test': 'New Value'}) 'X-Account-Meta-Test': 'New Value'})
resp = req.get_response(self.controller) resp = req.get_response(self.controller)
@ -363,7 +375,8 @@ class TestAccountController(unittest.TestCase):
self.assertEquals(resp.status_int, 204) self.assertEquals(resp.status_int, 204)
self.assertEquals(resp.headers.get('x-account-meta-test'), 'New Value') self.assertEquals(resp.headers.get('x-account-meta-test'), 'New Value')
# Send old update to metadata header # Send old update to metadata header
req = Request.blank('/sda1/p/a', environ={'REQUEST_METHOD': 'POST'}, req = Request.blank(
'/sda1/p/a', environ={'REQUEST_METHOD': 'POST'},
headers={'X-Timestamp': normalize_timestamp(2), headers={'X-Timestamp': normalize_timestamp(2),
'X-Account-Meta-Test': 'Old Value'}) 'X-Account-Meta-Test': 'Old Value'})
resp = req.get_response(self.controller) resp = req.get_response(self.controller)
@ -373,7 +386,8 @@ class TestAccountController(unittest.TestCase):
self.assertEquals(resp.status_int, 204) self.assertEquals(resp.status_int, 204)
self.assertEquals(resp.headers.get('x-account-meta-test'), 'New Value') self.assertEquals(resp.headers.get('x-account-meta-test'), 'New Value')
# Remove metadata header (by setting it to empty) # Remove metadata header (by setting it to empty)
req = Request.blank('/sda1/p/a', environ={'REQUEST_METHOD': 'POST'}, req = Request.blank(
'/sda1/p/a', environ={'REQUEST_METHOD': 'POST'},
headers={'X-Timestamp': normalize_timestamp(4), headers={'X-Timestamp': normalize_timestamp(4),
'X-Account-Meta-Test': ''}) 'X-Account-Meta-Test': ''})
resp = req.get_response(self.controller) resp = req.get_response(self.controller)
@ -465,7 +479,8 @@ class TestAccountController(unittest.TestCase):
def test_GET_empty_account_json(self): def test_GET_empty_account_json(self):
req = Request.blank('/sda1/p/a?format=json', req = Request.blank('/sda1/p/a?format=json',
environ={'REQUEST_METHOD': 'PUT', 'HTTP_X_TIMESTAMP': '0'}) environ={'REQUEST_METHOD': 'PUT',
'HTTP_X_TIMESTAMP': '0'})
req.get_response(self.controller) req.get_response(self.controller)
req = Request.blank('/sda1/p/a?format=json', req = Request.blank('/sda1/p/a?format=json',
environ={'REQUEST_METHOD': 'GET'}) environ={'REQUEST_METHOD': 'GET'})
@ -476,7 +491,8 @@ class TestAccountController(unittest.TestCase):
def test_GET_empty_account_xml(self): def test_GET_empty_account_xml(self):
req = Request.blank('/sda1/p/a?format=xml', req = Request.blank('/sda1/p/a?format=xml',
environ={'REQUEST_METHOD': 'PUT', 'HTTP_X_TIMESTAMP': '0'}) environ={'REQUEST_METHOD': 'PUT',
'HTTP_X_TIMESTAMP': '0'})
req.get_response(self.controller) req.get_response(self.controller)
req = Request.blank('/sda1/p/a?format=xml', req = Request.blank('/sda1/p/a?format=xml',
environ={'REQUEST_METHOD': 'GET'}) environ={'REQUEST_METHOD': 'GET'})
@ -486,8 +502,9 @@ class TestAccountController(unittest.TestCase):
'application/xml; charset=utf-8') 'application/xml; charset=utf-8')
def test_GET_over_limit(self): def test_GET_over_limit(self):
req = Request.blank('/sda1/p/a?limit=%d' % req = Request.blank(
(ACCOUNT_LISTING_LIMIT + 1), environ={'REQUEST_METHOD': 'GET'}) '/sda1/p/a?limit=%d' % (ACCOUNT_LISTING_LIMIT + 1),
environ={'REQUEST_METHOD': 'GET'})
resp = req.get_response(self.controller) resp = req.get_response(self.controller)
self.assertEquals(resp.status_int, 412) self.assertEquals(resp.status_int, 412)
@ -675,7 +692,8 @@ class TestAccountController(unittest.TestCase):
node = [n for n in container if n.nodeName == 'bytes'][0] node = [n for n in container if n.nodeName == 'bytes'][0]
self.assertEquals(node.firstChild.nodeValue, '2') self.assertEquals(node.firstChild.nodeValue, '2')
self.assertEquals(listing[-1].nodeName, 'container') self.assertEquals(listing[-1].nodeName, 'container')
container = [n for n in listing[-1].childNodes if n.nodeName != '#text'] container = [
n for n in listing[-1].childNodes if n.nodeName != '#text']
self.assertEquals(sorted([n.nodeName for n in container]), self.assertEquals(sorted([n.nodeName for n in container]),
['bytes', 'count', 'name']) ['bytes', 'count', 'name'])
node = [n for n in container if n.nodeName == 'name'][0] node = [n for n in container if n.nodeName == 'name'][0]
@ -751,7 +769,8 @@ class TestAccountController(unittest.TestCase):
'HTTP_X_TIMESTAMP': '0'}) 'HTTP_X_TIMESTAMP': '0'})
req.get_response(self.controller) req.get_response(self.controller)
for c in xrange(5): for c in xrange(5):
req = Request.blank('/sda1/p/a/c%d' % c, req = Request.blank(
'/sda1/p/a/c%d' % c,
environ={'REQUEST_METHOD': 'PUT'}, environ={'REQUEST_METHOD': 'PUT'},
headers={'X-Put-Timestamp': str(c + 1), headers={'X-Put-Timestamp': str(c + 1),
'X-Delete-Timestamp': '0', 'X-Delete-Timestamp': '0',
@ -775,7 +794,8 @@ class TestAccountController(unittest.TestCase):
'HTTP_X_TIMESTAMP': '0'}) 'HTTP_X_TIMESTAMP': '0'})
req.get_response(self.controller) req.get_response(self.controller)
for c in xrange(5): for c in xrange(5):
req = Request.blank('/sda1/p/a/c%d' % c, req = Request.blank(
'/sda1/p/a/c%d' % c,
environ={'REQUEST_METHOD': 'PUT'}, environ={'REQUEST_METHOD': 'PUT'},
headers={'X-Put-Timestamp': str(c + 1), headers={'X-Put-Timestamp': str(c + 1),
'X-Delete-Timestamp': '0', 'X-Delete-Timestamp': '0',
@ -804,7 +824,8 @@ class TestAccountController(unittest.TestCase):
'HTTP_X_TIMESTAMP': '0'}) 'HTTP_X_TIMESTAMP': '0'})
req.get_response(self.controller) req.get_response(self.controller)
for c in xrange(5): for c in xrange(5):
req = Request.blank('/sda1/p/a/c%d' % c, req = Request.blank(
'/sda1/p/a/c%d' % c,
environ={'REQUEST_METHOD': 'PUT'}, environ={'REQUEST_METHOD': 'PUT'},
headers={'X-Put-Timestamp': str(c + 1), headers={'X-Put-Timestamp': str(c + 1),
'X-Delete-Timestamp': '0', 'X-Delete-Timestamp': '0',
@ -832,7 +853,8 @@ class TestAccountController(unittest.TestCase):
node = [n for n in container if n.nodeName == 'bytes'][0] node = [n for n in container if n.nodeName == 'bytes'][0]
self.assertEquals(node.firstChild.nodeValue, '3') self.assertEquals(node.firstChild.nodeValue, '3')
self.assertEquals(listing[-1].nodeName, 'container') self.assertEquals(listing[-1].nodeName, 'container')
container = [n for n in listing[-1].childNodes if n.nodeName != '#text'] container = [
n for n in listing[-1].childNodes if n.nodeName != '#text']
self.assertEquals(sorted([n.nodeName for n in container]), self.assertEquals(sorted([n.nodeName for n in container]),
['bytes', 'count', 'name']) ['bytes', 'count', 'name'])
node = [n for n in container if n.nodeName == 'name'][0] node = [n for n in container if n.nodeName == 'name'][0]
@ -861,7 +883,8 @@ class TestAccountController(unittest.TestCase):
node = [n for n in container if n.nodeName == 'bytes'][0] node = [n for n in container if n.nodeName == 'bytes'][0]
self.assertEquals(node.firstChild.nodeValue, '3') self.assertEquals(node.firstChild.nodeValue, '3')
self.assertEquals(listing[-1].nodeName, 'container') self.assertEquals(listing[-1].nodeName, 'container')
container = [n for n in listing[-1].childNodes if n.nodeName != '#text'] container = [
n for n in listing[-1].childNodes if n.nodeName != '#text']
self.assertEquals(sorted([n.nodeName for n in container]), self.assertEquals(sorted([n.nodeName for n in container]),
['bytes', 'count', 'name']) ['bytes', 'count', 'name'])
node = [n for n in container if n.nodeName == 'name'][0] node = [n for n in container if n.nodeName == 'name'][0]
@ -989,7 +1012,8 @@ class TestAccountController(unittest.TestCase):
'HTTP_X_TIMESTAMP': '0'}) 'HTTP_X_TIMESTAMP': '0'})
resp = req.get_response(self.controller) resp = req.get_response(self.controller)
for first in range(3): for first in range(3):
req = Request.blank('/sda1/p/a/sub.%s' % first, req = Request.blank(
'/sda1/p/a/sub.%s' % first,
environ={'REQUEST_METHOD': 'PUT'}, environ={'REQUEST_METHOD': 'PUT'},
headers={'X-Put-Timestamp': '1', headers={'X-Put-Timestamp': '1',
'X-Delete-Timestamp': '0', 'X-Delete-Timestamp': '0',
@ -998,7 +1022,8 @@ class TestAccountController(unittest.TestCase):
'X-Timestamp': normalize_timestamp(0)}) 'X-Timestamp': normalize_timestamp(0)})
req.get_response(self.controller) req.get_response(self.controller)
for second in range(3): for second in range(3):
req = Request.blank('/sda1/p/a/sub.%s.%s' % (first, second), req = Request.blank(
'/sda1/p/a/sub.%s.%s' % (first, second),
environ={'REQUEST_METHOD': 'PUT'}, environ={'REQUEST_METHOD': 'PUT'},
headers={'X-Put-Timestamp': '1', headers={'X-Put-Timestamp': '1',
'X-Delete-Timestamp': '0', 'X-Delete-Timestamp': '0',
@ -1015,7 +1040,8 @@ class TestAccountController(unittest.TestCase):
environ={'REQUEST_METHOD': 'GET'}) environ={'REQUEST_METHOD': 'GET'})
resp = req.get_response(self.controller) resp = req.get_response(self.controller)
self.assertEquals(resp.status_int, 200) self.assertEquals(resp.status_int, 200)
self.assertEquals(resp.body.strip().split('\n'), self.assertEquals(
resp.body.strip().split('\n'),
['sub.0', 'sub.0.', 'sub.1', 'sub.1.', 'sub.2', 'sub.2.']) ['sub.0', 'sub.0.', 'sub.1', 'sub.1.', 'sub.2', 'sub.2.'])
req = Request.blank('/sda1/p/a?prefix=sub.1.&delimiter=.', req = Request.blank('/sda1/p/a?prefix=sub.1.&delimiter=.',
environ={'REQUEST_METHOD': 'GET'}) environ={'REQUEST_METHOD': 'GET'})
@ -1029,7 +1055,8 @@ class TestAccountController(unittest.TestCase):
'HTTP_X_TIMESTAMP': '0'}) 'HTTP_X_TIMESTAMP': '0'})
resp = req.get_response(self.controller) resp = req.get_response(self.controller)
for first in range(3): for first in range(3):
req = Request.blank('/sda1/p/a/sub.%s' % first, req = Request.blank(
'/sda1/p/a/sub.%s' % first,
environ={'REQUEST_METHOD': 'PUT'}, environ={'REQUEST_METHOD': 'PUT'},
headers={'X-Put-Timestamp': '1', headers={'X-Put-Timestamp': '1',
'X-Delete-Timestamp': '0', 'X-Delete-Timestamp': '0',
@ -1038,7 +1065,8 @@ class TestAccountController(unittest.TestCase):
'X-Timestamp': normalize_timestamp(0)}) 'X-Timestamp': normalize_timestamp(0)})
req.get_response(self.controller) req.get_response(self.controller)
for second in range(3): for second in range(3):
req = Request.blank('/sda1/p/a/sub.%s.%s' % (first, second), req = Request.blank(
'/sda1/p/a/sub.%s.%s' % (first, second),
environ={'REQUEST_METHOD': 'PUT'}, environ={'REQUEST_METHOD': 'PUT'},
headers={'X-Put-Timestamp': '1', headers={'X-Put-Timestamp': '1',
'X-Delete-Timestamp': '0', 'X-Delete-Timestamp': '0',
@ -1056,14 +1084,16 @@ class TestAccountController(unittest.TestCase):
environ={'REQUEST_METHOD': 'GET'}) environ={'REQUEST_METHOD': 'GET'})
resp = req.get_response(self.controller) resp = req.get_response(self.controller)
self.assertEquals(resp.status_int, 200) self.assertEquals(resp.status_int, 200)
self.assertEquals([n.get('name', 's:' + n.get('subdir', 'error')) self.assertEquals(
[n.get('name', 's:' + n.get('subdir', 'error'))
for n in simplejson.loads(resp.body)], for n in simplejson.loads(resp.body)],
['sub.0', 's:sub.0.', 'sub.1', 's:sub.1.', 'sub.2', 's:sub.2.']) ['sub.0', 's:sub.0.', 'sub.1', 's:sub.1.', 'sub.2', 's:sub.2.'])
req = Request.blank('/sda1/p/a?prefix=sub.1.&delimiter=.&format=json', req = Request.blank('/sda1/p/a?prefix=sub.1.&delimiter=.&format=json',
environ={'REQUEST_METHOD': 'GET'}) environ={'REQUEST_METHOD': 'GET'})
resp = req.get_response(self.controller) resp = req.get_response(self.controller)
self.assertEquals(resp.status_int, 200) self.assertEquals(resp.status_int, 200)
self.assertEquals([n.get('name', 's:' + n.get('subdir', 'error')) self.assertEquals(
[n.get('name', 's:' + n.get('subdir', 'error'))
for n in simplejson.loads(resp.body)], for n in simplejson.loads(resp.body)],
['sub.1.0', 'sub.1.1', 'sub.1.2']) ['sub.1.0', 'sub.1.1', 'sub.1.2'])
@ -1072,7 +1102,8 @@ class TestAccountController(unittest.TestCase):
'HTTP_X_TIMESTAMP': '0'}) 'HTTP_X_TIMESTAMP': '0'})
resp = req.get_response(self.controller) resp = req.get_response(self.controller)
for first in range(3): for first in range(3):
req = Request.blank('/sda1/p/a/sub.%s' % first, req = Request.blank(
'/sda1/p/a/sub.%s' % first,
environ={'REQUEST_METHOD': 'PUT'}, environ={'REQUEST_METHOD': 'PUT'},
headers={'X-Put-Timestamp': '1', headers={'X-Put-Timestamp': '1',
'X-Delete-Timestamp': '0', 'X-Delete-Timestamp': '0',
@ -1081,7 +1112,8 @@ class TestAccountController(unittest.TestCase):
'X-Timestamp': normalize_timestamp(0)}) 'X-Timestamp': normalize_timestamp(0)})
req.get_response(self.controller) req.get_response(self.controller)
for second in range(3): for second in range(3):
req = Request.blank('/sda1/p/a/sub.%s.%s' % (first, second), req = Request.blank(
'/sda1/p/a/sub.%s.%s' % (first, second),
environ={'REQUEST_METHOD': 'PUT'}, environ={'REQUEST_METHOD': 'PUT'},
headers={'X-Put-Timestamp': '1', headers={'X-Put-Timestamp': '1',
'X-Delete-Timestamp': '0', 'X-Delete-Timestamp': '0',
@ -1089,7 +1121,8 @@ class TestAccountController(unittest.TestCase):
'X-Bytes-Used': '0', 'X-Bytes-Used': '0',
'X-Timestamp': normalize_timestamp(0)}) 'X-Timestamp': normalize_timestamp(0)})
req.get_response(self.controller) req.get_response(self.controller)
req = Request.blank('/sda1/p/a?delimiter=.&format=xml', req = Request.blank(
'/sda1/p/a?delimiter=.&format=xml',
environ={'REQUEST_METHOD': 'GET'}) environ={'REQUEST_METHOD': 'GET'})
resp = req.get_response(self.controller) resp = req.get_response(self.controller)
self.assertEquals(resp.status_int, 200) self.assertEquals(resp.status_int, 200)
@ -1103,7 +1136,8 @@ class TestAccountController(unittest.TestCase):
if node2.nodeName == 'name': if node2.nodeName == 'name':
listing.append(node2.firstChild.nodeValue) listing.append(node2.firstChild.nodeValue)
self.assertEquals(listing, ['s:sub.']) self.assertEquals(listing, ['s:sub.'])
req = Request.blank('/sda1/p/a?prefix=sub.&delimiter=.&format=xml', req = Request.blank(
'/sda1/p/a?prefix=sub.&delimiter=.&format=xml',
environ={'REQUEST_METHOD': 'GET'}) environ={'REQUEST_METHOD': 'GET'})
resp = req.get_response(self.controller) resp = req.get_response(self.controller)
self.assertEquals(resp.status_int, 200) self.assertEquals(resp.status_int, 200)
@ -1116,9 +1150,11 @@ class TestAccountController(unittest.TestCase):
for node2 in node1.childNodes: for node2 in node1.childNodes:
if node2.nodeName == 'name': if node2.nodeName == 'name':
listing.append(node2.firstChild.nodeValue) listing.append(node2.firstChild.nodeValue)
self.assertEquals(listing, self.assertEquals(
listing,
['sub.0', 's:sub.0.', 'sub.1', 's:sub.1.', 'sub.2', 's:sub.2.']) ['sub.0', 's:sub.0.', 'sub.1', 's:sub.1.', 'sub.2', 's:sub.2.'])
req = Request.blank('/sda1/p/a?prefix=sub.1.&delimiter=.&format=xml', req = Request.blank(
'/sda1/p/a?prefix=sub.1.&delimiter=.&format=xml',
environ={'REQUEST_METHOD': 'GET'}) environ={'REQUEST_METHOD': 'GET'})
resp = req.get_response(self.controller) resp = req.get_response(self.controller)
self.assertEquals(resp.status_int, 200) self.assertEquals(resp.status_int, 200)
@ -1369,7 +1405,8 @@ class TestAccountController(unittest.TestCase):
errbuf = StringIO() errbuf = StringIO()
outbuf = StringIO() outbuf = StringIO()
self.controller = AccountController( self.controller = AccountController(
{'devices': self.testdir, 'mount_check': 'false', {'devices': self.testdir,
'mount_check': 'false',
'replication_server': 'false'}) 'replication_server': 'false'})
def start_response(*args): def start_response(*args):

View File

@ -107,24 +107,24 @@ def setup():
obj2lis = listen(('localhost', 0)) obj2lis = listen(('localhost', 0))
_test_sockets = \ _test_sockets = \
(prolis, acc1lis, acc2lis, con1lis, con2lis, obj1lis, obj2lis) (prolis, acc1lis, acc2lis, con1lis, con2lis, obj1lis, obj2lis)
with closing(GzipFile(os.path.join(_testdir, 'account.ring.gz'), 'wb')) \ account_ring_path = os.path.join(_testdir, 'account.ring.gz')
as f: with closing(GzipFile(account_ring_path, 'wb')) as f:
pickle.dump(ring.RingData([[0, 1, 0, 1], [1, 0, 1, 0]], pickle.dump(ring.RingData([[0, 1, 0, 1], [1, 0, 1, 0]],
[{'id': 0, 'zone': 0, 'device': 'sda1', 'ip': '127.0.0.1', [{'id': 0, 'zone': 0, 'device': 'sda1', 'ip': '127.0.0.1',
'port': acc1lis.getsockname()[1]}, 'port': acc1lis.getsockname()[1]},
{'id': 1, 'zone': 1, 'device': 'sdb1', 'ip': '127.0.0.1', {'id': 1, 'zone': 1, 'device': 'sdb1', 'ip': '127.0.0.1',
'port': acc2lis.getsockname()[1]}], 30), 'port': acc2lis.getsockname()[1]}], 30),
f) f)
with closing(GzipFile(os.path.join(_testdir, 'container.ring.gz'), 'wb')) \ container_ring_path = os.path.join(_testdir, 'container.ring.gz')
as f: with closing(GzipFile(container_ring_path, 'wb')) as f:
pickle.dump(ring.RingData([[0, 1, 0, 1], [1, 0, 1, 0]], pickle.dump(ring.RingData([[0, 1, 0, 1], [1, 0, 1, 0]],
[{'id': 0, 'zone': 0, 'device': 'sda1', 'ip': '127.0.0.1', [{'id': 0, 'zone': 0, 'device': 'sda1', 'ip': '127.0.0.1',
'port': con1lis.getsockname()[1]}, 'port': con1lis.getsockname()[1]},
{'id': 1, 'zone': 1, 'device': 'sdb1', 'ip': '127.0.0.1', {'id': 1, 'zone': 1, 'device': 'sdb1', 'ip': '127.0.0.1',
'port': con2lis.getsockname()[1]}], 30), 'port': con2lis.getsockname()[1]}], 30),
f) f)
with closing(GzipFile(os.path.join(_testdir, 'object.ring.gz'), 'wb')) \ object_ring_path = os.path.join(_testdir, 'object.ring.gz')
as f: with closing(GzipFile(object_ring_path, 'wb')) as f:
pickle.dump(ring.RingData([[0, 1, 0, 1], [1, 0, 1, 0]], pickle.dump(ring.RingData([[0, 1, 0, 1], [1, 0, 1, 0]],
[{'id': 0, 'zone': 0, 'device': 'sda1', 'ip': '127.0.0.1', [{'id': 0, 'zone': 0, 'device': 'sda1', 'ip': '127.0.0.1',
'port': obj1lis.getsockname()[1]}, 'port': obj1lis.getsockname()[1]},
@ -171,7 +171,8 @@ def setup():
fd.flush() fd.flush()
headers = readuntil2crlfs(fd) headers = readuntil2crlfs(fd)
exp = 'HTTP/1.1 201' exp = 'HTTP/1.1 201'
assert headers[:len(exp)] == exp, "Expected '%s', encountered '%s'" % (exp, headers[:len(exp)]) assert headers[:len(exp)] == exp, "Expected '%s', encountered '%s'" % (
exp, headers[:len(exp)])
def teardown(): def teardown():
@ -457,7 +458,7 @@ class TestController(unittest.TestCase):
self.account, self.container, self.request) self.account, self.container, self.request)
self.check_container_info_return(ret, True) self.check_container_info_return(ret, True)
set_http_connect(503, 404, 404)# account_info 'NotFound' set_http_connect(503, 404, 404) # account_info 'NotFound'
ret = self.controller.container_info( ret = self.controller.container_info(
self.account, self.container, self.request) self.account, self.container, self.request)
self.check_container_info_return(ret, True) self.check_container_info_return(ret, True)
@ -1897,7 +1898,7 @@ class TestObjectController(unittest.TestCase):
with save_globals(): with save_globals():
limit = MAX_META_VALUE_LENGTH limit = MAX_META_VALUE_LENGTH
self.app.object_post_as_copy = False self.app.object_post_as_copy = False
controller = proxy_server.ObjectController(self.app, 'account', proxy_server.ObjectController(self.app, 'account',
'container', 'object') 'container', 'object')
set_http_connect(200, 200, 202, 202, 202) set_http_connect(200, 200, 202, 202, 202)
# acct cont obj obj obj # acct cont obj obj obj
@ -2024,7 +2025,7 @@ class TestObjectController(unittest.TestCase):
req = Request.blank('/v1/a/c/o.html', {'REQUEST_METHOD': 'PUT'}, req = Request.blank('/v1/a/c/o.html', {'REQUEST_METHOD': 'PUT'},
headers=headers) headers=headers)
self.app.update_request(req) self.app.update_request(req)
res = req.get_response(self.app) req.get_response(self.app)
self.assertNotEquals(it_worked, []) self.assertNotEquals(it_worked, [])
self.assertTrue(all(it_worked)) self.assertTrue(all(it_worked))
@ -2046,7 +2047,7 @@ class TestObjectController(unittest.TestCase):
req = Request.blank('/v1/a/c/o.html', {'REQUEST_METHOD': 'PUT'}, req = Request.blank('/v1/a/c/o.html', {'REQUEST_METHOD': 'PUT'},
headers=headers) headers=headers)
self.app.update_request(req) self.app.update_request(req)
res = req.get_response(self.app) req.get_response(self.app)
self.assertNotEquals(it_worked, []) self.assertNotEquals(it_worked, [])
self.assertTrue(all(it_worked)) self.assertTrue(all(it_worked))
@ -4615,7 +4616,8 @@ class TestObjectController(unittest.TestCase):
seen_headers = self._gather_x_container_headers( seen_headers = self._gather_x_container_headers(
controller.PUT, req, controller.PUT, req,
200, 200, 201, 201, 201) # HEAD HEAD PUT PUT PUT 200, 200, 201, 201, 201) # HEAD HEAD PUT PUT PUT
self.assertEqual(seen_headers, [ self.assertEqual(
seen_headers, [
{'X-Container-Host': '10.0.0.0:1000', {'X-Container-Host': '10.0.0.0:1000',
'X-Container-Partition': '1', 'X-Container-Partition': '1',
'X-Container-Device': 'sda'}, 'X-Container-Device': 'sda'},
@ -4636,7 +4638,8 @@ class TestObjectController(unittest.TestCase):
controller.PUT, req, controller.PUT, req,
200, 200, 201, 201, 201) # HEAD HEAD PUT PUT PUT 200, 200, 201, 201, 201) # HEAD HEAD PUT PUT PUT
self.assertEqual(seen_headers, [ self.assertEqual(
seen_headers, [
{'X-Container-Host': '10.0.0.0:1000', {'X-Container-Host': '10.0.0.0:1000',
'X-Container-Partition': '1', 'X-Container-Partition': '1',
'X-Container-Device': 'sda'}, 'X-Container-Device': 'sda'},
@ -4657,7 +4660,8 @@ class TestObjectController(unittest.TestCase):
controller.PUT, req, controller.PUT, req,
200, 200, 201, 201, 201) # HEAD HEAD PUT PUT PUT 200, 200, 201, 201, 201) # HEAD HEAD PUT PUT PUT
self.assertEqual(seen_headers, [ self.assertEqual(
seen_headers, [
{'X-Container-Host': '10.0.0.0:1000,10.0.0.3:1003', {'X-Container-Host': '10.0.0.0:1000,10.0.0.3:1003',
'X-Container-Partition': '1', 'X-Container-Partition': '1',
'X-Container-Device': 'sda,sdd'}, 'X-Container-Device': 'sda,sdd'},
@ -4679,7 +4683,8 @@ class TestObjectController(unittest.TestCase):
controller.POST, req, controller.POST, req,
200, 200, 200, 200, 200) # HEAD HEAD POST POST POST 200, 200, 200, 200, 200) # HEAD HEAD POST POST POST
self.assertEqual(seen_headers, [ self.assertEqual(
seen_headers, [
{'X-Container-Host': '10.0.0.0:1000,10.0.0.3:1003', {'X-Container-Host': '10.0.0.0:1000,10.0.0.3:1003',
'X-Container-Partition': '1', 'X-Container-Partition': '1',
'X-Container-Device': 'sda,sdd'}, 'X-Container-Device': 'sda,sdd'},
@ -4844,7 +4849,8 @@ class TestContainerController(unittest.TestCase):
self.assertEquals(res.headers['x-works'], 'yes') self.assertEquals(res.headers['x-works'], 'yes')
if c_expected: if c_expected:
self.assertTrue('swift.container/a/c' in res.environ) self.assertTrue('swift.container/a/c' in res.environ)
self.assertEquals(res.environ['swift.container/a/c']['status'], self.assertEquals(
res.environ['swift.container/a/c']['status'],
c_expected) c_expected)
else: else:
self.assertTrue('swift.container/a/c' not in res.environ) self.assertTrue('swift.container/a/c' not in res.environ)
@ -4867,7 +4873,8 @@ class TestContainerController(unittest.TestCase):
self.assertEquals(res.headers['x-works'], 'yes') self.assertEquals(res.headers['x-works'], 'yes')
if c_expected: if c_expected:
self.assertTrue('swift.container/a/c' in res.environ) self.assertTrue('swift.container/a/c' in res.environ)
self.assertEquals(res.environ['swift.container/a/c']['status'], self.assertEquals(
res.environ['swift.container/a/c']['status'],
c_expected) c_expected)
else: else:
self.assertTrue('swift.container/a/c' not in res.environ) self.assertTrue('swift.container/a/c' not in res.environ)
@ -4894,7 +4901,8 @@ class TestContainerController(unittest.TestCase):
# In all the following tests cache 404 for account # In all the following tests cache 404 for account
# return 404 (as account is not found) and dont cache container # return 404 (as account is not found) and dont cache container
test_status_map((404, 404, 404), 404, None, 404) test_status_map((404, 404, 404), 404, None, 404)
self.app.account_autocreate = True # This should make no difference # This should make no difference
self.app.account_autocreate = True
test_status_map((404, 404, 404), 404, None, 404) test_status_map((404, 404, 404), 404, None, 404)
def test_PUT(self): def test_PUT(self):
@ -4919,7 +4927,7 @@ class TestContainerController(unittest.TestCase):
self.assertFalse(self.app.account_autocreate) self.assertFalse(self.app.account_autocreate)
test_status_map((404, 404, 404), 404, missing_container=True) test_status_map((404, 404, 404), 404, missing_container=True)
self.app.account_autocreate = True self.app.account_autocreate = True
#fail to retrieve account info # fail to retrieve account info
test_status_map( test_status_map(
(503, 503, 503), # account_info fails on 503 (503, 503, 503), # account_info fails on 503
404, missing_container=True) 404, missing_container=True)
@ -4934,7 +4942,7 @@ class TestContainerController(unittest.TestCase):
503, 503, 503, # PUT account 503, 503, 503, # PUT account
503, 503, 404), # account_info fail 503, 503, 404), # account_info fail
404, missing_container=True) 404, missing_container=True)
#put fails # put fails
test_status_map( test_status_map(
(404, 404, 404, # account_info fails on 404 (404, 404, 404, # account_info fails on 404
201, 201, 201, # PUT account 201, 201, 201, # PUT account
@ -5367,7 +5375,8 @@ class TestContainerController(unittest.TestCase):
req = Request.blank('/a/c') req = Request.blank('/a/c')
self.app.update_request(req) self.app.update_request(req)
res = controller.GET(req) res = controller.GET(req)
self.assertEquals(res.environ['swift.container/a/c']['status'], 204) self.assertEquals(
res.environ['swift.container/a/c']['status'], 204)
self.assertEquals(res.content_length, 0) self.assertEquals(res.content_length, 0)
self.assertTrue('transfer-encoding' not in res.headers) self.assertTrue('transfer-encoding' not in res.headers)
@ -5721,7 +5730,8 @@ class TestAccountController(unittest.TestCase):
# Access-Control-Request-Method headers) # Access-Control-Request-Method headers)
self.app.allow_account_management = False self.app.allow_account_management = False
controller = proxy_server.AccountController(self.app, 'account') controller = proxy_server.AccountController(self.app, 'account')
req = Request.blank('/account', {'REQUEST_METHOD': 'OPTIONS'}, req = Request.blank(
'/account', {'REQUEST_METHOD': 'OPTIONS'},
headers={'Origin': 'http://foo.com', headers={'Origin': 'http://foo.com',
'Access-Control-Request-Method': 'GET'}) 'Access-Control-Request-Method': 'GET'})
req.content_length = 0 req.content_length = 0
@ -5834,13 +5844,16 @@ class TestAccountController(unittest.TestCase):
(404, 404, 404), 404) (404, 404, 404), 404)
# next turn it on and test account being created than updated # next turn it on and test account being created than updated
controller.app.account_autocreate = True controller.app.account_autocreate = True
self.assert_status_map(controller.POST, self.assert_status_map(
controller.POST,
(404, 404, 404, 202, 202, 202, 201, 201, 201), 201) (404, 404, 404, 202, 202, 202, 201, 201, 201), 201)
# account_info PUT account POST account # account_info PUT account POST account
self.assert_status_map(controller.POST, self.assert_status_map(
controller.POST,
(404, 404, 503, 201, 201, 503, 204, 204, 504), 204) (404, 404, 503, 201, 201, 503, 204, 204, 504), 204)
# what if create fails # what if create fails
self.assert_status_map(controller.POST, self.assert_status_map(
controller.POST,
(404, 404, 404, 403, 403, 403, 400, 400, 400), 400) (404, 404, 404, 403, 403, 403, 400, 400, 400), 400)
def test_connection_refused(self): def test_connection_refused(self):
@ -6115,7 +6128,8 @@ class TestAccountControllerFakeGetResponse(unittest.TestCase):
def test_GET_autocreate_accept_json(self): def test_GET_autocreate_accept_json(self):
with save_globals(): with save_globals():
set_http_connect(*([404] * 100)) # nonexistent: all backends 404 set_http_connect(*([404] * 100)) # nonexistent: all backends 404
req = Request.blank('/v1/a', headers={'Accept': 'application/json'}, req = Request.blank(
'/v1/a', headers={'Accept': 'application/json'},
environ={'REQUEST_METHOD': 'GET', environ={'REQUEST_METHOD': 'GET',
'PATH_INFO': '/v1/a'}) 'PATH_INFO': '/v1/a'})
resp = req.get_response(self.app) resp = req.get_response(self.app)
@ -6360,7 +6374,8 @@ class TestSegmentedIterable(unittest.TestCase):
segit.ratelimit_index = 0 segit.ratelimit_index = 0
segit.listing.next() segit.listing.next()
segit._load_next_segment() segit._load_next_segment()
self.assertEquals(self.controller.GETorHEAD_base_args[-1][4], '/a/lc/o2') self.assertEquals(
self.controller.GETorHEAD_base_args[-1][4], '/a/lc/o2')
data = ''.join(segit.segment_iter) data = ''.join(segit.segment_iter)
self.assertEquals(data, '22') self.assertEquals(data, '22')
@ -6372,8 +6387,10 @@ class TestSegmentedIterable(unittest.TestCase):
segit.listing.next() segit.listing.next()
segit.seek = 1 segit.seek = 1
segit._load_next_segment() segit._load_next_segment()
self.assertEquals(self.controller.GETorHEAD_base_args[-1][4], '/a/lc/o2') self.assertEquals(
self.assertEquals(str(self.controller.GETorHEAD_base_args[-1][0].range), self.controller.GETorHEAD_base_args[-1][4], '/a/lc/o2')
self.assertEquals(
str(self.controller.GETorHEAD_base_args[-1][0].range),
'bytes=1-') 'bytes=1-')
data = ''.join(segit.segment_iter) data = ''.join(segit.segment_iter)
self.assertEquals(data, '2') self.assertEquals(data, '2')