From 124e75bc1bd0dd7eaeede5889d6a3441ad9694b1 Mon Sep 17 00:00:00 2001 From: Tom Fifield Date: Sun, 7 Oct 2012 14:28:41 +1100 Subject: [PATCH] Allows removal of ACLs fixes bug 1049017 As per the bug report, the -remove- form of deletion only works with meta headers and not with x-container-read and x-container-write. This patch by Yukihiro KAWADA detects the container acls and sends them through to the backend empty like the other metadata values. patch2 extends metadata-helper in ContainerController tests so that the new functionality can be tested. patch3 changes the k.lower().startswith() commands for read/write to a single k.lower - thanks David :) patch4 fixes PEP8 patch5 fixes more than two hundred pep8 errors. Except one, where the pep8 tool complains of overindent, or underindent depending on the position on the line. No idea how to fix that one. patch6 fixes the remaining pep8 error - thanks Darrell Change-Id: I36c2dd72b4636136c5ce7db414bf2b61501090ad --- swift/proxy/controllers/base.py | 50 +- test/unit/proxy/test_server.py | 830 ++++++++++++++++++-------------- 2 files changed, 492 insertions(+), 388 deletions(-) diff --git a/swift/proxy/controllers/base.py b/swift/proxy/controllers/base.py index 3fd2ffaac3..12196a2de5 100644 --- a/swift/proxy/controllers/base.py +++ b/swift/proxy/controllers/base.py @@ -107,15 +107,21 @@ class Controller(object): self.trans_id = '-' def transfer_headers(self, src_headers, dst_headers): - x_remove = 'x-remove-%s-meta-' % self.server_type.lower() - x_meta = 'x-%s-meta-' % self.server_type.lower() + + st = self.server_type.lower() + x_remove = 'x-remove-%s-meta-' % st + x_remove_read = 'x-remove-%s-read' % st + x_remove_write = 'x-remove-%s-write' % st + x_meta = 'x-%s-meta-' % st dst_headers.update((k.lower().replace('-remove', '', 1), '') for k in src_headers - if k.lower().startswith(x_remove)) + if k.lower().startswith(x_remove) or + k.lower() in (x_remove_read, x_remove_write)) + dst_headers.update((k.lower(), v) for k, v in src_headers.iteritems() if k.lower() in self.pass_through_headers or - k.lower().startswith(x_meta)) + k.lower().startswith(x_meta)) def error_increment(self, node): """ @@ -135,7 +141,8 @@ class Controller(object): """ self.error_increment(node) self.app.logger.error(_('%(msg)s %(ip)s:%(port)s'), - {'msg': msg, 'ip': node['ip'], 'port': node['port']}) + {'msg': msg, 'ip': node['ip'], + 'port': node['port']}) def exception_occurred(self, node, typ, additional_info): """ @@ -220,7 +227,8 @@ class Controller(object): try: with ConnectionTimeout(self.app.conn_timeout): conn = http_connect(node['ip'], node['port'], - node['device'], partition, 'HEAD', path, headers) + node['device'], partition, 'HEAD', + path, headers) with Timeout(self.app.node_timeout): resp = conn.getresponse() body = resp.read() @@ -241,7 +249,8 @@ class Controller(object): result_code = -1 except (Exception, Timeout): self.exception_occurred(node, _('Account'), - _('Trying to get account info for %s') % path) + _('Trying to get account info for %s') + % path) if result_code == HTTP_NOT_FOUND and autocreate: if len(account) > MAX_ACCOUNT_NAME_LENGTH: return None, None, None @@ -249,10 +258,10 @@ class Controller(object): 'X-Trans-Id': self.trans_id, 'Connection': 'close'} resp = self.make_requests(Request.blank('/v1' + path), - self.app.account_ring, partition, 'PUT', - path, [headers] * len(nodes)) + self.app.account_ring, partition, 'PUT', + path, [headers] * len(nodes)) if not is_success(resp.status_int): - self.app.logger.warning('Could not autocreate account %r' % \ + self.app.logger.warning('Could not autocreate account %r' % path) return None, None, None result_code = HTTP_OK @@ -262,8 +271,9 @@ class Controller(object): else: cache_timeout = self.app.recheck_account_existence * 0.1 self.app.memcache.set(cache_key, - {'status': result_code, 'container_count': container_count}, - timeout=cache_timeout) + {'status': result_code, + 'container_count': container_count}, + timeout=cache_timeout) if result_code == HTTP_OK: return partition, nodes, container_count return None, None, None @@ -381,23 +391,23 @@ class Controller(object): try: with ConnectionTimeout(self.app.conn_timeout): conn = http_connect(node['ip'], node['port'], - node['device'], part, method, path, - headers=headers, query_string=query) + node['device'], part, method, path, + headers=headers, query_string=query) conn.node = node with Timeout(self.app.node_timeout): resp = conn.getresponse() if not is_informational(resp.status) and \ - not is_server_error(resp.status): + not is_server_error(resp.status): return resp.status, resp.reason, resp.read() elif resp.status == HTTP_INSUFFICIENT_STORAGE: self.error_limit(node) except (Exception, Timeout): self.exception_occurred(node, self.server_type, - _('Trying to %(method)s %(path)s') % - {'method': method, 'path': path}) + _('Trying to %(method)s %(path)s') % + {'method': method, 'path': path}) def make_requests(self, req, ring, part, method, path, headers, - query_string=''): + query_string=''): """ Sends an HTTP request to multiple nodes and aggregates the results. It attempts the primary nodes concurrently, then iterates over the @@ -418,7 +428,7 @@ class Controller(object): response.append((HTTP_SERVICE_UNAVAILABLE, '', '')) statuses, reasons, bodies = zip(*response) return self.best_response(req, statuses, reasons, bodies, - '%s %s' % (self.server_type, req.method)) + '%s %s' % (self.server_type, req.method)) def best_response(self, req, statuses, reasons, bodies, server_type, etag=None): @@ -495,7 +505,7 @@ class Controller(object): success = False except (Exception, Timeout): self.exception_occurred(node, _('Object'), - _('Trying to read during GET')) + _('Trying to read during GET')) success = False finally: # Ensure the queue getter gets a terminator. diff --git a/test/unit/proxy/test_server.py b/test/unit/proxy/test_server.py index 2cd1763a3a..62113c1789 100644 --- a/test/unit/proxy/test_server.py +++ b/test/unit/proxy/test_server.py @@ -77,7 +77,7 @@ def request_del(self): def setup(): global _testdir, _test_servers, _test_sockets, \ - _orig_container_listing_limit, _test_coros + _orig_container_listing_limit, _test_coros Request._orig_init = Request.__init__ Request.__init__ = request_init Request._orig_del = getattr(Request, '__del__', None) @@ -110,23 +110,23 @@ def setup(): _test_sockets = \ (prolis, acc1lis, acc2lis, con1lis, con2lis, obj1lis, obj2lis) pickle.dump(ring.RingData([[0, 1, 0, 1], [1, 0, 1, 0]], - [{'id': 0, 'zone': 0, 'device': 'sda1', 'ip': '127.0.0.1', - 'port': acc1lis.getsockname()[1]}, - {'id': 1, 'zone': 1, 'device': 'sdb1', 'ip': '127.0.0.1', - 'port': acc2lis.getsockname()[1]}], 30), - GzipFile(os.path.join(_testdir, 'account.ring.gz'), 'wb')) + [{'id': 0, 'zone': 0, 'device': 'sda1', 'ip': '127.0.0.1', + 'port': acc1lis.getsockname()[1]}, + {'id': 1, 'zone': 1, 'device': 'sdb1', 'ip': '127.0.0.1', + 'port': acc2lis.getsockname()[1]}], 30), + GzipFile(os.path.join(_testdir, 'account.ring.gz'), 'wb')) pickle.dump(ring.RingData([[0, 1, 0, 1], [1, 0, 1, 0]], - [{'id': 0, 'zone': 0, 'device': 'sda1', 'ip': '127.0.0.1', - 'port': con1lis.getsockname()[1]}, - {'id': 1, 'zone': 1, 'device': 'sdb1', 'ip': '127.0.0.1', - 'port': con2lis.getsockname()[1]}], 30), - GzipFile(os.path.join(_testdir, 'container.ring.gz'), 'wb')) + [{'id': 0, 'zone': 0, 'device': 'sda1', 'ip': '127.0.0.1', + 'port': con1lis.getsockname()[1]}, + {'id': 1, 'zone': 1, 'device': 'sdb1', 'ip': '127.0.0.1', + 'port': con2lis.getsockname()[1]}], 30), + GzipFile(os.path.join(_testdir, 'container.ring.gz'), 'wb')) pickle.dump(ring.RingData([[0, 1, 0, 1], [1, 0, 1, 0]], - [{'id': 0, 'zone': 0, 'device': 'sda1', 'ip': '127.0.0.1', - 'port': obj1lis.getsockname()[1]}, - {'id': 1, 'zone': 1, 'device': 'sdb1', 'ip': '127.0.0.1', - 'port': obj2lis.getsockname()[1]}], 30), - GzipFile(os.path.join(_testdir, 'object.ring.gz'), 'wb')) + [{'id': 0, 'zone': 0, 'device': 'sda1', 'ip': '127.0.0.1', + 'port': obj1lis.getsockname()[1]}, + {'id': 1, 'zone': 1, 'device': 'sdb1', 'ip': '127.0.0.1', + 'port': obj2lis.getsockname()[1]}], 30), + GzipFile(os.path.join(_testdir, 'object.ring.gz'), 'wb')) prosrv = proxy_server.Application(conf, FakeMemcacheReturnsNone()) acc1srv = account_server.AccountController(conf) acc2srv = account_server.AccountController(conf) @@ -151,16 +151,19 @@ def setup(): partition, nodes = prosrv.account_ring.get_nodes('a') for node in nodes: conn = swift.proxy.controllers.obj.http_connect(node['ip'], - node['port'], node['device'], partition, 'PUT', '/a', - {'X-Timestamp': ts, 'x-trans-id': 'test'}) + node['port'], + node['device'], + partition, 'PUT', '/a', + {'X-Timestamp': ts, + 'x-trans-id': 'test'}) resp = conn.getresponse() assert(resp.status == 201) # Create container sock = connect_tcp(('localhost', prolis.getsockname()[1])) fd = sock.makefile() fd.write('PUT /v1/a/c HTTP/1.1\r\nHost: localhost\r\n' - 'Connection: close\r\nX-Auth-Token: t\r\n' - 'Content-Length: 0\r\n\r\n') + 'Connection: close\r\nX-Auth-Token: t\r\n' + 'Content-Length: 0\r\n\r\n') fd.flush() headers = readuntil2crlfs(fd) exp = 'HTTP/1.1 201' @@ -214,7 +217,7 @@ def fake_http_connect(*code_iter, **kwargs): 'last-modified': self.timestamp, 'x-object-meta-test': 'testing', 'etag': - self.etag or '"68b329da9893e34099c7d8ad5cb9c940"', + self.etag or '"68b329da9893e34099c7d8ad5cb9c940"', 'x-works': 'yes', 'x-account-container-count': 12345} if not self.timestamp: @@ -344,7 +347,7 @@ class FakeMemcacheReturnsNone(FakeMemcache): @contextmanager def save_globals(): orig_http_connect = getattr(swift.proxy.controllers.base, 'http_connect', - None) + None) orig_account_info = getattr(proxy_server.Controller, 'account_info', None) try: yield True @@ -382,9 +385,9 @@ class TestController(unittest.TestCase): self.memcache = FakeMemcache() app = proxy_server.Application(None, self.memcache, - account_ring=self.account_ring, - container_ring=self.container_ring, - object_ring=FakeRing()) + account_ring=self.account_ring, + container_ring=self.container_ring, + object_ring=FakeRing()) self.controller = proxy_server.Controller(app) self.account = 'some_account' @@ -509,7 +512,7 @@ class TestController(unittest.TestCase): self.controller.account_info(self.account, autocreate=True) self.check_account_info_return(partition, nodes, is_none=True) self.assertEquals(None, count) - + self.memcache.store = {} set_http_connect(404, 404, 404, 409, 409, 409) exc = None @@ -523,7 +526,7 @@ class TestController(unittest.TestCase): partition, nodes, read_acl, write_acl = None, None, None, None else: partition, nodes = self.container_ring.get_nodes(self.account, - self.container) + self.container) read_acl, write_acl = self.read_acl, self.write_acl self.assertEqual(partition, ret['partition']) self.assertEqual(nodes, ret['nodes']) @@ -537,7 +540,7 @@ class TestController(unittest.TestCase): with save_globals(): proxy_server.Controller.account_info = account_info ret = self.controller.container_info(self.account, - self.container) + self.container) self.check_container_info_return(ret, True) # tests if 200 is cached and used @@ -547,22 +550,22 @@ class TestController(unittest.TestCase): with save_globals(): headers = {'x-container-read': self.read_acl, - 'x-container-write': self.write_acl} + 'x-container-write': self.write_acl} proxy_server.Controller.account_info = account_info set_http_connect(200, headers=headers) ret = self.controller.container_info(self.account, - self.container) + self.container) self.check_container_info_return(ret) cache_key = get_container_memcache_key(self.account, - self.container) + self.container) cache_value = self.memcache.get(cache_key) self.assertTrue(isinstance(cache_value, dict)) self.assertEquals(200, cache_value.get('status')) set_http_connect() ret = self.controller.container_info(self.account, - self.container) + self.container) self.check_container_info_return(ret) # tests if 404 is cached and used @@ -574,18 +577,18 @@ class TestController(unittest.TestCase): proxy_server.Controller.account_info = account_info set_http_connect(404, 404, 404) ret = self.controller.container_info(self.account, - self.container) + self.container) self.check_container_info_return(ret, True) cache_key = get_container_memcache_key(self.account, - self.container) + self.container) cache_value = self.memcache.get(cache_key) self.assertTrue(isinstance(cache_value, dict)) self.assertEquals(404, cache_value.get('status')) set_http_connect() ret = self.controller.container_info(self.account, - self.container) + self.container) self.check_container_info_return(ret, True) # tests if some http status codes are not cached @@ -593,7 +596,7 @@ class TestController(unittest.TestCase): def test(*status_list): set_http_connect(*status_list) ret = self.controller.container_info(self.account, - self.container) + self.container) self.assertEqual(len(self.memcache.keys()), 0) self.check_container_info_return(ret, True) @@ -614,7 +617,7 @@ class TestProxyServer(unittest.TestCase): raise Exception('this shouldnt be caught') app = MyApp(None, FakeMemcache(), account_ring=FakeRing(), - container_ring=FakeRing(), object_ring=FakeRing()) + container_ring=FakeRing(), object_ring=FakeRing()) req = Request.blank('/account', environ={'REQUEST_METHOD': 'HEAD'}) app.update_request(req) resp = app.handle_request(req) @@ -622,16 +625,20 @@ class TestProxyServer(unittest.TestCase): def test_internal_method_request(self): baseapp = proxy_server.Application({}, - FakeMemcache(), container_ring=FakeRing(), object_ring=FakeRing(), - account_ring=FakeRing()) + FakeMemcache(), + container_ring=FakeRing(), + object_ring=FakeRing(), + account_ring=FakeRing()) resp = baseapp.handle_request( Request.blank('/v1/a', environ={'REQUEST_METHOD': '__init__'})) self.assertEquals(resp.status, '405 Method Not Allowed') def test_inexistent_method_request(self): baseapp = proxy_server.Application({}, - FakeMemcache(), container_ring=FakeRing(), account_ring=FakeRing(), - object_ring=FakeRing()) + FakeMemcache(), + container_ring=FakeRing(), + account_ring=FakeRing(), + object_ring=FakeRing()) resp = baseapp.handle_request( Request.blank('/v1/a', environ={'REQUEST_METHOD': '!invalid'})) self.assertEquals(resp.status, '405 Method Not Allowed') @@ -644,8 +651,9 @@ class TestProxyServer(unittest.TestCase): with save_globals(): set_http_connect(200) app = proxy_server.Application(None, FakeMemcache(), - account_ring=FakeRing(), container_ring=FakeRing(), - object_ring=FakeRing()) + account_ring=FakeRing(), + container_ring=FakeRing(), + object_ring=FakeRing()) req = Request.blank('/v1/a') req.environ['swift.authorize'] = authorize app.update_request(req) @@ -659,8 +667,9 @@ class TestProxyServer(unittest.TestCase): called[0] = True return HTTPUnauthorized(request=req) app = proxy_server.Application(None, FakeMemcache(), - account_ring=FakeRing(), container_ring=FakeRing(), - object_ring=FakeRing()) + account_ring=FakeRing(), + container_ring=FakeRing(), + object_ring=FakeRing()) req = Request.blank('/v1/a') req.environ['swift.authorize'] = authorize app.update_request(req) @@ -671,8 +680,9 @@ class TestProxyServer(unittest.TestCase): swift_dir = mkdtemp() try: baseapp = proxy_server.Application({'swift_dir': swift_dir}, - FakeMemcache(), FakeLogger(), FakeRing(), FakeRing(), - FakeRing()) + FakeMemcache(), FakeLogger(), + FakeRing(), FakeRing(), + FakeRing()) resp = baseapp.handle_request( Request.blank('/', environ={'CONTENT_LENGTH': '-1'})) self.assertEquals(resp.status, '400 Bad Request') @@ -688,9 +698,11 @@ class TestProxyServer(unittest.TestCase): swift_dir = mkdtemp() try: baseapp = proxy_server.Application({'swift_dir': swift_dir, - 'deny_host_headers': 'invalid_host.com'}, - FakeMemcache(), FakeLogger(), FakeRing(), FakeRing(), - FakeRing()) + 'deny_host_headers': + 'invalid_host.com'}, + FakeMemcache(), FakeLogger(), + FakeRing(), FakeRing(), + FakeRing()) resp = baseapp.handle_request( Request.blank('/v1/a/c/o', environ={'HTTP_HOST': 'invalid_host.com'})) @@ -698,12 +710,14 @@ class TestProxyServer(unittest.TestCase): finally: rmtree(swift_dir, ignore_errors=True) + class TestObjectController(unittest.TestCase): def setUp(self): self.app = proxy_server.Application(None, FakeMemcache(), - account_ring=FakeRing(), container_ring=FakeRing(), - object_ring=FakeRing()) + account_ring=FakeRing(), + container_ring=FakeRing(), + object_ring=FakeRing()) monkey_patch_mimetools() def assert_status_map(self, method, statuses, expected, raise_exc=False): @@ -714,8 +728,9 @@ class TestObjectController(unittest.TestCase): set_http_connect(*statuses, **kwargs) self.app.memcache.store = {} - req = Request.blank('/a/c/o', headers={'Content-Length': '0', - 'Content-Type': 'text/plain'}) + req = Request.blank('/a/c/o', + headers={'Content-Length': '0', + 'Content-Type': 'text/plain'}) self.app.update_request(req) res = method(req) self.assertEquals(res.status_int, expected) @@ -723,8 +738,9 @@ class TestObjectController(unittest.TestCase): # repeat test set_http_connect(*statuses, **kwargs) self.app.memcache.store = {} - req = Request.blank('/a/c/o', headers={'Content-Length': '0', - 'Content-Type': 'text/plain'}) + req = Request.blank('/a/c/o', + headers={'Content-Length': '0', + 'Content-Type': 'text/plain'}) self.app.update_request(req) res = method(req) self.assertEquals(res.status_int, expected) @@ -755,9 +771,10 @@ class TestObjectController(unittest.TestCase): exp = 'HTTP/1.1 201' self.assertEqual(headers[:len(exp)], exp) req = Request.blank(path, - environ={'REQUEST_METHOD': 'GET'}, - headers={'Content-Type': 'application/octet-stream', - 'X-Newest':'true'}) + environ={'REQUEST_METHOD': 'GET'}, + headers={'Content-Type': + 'application/octet-stream', + 'X-Newest': 'true'}) res = req.get_response(prosrv) self.assertEqual(res.status_int, 200) self.assertEqual(res.body, obj) @@ -768,22 +785,26 @@ class TestObjectController(unittest.TestCase): def test_PUT_auto_content_type(self): with save_globals(): controller = proxy_server.ObjectController(self.app, 'account', - 'container', 'object') + 'container', 'object') def test_content_type(filename, expected): - # The three responses here are for account_info() (HEAD to account server), - # container_info() (HEAD to container server) and three calls to - # _connect_put_node() (PUT to three object servers) + # The three responses here are for account_info() (HEAD to + # account server), container_info() (HEAD to container server) + # and three calls to _connect_put_node() (PUT to three object + # servers) set_http_connect(201, 201, 201, 201, 201, - give_content_type=lambda content_type: - self.assertEquals(content_type, expected.next())) + give_content_type=lambda content_type: + self.assertEquals(content_type, + expected.next())) # We need into include a transfer-encoding to get past # constraints.check_object_creation() - req = Request.blank('/a/c/%s' % filename, {}, headers={'transfer-encoding': 'chunked'}) + req = Request.blank('/a/c/%s' % filename, {}, + headers={'transfer-encoding': 'chunked'}) self.app.update_request(req) self.app.memcache.store = {} res = controller.PUT(req) - # If we don't check the response here we could miss problems in PUT() + # If we don't check the response here we could miss problems + # in PUT() self.assertEquals(res.status_int, 201) test_content_type('test.jpg', iter(['', '', 'image/jpeg', @@ -799,8 +820,9 @@ class TestObjectController(unittest.TestCase): with open(os.path.join(swift_dir, 'mime.types'), 'w') as fp: fp.write('foo/bar foo\n') ba = proxy_server.Application({'swift_dir': swift_dir}, - FakeMemcache(), FakeLogger(), FakeRing(), FakeRing(), - FakeRing()) + FakeMemcache(), FakeLogger(), + FakeRing(), FakeRing(), + FakeRing()) self.assertEquals(proxy_server.mimetypes.guess_type('blah.foo')[0], 'foo/bar') self.assertEquals(proxy_server.mimetypes.guess_type('blah.jpg')[0], @@ -811,7 +833,7 @@ class TestObjectController(unittest.TestCase): def test_PUT(self): with save_globals(): controller = proxy_server.ObjectController(self.app, 'account', - 'container', 'object') + 'container', 'object') def test_status_map(statuses, expected): set_http_connect(*statuses) @@ -830,7 +852,7 @@ class TestObjectController(unittest.TestCase): def test_PUT_connect_exceptions(self): with save_globals(): controller = proxy_server.ObjectController(self.app, 'account', - 'container', 'object') + 'container', 'object') def test_status_map(statuses, expected): set_http_connect(*statuses) @@ -850,13 +872,14 @@ class TestObjectController(unittest.TestCase): def test_PUT_send_exceptions(self): with save_globals(): controller = proxy_server.ObjectController(self.app, 'account', - 'container', 'object') + 'container', 'object') def test_status_map(statuses, expected): self.app.memcache.store = {} set_http_connect(*statuses) req = Request.blank('/a/c/o.jpg', - environ={'REQUEST_METHOD': 'PUT'}, body='some data') + environ={'REQUEST_METHOD': 'PUT'}, + body='some data') self.app.update_request(req) res = controller.PUT(req) expected = str(expected) @@ -869,7 +892,7 @@ class TestObjectController(unittest.TestCase): with save_globals(): set_http_connect(201, 201, 201) controller = proxy_server.ObjectController(self.app, 'account', - 'container', 'object') + 'container', 'object') req = Request.blank('/a/c/o', {}, headers={ 'Content-Length': str(MAX_FILE_SIZE + 1), 'Content-Type': 'foo/bar'}) @@ -881,7 +904,7 @@ class TestObjectController(unittest.TestCase): with save_globals(): controller = proxy_server.ObjectController(self.app, 'account', - 'container', 'object') + 'container', 'object') def test_status_map(statuses, expected): self.app.memcache.store = {} @@ -901,13 +924,13 @@ class TestObjectController(unittest.TestCase): with save_globals(): self.app.object_post_as_copy = False controller = proxy_server.ObjectController(self.app, 'account', - 'container', 'object') + 'container', 'object') def test_status_map(statuses, expected): set_http_connect(*statuses) self.app.memcache.store = {} - req = Request.blank('/a/c/o', {}, headers={ - 'Content-Type': 'foo/bar'}) + req = Request.blank('/a/c/o', {}, + headers={'Content-Type': 'foo/bar'}) self.app.update_request(req) res = controller.POST(req) expected = str(expected) @@ -923,13 +946,13 @@ class TestObjectController(unittest.TestCase): def test_POST_as_copy(self): with save_globals(): controller = proxy_server.ObjectController(self.app, 'account', - 'container', 'object') + 'container', 'object') def test_status_map(statuses, expected): set_http_connect(*statuses) self.app.memcache.store = {} - req = Request.blank('/a/c/o', {}, headers={ - 'Content-Type': 'foo/bar'}) + req = Request.blank('/a/c/o', {}, + headers={'Content-Type': 'foo/bar'}) self.app.update_request(req) res = controller.POST(req) expected = str(expected) @@ -945,7 +968,7 @@ class TestObjectController(unittest.TestCase): def test_DELETE(self): with save_globals(): controller = proxy_server.ObjectController(self.app, 'account', - 'container', 'object') + 'container', 'object') def test_status_map(statuses, expected): set_http_connect(*statuses) @@ -965,7 +988,7 @@ class TestObjectController(unittest.TestCase): def test_HEAD(self): with save_globals(): controller = proxy_server.ObjectController(self.app, 'account', - 'container', 'object') + 'container', 'object') def test_status_map(statuses, expected): set_http_connect(*statuses) @@ -991,7 +1014,7 @@ class TestObjectController(unittest.TestCase): def test_HEAD_newest(self): with save_globals(): controller = proxy_server.ObjectController(self.app, 'account', - 'container', 'object') + 'container', 'object') def test_status_map(statuses, expected, timestamps, expected_timestamp): @@ -1006,17 +1029,23 @@ class TestObjectController(unittest.TestCase): expected_timestamp) # acct cont obj obj obj - test_status_map((200, 200, 200, 200, 200), 200, ('0', '0', '1', '2', '3'), '3') - test_status_map((200, 200, 200, 200, 200), 200, ('0', '0', '1', '3', '2'), '3') - test_status_map((200, 200, 200, 200, 200), 200, ('0', '0', '1', '3', '1'), '3') - test_status_map((200, 200, 200, 200, 200), 200, ('0', '0', '3', '3', '1'), '3') - test_status_map((200, 200, 200, 200, 200), 200, ('0', '0', None, None, None), None) - test_status_map((200, 200, 200, 200, 200), 200, ('0', '0', None, None, '1'), '1') + test_status_map((200, 200, 200, 200, 200), 200, ('0', '0', '1', + '2', '3'), '3') + test_status_map((200, 200, 200, 200, 200), 200, ('0', '0', '1', + '3', '2'), '3') + test_status_map((200, 200, 200, 200, 200), 200, ('0', '0', '1', + '3', '1'), '3') + test_status_map((200, 200, 200, 200, 200), 200, ('0', '0', '3', + '3', '1'), '3') + test_status_map((200, 200, 200, 200, 200), 200, ('0', '0', None, + None, None), None) + test_status_map((200, 200, 200, 200, 200), 200, ('0', '0', None, + None, '1'), '1') def test_GET_newest(self): with save_globals(): controller = proxy_server.ObjectController(self.app, 'account', - 'container', 'object') + 'container', 'object') def test_status_map(statuses, expected, timestamps, expected_timestamp): @@ -1030,16 +1059,22 @@ class TestObjectController(unittest.TestCase): self.assertEquals(res.headers.get('last-modified'), expected_timestamp) - test_status_map((200, 200, 200, 200, 200), 200, ('0', '0', '1', '2', '3'), '3') - test_status_map((200, 200, 200, 200, 200), 200, ('0', '0', '1', '3', '2'), '3') - test_status_map((200, 200, 200, 200, 200), 200, ('0', '0', '1', '3', '1'), '3') - test_status_map((200, 200, 200, 200, 200), 200, ('0', '0', '3', '3', '1'), '3') - test_status_map((200, 200, 200, 200, 200), 200, ('0', '0', None, None, None), None) - test_status_map((200, 200, 200, 200, 200), 200, ('0', '0', None, None, '1'), '1') + test_status_map((200, 200, 200, 200, 200), 200, ('0', '0', '1', + '2', '3'), '3') + test_status_map((200, 200, 200, 200, 200), 200, ('0', '0', '1', + '3', '2'), '3') + test_status_map((200, 200, 200, 200, 200), 200, ('0', '0', '1', + '3', '1'), '3') + test_status_map((200, 200, 200, 200, 200), 200, ('0', '0', '3', + '3', '1'), '3') + test_status_map((200, 200, 200, 200, 200), 200, ('0', '0', None, + None, None), None) + test_status_map((200, 200, 200, 200, 200), 200, ('0', '0', None, + None, '1'), '1') with save_globals(): controller = proxy_server.ObjectController(self.app, 'account', - 'container', 'object') + 'container', 'object') def test_status_map(statuses, expected, timestamps, expected_timestamp): @@ -1053,18 +1088,23 @@ class TestObjectController(unittest.TestCase): self.assertEquals(res.headers.get('last-modified'), expected_timestamp) - test_status_map((200, 200, 200, 200, 200), 200, ('0', '0', '1', '2', '3'), '1') - test_status_map((200, 200, 200, 200, 200), 200, ('0', '0', '1', '3', '2'), '1') - test_status_map((200, 200, 200, 200, 200), 200, ('0', '0', '1', '3', '1'), '1') - test_status_map((200, 200, 200, 200, 200), 200, ('0', '0', '3', '3', '1'), '3') - test_status_map((200, 200, 200, 200, 200), 200, ('0', '0', None, '1', '2'), None) + test_status_map((200, 200, 200, 200, 200), 200, ('0', '0', '1', + '2', '3'), '1') + test_status_map((200, 200, 200, 200, 200), 200, ('0', '0', '1', + '3', '2'), '1') + test_status_map((200, 200, 200, 200, 200), 200, ('0', '0', '1', + '3', '1'), '1') + test_status_map((200, 200, 200, 200, 200), 200, ('0', '0', '3', + '3', '1'), '3') + test_status_map((200, 200, 200, 200, 200), 200, ('0', '0', None, + '1', '2'), None) def test_POST_meta_val_len(self): with save_globals(): limit = MAX_META_VALUE_LENGTH self.app.object_post_as_copy = False controller = proxy_server.ObjectController(self.app, 'account', - 'container', 'object') + 'container', 'object') set_http_connect(200, 200, 202, 202, 202) # acct cont obj obj obj req = Request.blank('/a/c/o', {}, headers={ @@ -1085,7 +1125,7 @@ class TestObjectController(unittest.TestCase): with save_globals(): limit = MAX_META_VALUE_LENGTH controller = proxy_server.ObjectController(self.app, 'account', - 'container', 'object') + 'container', 'object') set_http_connect(200, 200, 200, 200, 200, 202, 202, 202) # acct cont objc objc objc obj obj obj req = Request.blank('/a/c/o', {}, headers={ @@ -1107,7 +1147,7 @@ class TestObjectController(unittest.TestCase): limit = MAX_META_NAME_LENGTH self.app.object_post_as_copy = False controller = proxy_server.ObjectController(self.app, 'account', - 'container', 'object') + 'container', 'object') set_http_connect(200, 200, 202, 202, 202) # acct cont obj obj obj req = Request.blank('/a/c/o', {}, headers={ @@ -1128,7 +1168,7 @@ class TestObjectController(unittest.TestCase): with save_globals(): limit = MAX_META_NAME_LENGTH controller = proxy_server.ObjectController(self.app, 'account', - 'container', 'object') + 'container', 'object') set_http_connect(200, 200, 200, 200, 200, 202, 202, 202) # acct cont objc objc objc obj obj obj req = Request.blank('/a/c/o', {}, headers={ @@ -1149,7 +1189,7 @@ class TestObjectController(unittest.TestCase): with save_globals(): limit = MAX_META_COUNT controller = proxy_server.ObjectController(self.app, 'account', - 'container', 'object') + 'container', 'object') headers = dict( (('X-Object-Meta-' + str(i), 'a') for i in xrange(limit + 1))) headers.update({'Content-Type': 'foo/bar'}) @@ -1163,7 +1203,7 @@ class TestObjectController(unittest.TestCase): with save_globals(): limit = MAX_META_OVERALL_SIZE controller = proxy_server.ObjectController(self.app, 'account', - 'container', 'object') + 'container', 'object') count = limit / 256 # enough to cause the limit to be reched headers = dict( (('X-Object-Meta-' + str(i), 'a' * 256) @@ -1203,8 +1243,10 @@ class TestObjectController(unittest.TestCase): return '' req = Request.blank('/a/c/o', - environ={'REQUEST_METHOD': 'PUT', 'wsgi.input': SlowBody()}, - headers={'Content-Length': '4', 'Content-Type': 'text/plain'}) + environ={'REQUEST_METHOD': 'PUT', + 'wsgi.input': SlowBody()}, + headers={'Content-Length': '4', + 'Content-Type': 'text/plain'}) self.app.update_request(req) controller = proxy_server.ObjectController(self.app, 'account', 'container', 'object') @@ -1214,8 +1256,10 @@ class TestObjectController(unittest.TestCase): self.assertEquals(resp.status_int, 201) self.app.client_timeout = 0.1 req = Request.blank('/a/c/o', - environ={'REQUEST_METHOD': 'PUT', 'wsgi.input': SlowBody()}, - headers={'Content-Length': '4', 'Content-Type': 'text/plain'}) + environ={'REQUEST_METHOD': 'PUT', + 'wsgi.input': SlowBody()}, + headers={'Content-Length': '4', + 'Content-Type': 'text/plain'}) self.app.update_request(req) set_http_connect(201, 201, 201) # obj obj obj @@ -1246,8 +1290,10 @@ class TestObjectController(unittest.TestCase): raise Exception('Disconnected') req = Request.blank('/a/c/o', - environ={'REQUEST_METHOD': 'PUT', 'wsgi.input': SlowBody()}, - headers={'Content-Length': '4', 'Content-Type': 'text/plain'}) + environ={'REQUEST_METHOD': 'PUT', + 'wsgi.input': SlowBody()}, + headers={'Content-Length': '4', + 'Content-Type': 'text/plain'}) self.app.update_request(req) controller = proxy_server.ObjectController(self.app, 'account', 'container', 'object') @@ -1308,9 +1354,10 @@ class TestObjectController(unittest.TestCase): dev['ip'] = '127.0.0.1' dev['port'] = 1 req = Request.blank('/a/c/o', - environ={'REQUEST_METHOD': 'PUT'}, - headers={'Content-Length': '4', 'Content-Type': 'text/plain'}, - body=' ') + environ={'REQUEST_METHOD': 'PUT'}, + headers={'Content-Length': '4', + 'Content-Type': 'text/plain'}, + body=' ') self.app.update_request(req) controller = proxy_server.ObjectController(self.app, 'account', 'container', 'object') @@ -1320,9 +1367,10 @@ class TestObjectController(unittest.TestCase): self.app.node_timeout = 0.1 set_http_connect(201, 201, 201, slow=True) req = Request.blank('/a/c/o', - environ={'REQUEST_METHOD': 'PUT'}, - headers={'Content-Length': '4', 'Content-Type': 'text/plain'}, - body=' ') + environ={'REQUEST_METHOD': 'PUT'}, + headers={'Content-Length': '4', + 'Content-Type': 'text/plain'}, + body=' ') self.app.update_request(req) resp = controller.PUT(req) self.assertEquals(resp.status_int, 503) @@ -1332,9 +1380,11 @@ class TestObjectController(unittest.TestCase): try: self.app.object_ring.max_more_nodes = 2 controller = proxy_server.ObjectController(self.app, 'account', - 'container', 'object') + 'container', + 'object') partition, nodes = self.app.object_ring.get_nodes('account', - 'container', 'object') + 'container', + 'object') collected_nodes = [] for node in controller.iter_nodes(partition, nodes, self.app.object_ring): @@ -1343,9 +1393,11 @@ class TestObjectController(unittest.TestCase): self.app.object_ring.max_more_nodes = 20 controller = proxy_server.ObjectController(self.app, 'account', - 'container', 'object') + 'container', + 'object') partition, nodes = self.app.object_ring.get_nodes('account', - 'container', 'object') + 'container', + 'object') collected_nodes = [] for node in controller.iter_nodes(partition, nodes, self.app.object_ring): @@ -1356,9 +1408,11 @@ class TestObjectController(unittest.TestCase): self.app.logger = FakeLogger() self.app.object_ring.max_more_nodes = 2 controller = proxy_server.ObjectController(self.app, 'account', - 'container', 'object') + 'container', + 'object') partition, nodes = self.app.object_ring.get_nodes('account', - 'container', 'object') + 'container', + 'object') collected_nodes = [] for node in controller.iter_nodes(partition, nodes, self.app.object_ring): @@ -1373,9 +1427,11 @@ class TestObjectController(unittest.TestCase): self.app.logger = FakeLogger() self.app.object_ring.max_more_nodes = 2 controller = proxy_server.ObjectController(self.app, 'account', - 'container', 'object') + 'container', + 'object') partition, nodes = self.app.object_ring.get_nodes('account', - 'container', 'object') + 'container', + 'object') collected_nodes = [] for node in controller.iter_nodes(partition, nodes, self.app.object_ring): @@ -1393,7 +1449,9 @@ class TestObjectController(unittest.TestCase): 'Object') self.assertEquals(resp.etag, None) resp = controller.best_response(req, [200] * 3, ['OK'] * 3, [''] * 3, - 'Object', etag='68b329da9893e34099c7d8ad5cb9c940') + 'Object', + etag='68b329da9893e34099c7d8ad5cb9c940' + ) self.assertEquals(resp.etag, '68b329da9893e34099c7d8ad5cb9c940') def test_proxy_passes_content_type(self): @@ -1435,26 +1493,33 @@ class TestObjectController(unittest.TestCase): set_shuffle() controller = proxy_server.ObjectController(self.app, 'account', 'container', 'object') - self.assert_status_map(controller.HEAD, (200, 200, 503, 200, 200), 200) + self.assert_status_map(controller.HEAD, (200, 200, 503, 200, 200), + 200) print controller.app.object_ring.devs self.assertEquals(controller.app.object_ring.devs[0]['errors'], 2) self.assert_('last_error' in controller.app.object_ring.devs[0]) for _junk in xrange(self.app.error_suppression_limit): - self.assert_status_map(controller.HEAD, (200, 200, 503, 503, 503), 503) + self.assert_status_map(controller.HEAD, (200, 200, 503, 503, + 503), 503) self.assertEquals(controller.app.object_ring.devs[0]['errors'], self.app.error_suppression_limit + 1) - self.assert_status_map(controller.HEAD, (200, 200, 200, 200, 200), 503) + self.assert_status_map(controller.HEAD, (200, 200, 200, 200, 200), + 503) self.assert_('last_error' in controller.app.object_ring.devs[0]) - self.assert_status_map(controller.PUT, (200, 200, 200, 201, 201, 201), 503) + self.assert_status_map(controller.PUT, (200, 200, 200, 201, 201, + 201), 503) self.assert_status_map(controller.POST, - (200, 200, 200, 200, 200, 200, 202, 202, 202), 503) + (200, 200, 200, 200, 200, 200, 202, 202, + 202), 503) self.assert_status_map(controller.DELETE, (200, 200, 200, 204, 204, 204), 503) self.app.error_suppression_interval = -300 - self.assert_status_map(controller.HEAD, (200, 200, 200, 200, 200), 200) + self.assert_status_map(controller.HEAD, (200, 200, 200, 200, 200), + 200) self.assertRaises(BaseException, - self.assert_status_map, controller.DELETE, - (200, 200, 200, 204, 204, 204), 503, raise_exc=True) + self.assert_status_map, controller.DELETE, + (200, 200, 200, 204, 204, 204), 503, + raise_exc=True) def test_acc_or_con_missing_returns_404(self): with save_globals(): @@ -1466,7 +1531,7 @@ class TestObjectController(unittest.TestCase): del dev['errors'] del dev['last_error'] controller = proxy_server.ObjectController(self.app, 'account', - 'container', 'object') + 'container', 'object') set_http_connect(200, 200, 200, 200, 200, 200) req = Request.blank('/a/c/o', environ={'REQUEST_METHOD': 'DELETE'}) self.app.update_request(req) @@ -1580,34 +1645,34 @@ class TestObjectController(unittest.TestCase): set_http_connect(201, 201, 201) req = Request.blank('/a/c/o', environ={'REQUEST_METHOD': 'PUT'}, - headers={'Content-Length': '0', - 'X-Object-Meta-' + ('a' * - MAX_META_NAME_LENGTH): 'v'}) + headers={'Content-Length': '0', + 'X-Object-Meta-' + ('a' * + MAX_META_NAME_LENGTH): 'v'}) self.app.update_request(req) resp = controller.PUT(req) self.assertEquals(resp.status_int, 201) set_http_connect(201, 201, 201) req = Request.blank('/a/c/o', environ={'REQUEST_METHOD': 'PUT'}, - headers={'Content-Length': '0', - 'X-Object-Meta-' + ('a' * - (MAX_META_NAME_LENGTH + 1)): 'v'}) + headers={'Content-Length': '0', + 'X-Object-Meta-' + ('a' * + (MAX_META_NAME_LENGTH + 1)): 'v'}) self.app.update_request(req) resp = controller.PUT(req) self.assertEquals(resp.status_int, 400) set_http_connect(201, 201, 201) req = Request.blank('/a/c/o', environ={'REQUEST_METHOD': 'PUT'}, - headers={'Content-Length': '0', - 'X-Object-Meta-Too-Long': 'a' * - MAX_META_VALUE_LENGTH}) + headers={'Content-Length': '0', + 'X-Object-Meta-Too-Long': 'a' * + MAX_META_VALUE_LENGTH}) self.app.update_request(req) resp = controller.PUT(req) self.assertEquals(resp.status_int, 201) set_http_connect(201, 201, 201) req = Request.blank('/a/c/o', environ={'REQUEST_METHOD': 'PUT'}, - headers={'Content-Length': '0', - 'X-Object-Meta-Too-Long': 'a' * - (MAX_META_VALUE_LENGTH + 1)}) + headers={'Content-Length': '0', + 'X-Object-Meta-Too-Long': 'a' * + (MAX_META_VALUE_LENGTH + 1)}) self.app.update_request(req) resp = controller.PUT(req) self.assertEquals(resp.status_int, 400) @@ -1674,7 +1739,7 @@ class TestObjectController(unittest.TestCase): # basic copy req = Request.blank('/a/c/o', environ={'REQUEST_METHOD': 'PUT'}, headers={'Content-Length': '0', - 'X-Copy-From': 'c/o'}) + 'X-Copy-From': 'c/o'}) self.app.update_request(req) set_http_connect(200, 200, 200, 200, 200, 200, 200, 201, 201, 201) # acct cont acct cont objc objc objc obj obj obj @@ -1686,7 +1751,7 @@ class TestObjectController(unittest.TestCase): # non-zero content length req = Request.blank('/a/c/o', environ={'REQUEST_METHOD': 'PUT'}, headers={'Content-Length': '5', - 'X-Copy-From': 'c/o'}) + 'X-Copy-From': 'c/o'}) self.app.update_request(req) set_http_connect(200, 200, 200, 200, 200, 200, 200) # acct cont acct cont objc objc objc @@ -1697,7 +1762,7 @@ class TestObjectController(unittest.TestCase): # extra source path parsing req = Request.blank('/a/c/o', environ={'REQUEST_METHOD': 'PUT'}, headers={'Content-Length': '0', - 'X-Copy-From': 'c/o/o2'}) + 'X-Copy-From': 'c/o/o2'}) req.account = 'a' set_http_connect(200, 200, 200, 200, 200, 200, 200, 201, 201, 201) # acct cont acct cont objc objc objc obj obj obj @@ -1709,7 +1774,7 @@ class TestObjectController(unittest.TestCase): # space in soure path req = Request.blank('/a/c/o', environ={'REQUEST_METHOD': 'PUT'}, headers={'Content-Length': '0', - 'X-Copy-From': 'c/o%20o2'}) + 'X-Copy-From': 'c/o%20o2'}) req.account = 'a' set_http_connect(200, 200, 200, 200, 200, 200, 200, 201, 201, 201) # acct cont acct cont objc objc objc obj obj obj @@ -1721,7 +1786,7 @@ class TestObjectController(unittest.TestCase): # repeat tests with leading / req = Request.blank('/a/c/o', environ={'REQUEST_METHOD': 'PUT'}, headers={'Content-Length': '0', - 'X-Copy-From': '/c/o'}) + 'X-Copy-From': '/c/o'}) self.app.update_request(req) set_http_connect(200, 200, 200, 200, 200, 200, 200, 201, 201, 201) # acct cont acct cont objc objc objc obj obj obj @@ -1732,7 +1797,7 @@ class TestObjectController(unittest.TestCase): req = Request.blank('/a/c/o', environ={'REQUEST_METHOD': 'PUT'}, headers={'Content-Length': '0', - 'X-Copy-From': '/c/o/o2'}) + 'X-Copy-From': '/c/o/o2'}) req.account = 'a' set_http_connect(200, 200, 200, 200, 200, 200, 200, 201, 201, 201) # acct cont acct cont objc objc objc obj obj obj @@ -1746,7 +1811,7 @@ class TestObjectController(unittest.TestCase): # invalid x-copy-from path req = Request.blank('/a/c/o', environ={'REQUEST_METHOD': 'PUT'}, headers={'Content-Length': '0', - 'X-Copy-From': '/c'}) + 'X-Copy-From': '/c'}) self.app.update_request(req) self.app.memcache.store = {} resp = controller.PUT(req) @@ -1755,7 +1820,7 @@ class TestObjectController(unittest.TestCase): # server error req = Request.blank('/a/c/o', environ={'REQUEST_METHOD': 'PUT'}, headers={'Content-Length': '0', - 'X-Copy-From': '/c/o'}) + 'X-Copy-From': '/c/o'}) self.app.update_request(req) set_http_connect(200, 200, 503, 503, 503) # acct cont objc objc objc @@ -1766,7 +1831,7 @@ class TestObjectController(unittest.TestCase): # not found req = Request.blank('/a/c/o', environ={'REQUEST_METHOD': 'PUT'}, headers={'Content-Length': '0', - 'X-Copy-From': '/c/o'}) + 'X-Copy-From': '/c/o'}) self.app.update_request(req) set_http_connect(200, 200, 404, 404, 404) # acct cont objc objc objc @@ -1777,7 +1842,7 @@ class TestObjectController(unittest.TestCase): # some missing containers req = Request.blank('/a/c/o', environ={'REQUEST_METHOD': 'PUT'}, headers={'Content-Length': '0', - 'X-Copy-From': '/c/o'}) + 'X-Copy-From': '/c/o'}) self.app.update_request(req) set_http_connect(200, 200, 404, 404, 200, 201, 201, 201) # acct cont objc objc objc obj obj obj @@ -1788,8 +1853,8 @@ class TestObjectController(unittest.TestCase): # test object meta data req = Request.blank('/a/c/o', environ={'REQUEST_METHOD': 'PUT'}, headers={'Content-Length': '0', - 'X-Copy-From': '/c/o', - 'X-Object-Meta-Ours': 'okay'}) + 'X-Copy-From': '/c/o', + 'X-Object-Meta-Ours': 'okay'}) self.app.update_request(req) set_http_connect(200, 200, 200, 200, 200, 201, 201, 201) # acct cont objc objc objc obj obj obj @@ -1898,7 +1963,7 @@ class TestObjectController(unittest.TestCase): req = Request.blank('/a/c/o', environ={'REQUEST_METHOD': 'COPY'}, headers={'Destination': '/c/o', - 'X-Object-Meta-Ours': 'okay'}) + 'X-Object-Meta-Ours': 'okay'}) req.account = 'a' controller.object_name = 'o' set_http_connect(200, 200, 200, 200, 200, 201, 201, 201) @@ -1918,8 +1983,9 @@ class TestObjectController(unittest.TestCase): req.account = 'a' controller.object_name = 'o' set_http_connect(200, 200, 200, 200, 200, 201, 201, 201, - # acct cont objc objc objc obj obj obj - timestamps=('1', '1', '1', '3', '2', '4', '4', '4')) + #act cont objc objc objc obj obj obj + timestamps=('1', '1', '1', '3', '2', '4', '4', + '4')) self.app.memcache.store = {} resp = controller.COPY(req) self.assertEquals(resp.status_int, 201) @@ -1950,10 +2016,10 @@ class TestObjectController(unittest.TestCase): with save_globals(): set_http_connect(201, 201, 201, 201) controller = proxy_server.ObjectController(self.app, 'account', - 'container', 'object') + 'container', 'object') req = Request.blank('/a/c/o', environ={'REQUEST_METHOD': 'COPY'}, - headers={'Transfer-Encoding': 'chunked', - 'Content-Type': 'foo/bar'}) + headers={'Transfer-Encoding': 'chunked', + 'Content-Type': 'foo/bar'}) req.body_file = ChunkedFile(10) self.app.memcache.store = {} @@ -1964,8 +2030,8 @@ class TestObjectController(unittest.TestCase): # test 413 entity to large set_http_connect(201, 201, 201, 201) req = Request.blank('/a/c/o', environ={'REQUEST_METHOD': 'COPY'}, - headers={'Transfer-Encoding': 'chunked', - 'Content-Type': 'foo/bar'}) + headers={'Transfer-Encoding': 'chunked', + 'Content-Type': 'foo/bar'}) req.body_file = ChunkedFile(11) self.app.memcache.store = {} self.app.update_request(req) @@ -1978,12 +2044,12 @@ class TestObjectController(unittest.TestCase): def test_chunked_put_bad_version(self): # Check bad version - (prolis, acc1lis, acc2lis, con1lis, con2lis, obj1lis, obj2lis) = \ - _test_sockets + (prolis, acc1lis, acc2lis, con1lis, con2lis, obj1lis, + obj2lis) = _test_sockets sock = connect_tcp(('localhost', prolis.getsockname()[1])) fd = sock.makefile() fd.write('GET /v0 HTTP/1.1\r\nHost: localhost\r\n' - 'Connection: close\r\nContent-Length: 0\r\n\r\n') + 'Connection: close\r\nContent-Length: 0\r\n\r\n') fd.flush() headers = readuntil2crlfs(fd) exp = 'HTTP/1.1 412' @@ -1991,12 +2057,12 @@ class TestObjectController(unittest.TestCase): def test_chunked_put_bad_path(self): # Check bad path - (prolis, acc1lis, acc2lis, con1lis, con2lis, obj1lis, obj2lis) = \ - _test_sockets + (prolis, acc1lis, acc2lis, con1lis, con2lis, obj1lis, + obj2lis) = _test_sockets sock = connect_tcp(('localhost', prolis.getsockname()[1])) fd = sock.makefile() fd.write('GET invalid HTTP/1.1\r\nHost: localhost\r\n' - 'Connection: close\r\nContent-Length: 0\r\n\r\n') + 'Connection: close\r\nContent-Length: 0\r\n\r\n') fd.flush() headers = readuntil2crlfs(fd) exp = 'HTTP/1.1 404' @@ -2004,13 +2070,13 @@ class TestObjectController(unittest.TestCase): def test_chunked_put_bad_utf8(self): # Check invalid utf-8 - (prolis, acc1lis, acc2lis, con1lis, con2lis, obj1lis, obj2lis) = \ - _test_sockets + (prolis, acc1lis, acc2lis, con1lis, con2lis, obj1lis, + obj2lis) = _test_sockets sock = connect_tcp(('localhost', prolis.getsockname()[1])) fd = sock.makefile() fd.write('GET /v1/a%80 HTTP/1.1\r\nHost: localhost\r\n' - 'Connection: close\r\nX-Auth-Token: t\r\n' - 'Content-Length: 0\r\n\r\n') + 'Connection: close\r\nX-Auth-Token: t\r\n' + 'Content-Length: 0\r\n\r\n') fd.flush() headers = readuntil2crlfs(fd) exp = 'HTTP/1.1 412' @@ -2018,13 +2084,13 @@ class TestObjectController(unittest.TestCase): def test_chunked_put_bad_path_no_controller(self): # Check bad path, no controller - (prolis, acc1lis, acc2lis, con1lis, con2lis, obj1lis, obj2lis) = \ - _test_sockets + (prolis, acc1lis, acc2lis, con1lis, con2lis, obj1lis, + obj2lis) = _test_sockets sock = connect_tcp(('localhost', prolis.getsockname()[1])) fd = sock.makefile() fd.write('GET /v1 HTTP/1.1\r\nHost: localhost\r\n' - 'Connection: close\r\nX-Auth-Token: t\r\n' - 'Content-Length: 0\r\n\r\n') + 'Connection: close\r\nX-Auth-Token: t\r\n' + 'Content-Length: 0\r\n\r\n') fd.flush() headers = readuntil2crlfs(fd) exp = 'HTTP/1.1 412' @@ -2032,13 +2098,13 @@ class TestObjectController(unittest.TestCase): def test_chunked_put_bad_method(self): # Check bad method - (prolis, acc1lis, acc2lis, con1lis, con2lis, obj1lis, obj2lis) = \ - _test_sockets + (prolis, acc1lis, acc2lis, con1lis, con2lis, obj1lis, + obj2lis) = _test_sockets sock = connect_tcp(('localhost', prolis.getsockname()[1])) fd = sock.makefile() fd.write('LICK /v1/a HTTP/1.1\r\nHost: localhost\r\n' - 'Connection: close\r\nX-Auth-Token: t\r\n' - 'Content-Length: 0\r\n\r\n') + 'Connection: close\r\nX-Auth-Token: t\r\n' + 'Content-Length: 0\r\n\r\n') fd.flush() headers = readuntil2crlfs(fd) exp = 'HTTP/1.1 405' @@ -2046,10 +2112,10 @@ class TestObjectController(unittest.TestCase): def test_chunked_put_unhandled_exception(self): # Check unhandled exception - (prosrv, acc1srv, acc2srv, con1srv, con2srv, obj1srv, obj2srv) = \ - _test_servers - (prolis, acc1lis, acc2lis, con1lis, con2lis, obj1lis, obj2lis) = \ - _test_sockets + (prosrv, acc1srv, acc2srv, con1srv, con2srv, obj1srv, + obj2srv) = _test_servers + (prolis, acc1lis, acc2lis, con1lis, con2lis, obj1lis, + obj2lis) = _test_sockets orig_update_request = prosrv.update_request def broken_update_request(*args, **kwargs): @@ -2059,8 +2125,8 @@ class TestObjectController(unittest.TestCase): sock = connect_tcp(('localhost', prolis.getsockname()[1])) fd = sock.makefile() fd.write('HEAD /v1/a HTTP/1.1\r\nHost: localhost\r\n' - 'Connection: close\r\nX-Auth-Token: t\r\n' - 'Content-Length: 0\r\n\r\n') + 'Connection: close\r\nX-Auth-Token: t\r\n' + 'Content-Length: 0\r\n\r\n') fd.flush() headers = readuntil2crlfs(fd) exp = 'HTTP/1.1 500' @@ -2071,13 +2137,13 @@ class TestObjectController(unittest.TestCase): # Head account, just a double check and really is here to test # the part Application.log_request that 'enforces' a # content_length on the response. - (prolis, acc1lis, acc2lis, con1lis, con2lis, obj1lis, obj2lis) = \ - _test_sockets + (prolis, acc1lis, acc2lis, con1lis, con2lis, obj1lis, + obj2lis) = _test_sockets sock = connect_tcp(('localhost', prolis.getsockname()[1])) fd = sock.makefile() fd.write('HEAD /v1/a HTTP/1.1\r\nHost: localhost\r\n' - 'Connection: close\r\nX-Auth-Token: t\r\n' - 'Content-Length: 0\r\n\r\n') + 'Connection: close\r\nX-Auth-Token: t\r\n' + 'Content-Length: 0\r\n\r\n') fd.flush() headers = readuntil2crlfs(fd) exp = 'HTTP/1.1 204' @@ -2094,8 +2160,8 @@ class TestObjectController(unittest.TestCase): '\xbf\x86.Test' ustr_short = '\xe1\xbc\xb8\xce\xbf\xe1\xbd\xbatest' # Create ustr container - (prolis, acc1lis, acc2lis, con1lis, con2lis, obj1lis, obj2lis) = \ - _test_sockets + (prolis, acc1lis, acc2lis, con1lis, con2lis, obj1lis, + obj2lis) = _test_sockets sock = connect_tcp(('localhost', prolis.getsockname()[1])) fd = sock.makefile() fd.write('PUT /v1/a/%s HTTP/1.1\r\nHost: localhost\r\n' @@ -2201,21 +2267,21 @@ class TestObjectController(unittest.TestCase): exp = 'HTTP/1.1 200' self.assertEquals(headers[:len(exp)], exp) self.assert_('\r\nX-Object-Meta-%s: %s\r\n' % - (quote(ustr_short).lower(), quote(ustr)) in headers) + (quote(ustr_short).lower(), quote(ustr)) in headers) def test_chunked_put_chunked_put(self): # Do chunked object put - (prolis, acc1lis, acc2lis, con1lis, con2lis, obj1lis, obj2lis) = \ - _test_sockets + (prolis, acc1lis, acc2lis, con1lis, con2lis, obj1lis, + obj2lis) = _test_sockets sock = connect_tcp(('localhost', prolis.getsockname()[1])) fd = sock.makefile() # Also happens to assert that x-storage-token is taken as a # replacement for x-auth-token. fd.write('PUT /v1/a/c/o/chunky HTTP/1.1\r\nHost: localhost\r\n' - 'Connection: close\r\nX-Storage-Token: t\r\n' - 'Transfer-Encoding: chunked\r\n\r\n' - '2\r\noh\r\n4\r\n hai\r\nf\r\n123456789abcdef\r\n' - '0\r\n\r\n') + 'Connection: close\r\nX-Storage-Token: t\r\n' + 'Transfer-Encoding: chunked\r\n\r\n' + '2\r\noh\r\n4\r\n hai\r\nf\r\n123456789abcdef\r\n' + '0\r\n\r\n') fd.flush() headers = readuntil2crlfs(fd) exp = 'HTTP/1.1 201' @@ -2235,8 +2301,8 @@ class TestObjectController(unittest.TestCase): def test_version_manifest(self): versions_to_create = 3 # Create a container for our versioned object testing - (prolis, acc1lis, acc2lis, con1lis, con2lis, obj1lis, obj2lis) = \ - _test_sockets + (prolis, acc1lis, acc2lis, con1lis, con2lis, obj1lis, + obj2lis) = _test_sockets sock = connect_tcp(('localhost', prolis.getsockname()[1])) fd = sock.makefile() fd.write('PUT /v1/a/versions HTTP/1.1\r\nHost: localhost\r\n' @@ -2270,9 +2336,9 @@ class TestObjectController(unittest.TestCase): sock = connect_tcp(('localhost', prolis.getsockname()[1])) fd = sock.makefile() fd.write('PUT /v1/a/versions/name HTTP/1.1\r\nHost: ' - 'localhost\r\nConnection: close\r\nX-Storage-Token: ' - 't\r\nContent-Length: 5\r\nContent-Type: text/jibberish0\r\n' - 'X-Object-Meta-Foo: barbaz\r\n\r\n00000\r\n') + 'localhost\r\nConnection: close\r\nX-Storage-Token: ' + 't\r\nContent-Length: 5\r\nContent-Type: text/jibberish0\r\n' + 'X-Object-Meta-Foo: barbaz\r\n\r\n00000\r\n') fd.flush() headers = readuntil2crlfs(fd) exp = 'HTTP/1.1 201' @@ -2283,9 +2349,9 @@ class TestObjectController(unittest.TestCase): sock = connect_tcp(('localhost', prolis.getsockname()[1])) fd = sock.makefile() fd.write('PUT /v1/a/versions/name HTTP/1.1\r\nHost: ' - 'localhost\r\nConnection: close\r\nX-Storage-Token: ' - 't\r\nContent-Length: 5\r\nContent-Type: text/jibberish%s' - '\r\n\r\n%05d\r\n' % (segment, segment)) + 'localhost\r\nConnection: close\r\nX-Storage-Token: ' + 't\r\nContent-Length: 5\r\nContent-Type: text/jibberish%s' + '\r\n\r\n%05d\r\n' % (segment, segment)) fd.flush() headers = readuntil2crlfs(fd) exp = 'HTTP/1.1 201' @@ -2294,7 +2360,8 @@ class TestObjectController(unittest.TestCase): sock = connect_tcp(('localhost', prolis.getsockname()[1])) fd = sock.makefile() fd.write('GET /v1/a/versions/name HTTP/1.1\r\nHost: ' - 'localhost\r\nConnection: close\r\nX-Auth-Token: t\r\n\r\n') + 'localhost\r\nConnection: close\r\nX-Auth-Token: t\r\n' + '\r\n') fd.flush() headers = readuntil2crlfs(fd) exp = 'HTTP/1.1 200' @@ -2307,7 +2374,7 @@ class TestObjectController(unittest.TestCase): sock = connect_tcp(('localhost', prolis.getsockname()[1])) fd = sock.makefile() fd.write('GET /v1/a/vers?prefix=004name/ HTTP/1.1\r\nHost: ' - 'localhost\r\nConnection: close\r\nX-Auth-Token: t\r\n\r\n') + 'localhost\r\nConnection: close\r\nX-Auth-Token: t\r\n\r\n') fd.flush() headers = readuntil2crlfs(fd) exp = 'HTTP/1.1 200' @@ -2319,9 +2386,9 @@ class TestObjectController(unittest.TestCase): sock = connect_tcp(('localhost', prolis.getsockname()[1])) fd = sock.makefile() fd.write('COPY /v1/a/versions/name HTTP/1.1\r\nHost: ' - 'localhost\r\nConnection: close\r\nX-Auth-Token: ' - 't\r\nDestination: versions/copied_name\r\n' - 'Content-Length: 0\r\n\r\n') + 'localhost\r\nConnection: close\r\nX-Auth-Token: ' + 't\r\nDestination: versions/copied_name\r\n' + 'Content-Length: 0\r\n\r\n') fd.flush() headers = readuntil2crlfs(fd) exp = 'HTTP/1.1 2' # 2xx series response to the COPY @@ -2329,7 +2396,7 @@ class TestObjectController(unittest.TestCase): sock = connect_tcp(('localhost', prolis.getsockname()[1])) fd = sock.makefile() fd.write('GET /v1/a/versions/copied_name HTTP/1.1\r\nHost: ' - 'localhost\r\nConnection: close\r\nX-Auth-Token: t\r\n\r\n') + 'localhost\r\nConnection: close\r\nX-Auth-Token: t\r\n\r\n') fd.flush() headers = readuntil2crlfs(fd) exp = 'HTTP/1.1 200' @@ -2340,9 +2407,9 @@ class TestObjectController(unittest.TestCase): sock = connect_tcp(('localhost', prolis.getsockname()[1])) fd = sock.makefile() fd.write('POST /v1/a/versions/name HTTP/1.1\r\nHost: ' - 'localhost\r\nConnection: close\r\nX-Auth-Token: ' - 't\r\nContent-Type: foo/bar\r\nContent-Length: 0\r\n' - 'X-Object-Meta-Bar: foo\r\n\r\n') + 'localhost\r\nConnection: close\r\nX-Auth-Token: ' + 't\r\nContent-Type: foo/bar\r\nContent-Length: 0\r\n' + 'X-Object-Meta-Bar: foo\r\n\r\n') fd.flush() headers = readuntil2crlfs(fd) exp = 'HTTP/1.1 2' # 2xx series response to the POST @@ -2350,7 +2417,7 @@ class TestObjectController(unittest.TestCase): sock = connect_tcp(('localhost', prolis.getsockname()[1])) fd = sock.makefile() fd.write('GET /v1/a/versions/name HTTP/1.1\r\nHost: ' - 'localhost\r\nConnection: close\r\nX-Auth-Token: t\r\n\r\n') + 'localhost\r\nConnection: close\r\nX-Auth-Token: t\r\n\r\n') fd.flush() headers = readuntil2crlfs(fd) exp = 'HTTP/1.1 200' @@ -2363,8 +2430,8 @@ class TestObjectController(unittest.TestCase): for segment in xrange(versions_to_create - 1, 0, -1): sock = connect_tcp(('localhost', prolis.getsockname()[1])) fd = sock.makefile() - fd.write('DELETE /v1/a/versions/name HTTP/1.1\r\nHost: ' - 'localhost\r\nConnection: close\r\nX-Storage-Token: t\r\n\r\n') + fd.write('DELETE /v1/a/versions/name HTTP/1.1\r\nHost: localhost\r' + '\nConnection: close\r\nX-Storage-Token: t\r\n\r\n') fd.flush() headers = readuntil2crlfs(fd) exp = 'HTTP/1.1 2' # 2xx series response @@ -2372,21 +2439,22 @@ class TestObjectController(unittest.TestCase): # Ensure retrieving the manifest file gets the latest version sock = connect_tcp(('localhost', prolis.getsockname()[1])) fd = sock.makefile() - fd.write('GET /v1/a/versions/name HTTP/1.1\r\nHost: ' - 'localhost\r\nConnection: close\r\nX-Auth-Token: t\r\n\r\n') + fd.write('GET /v1/a/versions/name HTTP/1.1\r\nHost: localhost\r\n' + 'Connection: close\r\nX-Auth-Token: t\r\n\r\n') fd.flush() headers = readuntil2crlfs(fd) exp = 'HTTP/1.1 200' self.assertEquals(headers[:len(exp)], exp) self.assert_('Content-Type: text/jibberish%s' % (segment - 1) - in headers) + in headers) body = fd.read() self.assertEquals(body, '%05d' % (segment - 1)) # Ensure we have the right number of versions saved sock = connect_tcp(('localhost', prolis.getsockname()[1])) fd = sock.makefile() fd.write('GET /v1/a/vers?prefix=004name/ HTTP/1.1\r\nHost: ' - 'localhost\r\nConnection: close\r\nX-Auth-Token: t\r\n\r\n') + 'localhost\r\nConnection: close\r\nX-Auth-Token: t\r\n\r' + '\n') fd.flush() headers = readuntil2crlfs(fd) exp = 'HTTP/1.1 2' # 2xx series response @@ -2399,7 +2467,7 @@ class TestObjectController(unittest.TestCase): sock = connect_tcp(('localhost', prolis.getsockname()[1])) fd = sock.makefile() fd.write('GET /v1/a/vers?prefix=004name/ HTTP/1.1\r\nHost: ' - 'localhost\r\nConnection: close\r\nX-Auth-Token: t\r\n\r\n') + 'localhost\r\nConnection: close\r\nX-Auth-Token: t\r\n\r\n') fd.flush() headers = readuntil2crlfs(fd) exp = 'HTTP/1.1 204 No Content' @@ -2407,8 +2475,8 @@ class TestObjectController(unittest.TestCase): # delete the last verision sock = connect_tcp(('localhost', prolis.getsockname()[1])) fd = sock.makefile() - fd.write('DELETE /v1/a/versions/name HTTP/1.1\r\nHost: ' - 'localhost\r\nConnection: close\r\nX-Storage-Token: t\r\n\r\n') + fd.write('DELETE /v1/a/versions/name HTTP/1.1\r\nHost: localhost\r\n' + 'Connection: close\r\nX-Storage-Token: t\r\n\r\n') fd.flush() headers = readuntil2crlfs(fd) exp = 'HTTP/1.1 2' # 2xx series response @@ -2417,7 +2485,7 @@ class TestObjectController(unittest.TestCase): sock = connect_tcp(('localhost', prolis.getsockname()[1])) fd = sock.makefile() fd.write('GET /v1/a/versions/name HTTP/1.1\r\nHost: ' - 'localhost\r\nConnection: close\r\nX-Auth-Token: t\r\n\r\n') + 'localhost\r\nConnection: close\r\nX-Auth-Token: t\r\n\r\n') fd.flush() headers = readuntil2crlfs(fd) exp = 'HTTP/1.1 404' @@ -2427,9 +2495,9 @@ class TestObjectController(unittest.TestCase): sock = connect_tcp(('localhost', prolis.getsockname()[1])) fd = sock.makefile() fd.write('PUT /v1/a/versions/name HTTP/1.1\r\nHost: ' - 'localhost\r\nConnection: close\r\nX-Storage-Token: ' - 't\r\nContent-Length: 0\r\nContent-Type: text/jibberish0\r\n' - 'Foo: barbaz\r\nX-Object-Manifest: vers/foo_\r\n\r\n') + 'localhost\r\nConnection: close\r\nX-Storage-Token: ' + 't\r\nContent-Length: 0\r\nContent-Type: text/jibberish0\r\n' + 'Foo: barbaz\r\nX-Object-Manifest: vers/foo_\r\n\r\n') fd.flush() headers = readuntil2crlfs(fd) exp = 'HTTP/1.1 201' @@ -2438,7 +2506,7 @@ class TestObjectController(unittest.TestCase): sock = connect_tcp(('localhost', prolis.getsockname()[1])) fd = sock.makefile() fd.write('GET /v1/a/vers?prefix=004name/ HTTP/1.1\r\nHost: ' - 'localhost\r\nConnection: close\r\nX-Auth-Token: t\r\n\r\n') + 'localhost\r\nConnection: close\r\nX-Auth-Token: t\r\n\r\n') fd.flush() headers = readuntil2crlfs(fd) exp = 'HTTP/1.1 204 No Content' @@ -2448,9 +2516,9 @@ class TestObjectController(unittest.TestCase): sock = connect_tcp(('localhost', prolis.getsockname()[1])) fd = sock.makefile() fd.write('PUT /v1/a/versions/name HTTP/1.1\r\nHost: ' - 'localhost\r\nConnection: close\r\nX-Storage-Token: ' - 't\r\nContent-Length: 5\r\nContent-Type: text/jibberish0\r\n' - 'Foo: barbaz\r\n\r\n00000\r\n') + 'localhost\r\nConnection: close\r\nX-Storage-Token: ' + 't\r\nContent-Length: 5\r\nContent-Type: text/jibberish0\r\n' + 'Foo: barbaz\r\n\r\n00000\r\n') fd.flush() headers = readuntil2crlfs(fd) exp = 'HTTP/1.1 201' @@ -2458,9 +2526,9 @@ class TestObjectController(unittest.TestCase): sock = connect_tcp(('localhost', prolis.getsockname()[1])) fd = sock.makefile() fd.write('PUT /v1/a/versions/name HTTP/1.1\r\nHost: ' - 'localhost\r\nConnection: close\r\nX-Storage-Token: ' - 't\r\nContent-Length: 5\r\nContent-Type: text/jibberish0\r\n' - 'Foo: barbaz\r\n\r\n00001\r\n') + 'localhost\r\nConnection: close\r\nX-Storage-Token: ' + 't\r\nContent-Length: 5\r\nContent-Type: text/jibberish0\r\n' + 'Foo: barbaz\r\n\r\n00001\r\n') fd.flush() headers = readuntil2crlfs(fd) exp = 'HTTP/1.1 201' @@ -2468,9 +2536,9 @@ class TestObjectController(unittest.TestCase): sock = connect_tcp(('localhost', prolis.getsockname()[1])) fd = sock.makefile() fd.write('PUT /v1/a/versions/name/sub HTTP/1.1\r\nHost: ' - 'localhost\r\nConnection: close\r\nX-Storage-Token: ' - 't\r\nContent-Length: 4\r\nContent-Type: text/jibberish0\r\n' - 'Foo: barbaz\r\n\r\nsub1\r\n') + 'localhost\r\nConnection: close\r\nX-Storage-Token: ' + 't\r\nContent-Length: 4\r\nContent-Type: text/jibberish0\r\n' + 'Foo: barbaz\r\n\r\nsub1\r\n') fd.flush() headers = readuntil2crlfs(fd) exp = 'HTTP/1.1 201' @@ -2478,17 +2546,17 @@ class TestObjectController(unittest.TestCase): sock = connect_tcp(('localhost', prolis.getsockname()[1])) fd = sock.makefile() fd.write('PUT /v1/a/versions/name/sub HTTP/1.1\r\nHost: ' - 'localhost\r\nConnection: close\r\nX-Storage-Token: ' - 't\r\nContent-Length: 4\r\nContent-Type: text/jibberish0\r\n' - 'Foo: barbaz\r\n\r\nsub2\r\n') + 'localhost\r\nConnection: close\r\nX-Storage-Token: ' + 't\r\nContent-Length: 4\r\nContent-Type: text/jibberish0\r\n' + 'Foo: barbaz\r\n\r\nsub2\r\n') fd.flush() headers = readuntil2crlfs(fd) exp = 'HTTP/1.1 201' self.assertEquals(headers[:len(exp)], exp) sock = connect_tcp(('localhost', prolis.getsockname()[1])) fd = sock.makefile() - fd.write('DELETE /v1/a/versions/name HTTP/1.1\r\nHost: ' - 'localhost\r\nConnection: close\r\nX-Storage-Token: t\r\n\r\n') + fd.write('DELETE /v1/a/versions/name HTTP/1.1\r\nHost: localhost\r\n' + 'Connection: close\r\nX-Storage-Token: t\r\n\r\n') fd.flush() headers = readuntil2crlfs(fd) exp = 'HTTP/1.1 2' # 2xx series response @@ -2496,7 +2564,7 @@ class TestObjectController(unittest.TestCase): sock = connect_tcp(('localhost', prolis.getsockname()[1])) fd = sock.makefile() fd.write('GET /v1/a/vers?prefix=008name/sub/ HTTP/1.1\r\nHost: ' - 'localhost\r\nConnection: close\r\nX-Auth-Token: t\r\n\r\n') + 'localhost\r\nConnection: close\r\nX-Auth-Token: t\r\n\r\n') fd.flush() headers = readuntil2crlfs(fd) exp = 'HTTP/1.1 2' # 2xx series response @@ -2519,8 +2587,8 @@ class TestObjectController(unittest.TestCase): sock = connect_tcp(('localhost', prolis.getsockname()[1])) fd = sock.makefile() fd.write('PUT /v1/a/whoops/foo HTTP/1.1\r\nHost: ' - 'localhost\r\nConnection: close\r\nX-Storage-Token: ' - 't\r\nContent-Length: 5\r\n\r\n00000\r\n') + 'localhost\r\nConnection: close\r\nX-Storage-Token: ' + 't\r\nContent-Length: 5\r\n\r\n00000\r\n') fd.flush() headers = readuntil2crlfs(fd) exp = 'HTTP/1.1 201' @@ -2529,8 +2597,8 @@ class TestObjectController(unittest.TestCase): sock = connect_tcp(('localhost', prolis.getsockname()[1])) fd = sock.makefile() fd.write('PUT /v1/a/whoops/foo HTTP/1.1\r\nHost: ' - 'localhost\r\nConnection: close\r\nX-Storage-Token: ' - 't\r\nContent-Length: 5\r\n\r\n00001\r\n') + 'localhost\r\nConnection: close\r\nX-Storage-Token: ' + 't\r\nContent-Length: 5\r\n\r\n00001\r\n') fd.flush() headers = readuntil2crlfs(fd) exp = 'HTTP/1.1 412' @@ -2538,8 +2606,8 @@ class TestObjectController(unittest.TestCase): # Delete the object sock = connect_tcp(('localhost', prolis.getsockname()[1])) fd = sock.makefile() - fd.write('DELETE /v1/a/whoops/foo HTTP/1.1\r\nHost: ' - 'localhost\r\nConnection: close\r\nX-Storage-Token: t\r\n\r\n') + fd.write('DELETE /v1/a/whoops/foo HTTP/1.1\r\nHost: localhost\r\n' + 'Connection: close\r\nX-Storage-Token: t\r\n\r\n') fd.flush() headers = readuntil2crlfs(fd) exp = 'HTTP/1.1 2' # 2xx response @@ -2948,10 +3016,10 @@ class TestObjectController(unittest.TestCase): headers={'Content-Length': '0'}) self.app.update_request(req) set_http_connect(200, 201, 201, 201, - etags=[None, - '68b329da9893e34099c7d8ad5cb9c940', - '68b329da9893e34099c7d8ad5cb9c940', - '68b329da9893e34099c7d8ad5cb9c941']) + etags=[None, + '68b329da9893e34099c7d8ad5cb9c940', + '68b329da9893e34099c7d8ad5cb9c940', + '68b329da9893e34099c7d8ad5cb9c941']) resp = controller.PUT(req) self.assertEquals(resp.status_int // 100, 5) # server error @@ -2963,10 +3031,10 @@ class TestObjectController(unittest.TestCase): }) self.app.update_request(req) set_http_connect(200, 422, 422, 503, - etags=['68b329da9893e34099c7d8ad5cb9c940', - '68b329da9893e34099c7d8ad5cb9c941', - None, - None]) + etags=['68b329da9893e34099c7d8ad5cb9c940', + '68b329da9893e34099c7d8ad5cb9c941', + None, + None]) resp = controller.PUT(req) self.assertEquals(resp.status_int // 100, 4) # client error @@ -3001,7 +3069,7 @@ class TestObjectController(unittest.TestCase): with save_globals(): set_http_connect(200, 200, 201, 201, 201) controller = proxy_server.ObjectController(self.app, 'account', - 'container', 'object') + 'container', 'object') req = Request.blank('/a/c/o') req.environ['swift.authorize'] = authorize self.app.update_request(req) @@ -3017,7 +3085,7 @@ class TestObjectController(unittest.TestCase): with save_globals(): set_http_connect(200, 200, 201, 201, 201) controller = proxy_server.ObjectController(self.app, 'account', - 'container', 'object') + 'container', 'object') req = Request.blank('/a/c/o', {'REQUEST_METHOD': 'HEAD'}) req.environ['swift.authorize'] = authorize self.app.update_request(req) @@ -3034,7 +3102,7 @@ class TestObjectController(unittest.TestCase): self.app.object_post_as_copy = False set_http_connect(200, 200, 201, 201, 201) controller = proxy_server.ObjectController(self.app, 'account', - 'container', 'object') + 'container', 'object') req = Request.blank('/a/c/o', environ={'REQUEST_METHOD': 'POST'}, headers={'Content-Length': '5'}, body='12345') req.environ['swift.authorize'] = authorize @@ -3051,7 +3119,7 @@ class TestObjectController(unittest.TestCase): with save_globals(): set_http_connect(200, 200, 200, 200, 200, 201, 201, 201) controller = proxy_server.ObjectController(self.app, 'account', - 'container', 'object') + 'container', 'object') req = Request.blank('/a/c/o', environ={'REQUEST_METHOD': 'POST'}, headers={'Content-Length': '5'}, body='12345') req.environ['swift.authorize'] = authorize @@ -3068,7 +3136,7 @@ class TestObjectController(unittest.TestCase): with save_globals(): set_http_connect(200, 200, 201, 201, 201) controller = proxy_server.ObjectController(self.app, 'account', - 'container', 'object') + 'container', 'object') req = Request.blank('/a/c/o', environ={'REQUEST_METHOD': 'PUT'}, headers={'Content-Length': '5'}, body='12345') req.environ['swift.authorize'] = authorize @@ -3085,7 +3153,7 @@ class TestObjectController(unittest.TestCase): with save_globals(): set_http_connect(200, 200, 200, 200, 200, 201, 201, 201) controller = proxy_server.ObjectController(self.app, 'account', - 'container', 'object') + 'container', 'object') req = Request.blank('/a/c/o', environ={'REQUEST_METHOD': 'COPY'}, headers={'Destination': 'c/o'}) req.environ['swift.authorize'] = authorize @@ -3096,7 +3164,7 @@ class TestObjectController(unittest.TestCase): def test_POST_converts_delete_after_to_delete_at(self): with save_globals(): controller = proxy_server.ObjectController(self.app, 'account', - 'container', 'object') + 'container', 'object') set_http_connect(200, 200, 200, 200, 200, 202, 202, 202) self.app.memcache.store = {} orig_time = proxy_server.time.time @@ -3104,7 +3172,8 @@ class TestObjectController(unittest.TestCase): t = time() proxy_server.time.time = lambda: t req = Request.blank('/a/c/o', {}, - headers={'Content-Type': 'foo/bar', 'X-Delete-After': '60'}) + headers={'Content-Type': 'foo/bar', + 'X-Delete-After': '60'}) self.app.update_request(req) res = controller.POST(req) self.assertEquals(res.status, '202 Fake') @@ -3113,11 +3182,13 @@ class TestObjectController(unittest.TestCase): self.app.object_post_as_copy = False controller = proxy_server.ObjectController(self.app, 'account', - 'container', 'object') + 'container', + 'object') set_http_connect(200, 200, 202, 202, 202) self.app.memcache.store = {} req = Request.blank('/a/c/o', {}, - headers={'Content-Type': 'foo/bar', 'X-Delete-After': '60'}) + headers={'Content-Type': 'foo/bar', + 'X-Delete-After': '60'}) self.app.update_request(req) res = controller.POST(req) self.assertEquals(res.status, '202 Fake') @@ -3129,11 +3200,12 @@ class TestObjectController(unittest.TestCase): def test_POST_non_int_delete_after(self): with save_globals(): controller = proxy_server.ObjectController(self.app, 'account', - 'container', 'object') + 'container', 'object') set_http_connect(200, 200, 200, 200, 200, 202, 202, 202) self.app.memcache.store = {} req = Request.blank('/a/c/o', {}, - headers={'Content-Type': 'foo/bar', 'X-Delete-After': '60.1'}) + headers={'Content-Type': 'foo/bar', + 'X-Delete-After': '60.1'}) self.app.update_request(req) res = controller.POST(req) self.assertEquals(res.status, '400 Bad Request') @@ -3142,11 +3214,12 @@ class TestObjectController(unittest.TestCase): def test_POST_negative_delete_after(self): with save_globals(): controller = proxy_server.ObjectController(self.app, 'account', - 'container', 'object') + 'container', 'object') set_http_connect(200, 200, 200, 200, 200, 202, 202, 202) self.app.memcache.store = {} req = Request.blank('/a/c/o', {}, - headers={'Content-Type': 'foo/bar', 'X-Delete-After': '-60'}) + headers={'Content-Type': 'foo/bar', + 'X-Delete-After': '-60'}) self.app.update_request(req) res = controller.POST(req) self.assertEquals(res.status, '400 Bad Request') @@ -3162,13 +3235,14 @@ class TestObjectController(unittest.TestCase): self.app.object_post_as_copy = False controller = proxy_server.ObjectController(self.app, 'account', - 'container', 'object') + 'container', 'object') controller.make_requests = fake_make_requests set_http_connect(200, 200) self.app.memcache.store = {} t = str(int(time() + 100)) req = Request.blank('/a/c/o', {}, - headers={'Content-Type': 'foo/bar', 'X-Delete-At': t}) + headers={'Content-Type': 'foo/bar', + 'X-Delete-At': t}) self.app.update_request(req) controller.POST(req) self.assertEquals(given_headers.get('X-Delete-At'), t) @@ -3178,7 +3252,8 @@ class TestObjectController(unittest.TestCase): t = str(int(time() + 100)) + '.1' req = Request.blank('/a/c/o', {}, - headers={'Content-Type': 'foo/bar', 'X-Delete-At': t}) + headers={'Content-Type': 'foo/bar', + 'X-Delete-At': t}) self.app.update_request(req) resp = controller.POST(req) self.assertEquals(resp.status_int, 400) @@ -3186,7 +3261,8 @@ class TestObjectController(unittest.TestCase): t = str(int(time() - 100)) req = Request.blank('/a/c/o', {}, - headers={'Content-Type': 'foo/bar', 'X-Delete-At': t}) + headers={'Content-Type': 'foo/bar', + 'X-Delete-At': t}) self.app.update_request(req) resp = controller.POST(req) self.assertEquals(resp.status_int, 400) @@ -3195,7 +3271,7 @@ class TestObjectController(unittest.TestCase): def test_PUT_converts_delete_after_to_delete_at(self): with save_globals(): controller = proxy_server.ObjectController(self.app, 'account', - 'container', 'object') + 'container', 'object') set_http_connect(200, 200, 201, 201, 201) self.app.memcache.store = {} orig_time = proxy_server.time.time @@ -3203,8 +3279,9 @@ class TestObjectController(unittest.TestCase): t = time() proxy_server.time.time = lambda: t req = Request.blank('/a/c/o', {}, - headers={'Content-Length': '0', 'Content-Type': 'foo/bar', - 'X-Delete-After': '60'}) + headers={'Content-Length': '0', + 'Content-Type': 'foo/bar', + 'X-Delete-After': '60'}) self.app.update_request(req) res = controller.PUT(req) self.assertEquals(res.status, '201 Fake') @@ -3216,12 +3293,13 @@ class TestObjectController(unittest.TestCase): def test_PUT_non_int_delete_after(self): with save_globals(): controller = proxy_server.ObjectController(self.app, 'account', - 'container', 'object') + 'container', 'object') set_http_connect(200, 200, 201, 201, 201) self.app.memcache.store = {} req = Request.blank('/a/c/o', {}, - headers={'Content-Length': '0', 'Content-Type': 'foo/bar', - 'X-Delete-After': '60.1'}) + headers={'Content-Length': '0', + 'Content-Type': 'foo/bar', + 'X-Delete-After': '60.1'}) self.app.update_request(req) res = controller.PUT(req) self.assertEquals(res.status, '400 Bad Request') @@ -3230,12 +3308,13 @@ class TestObjectController(unittest.TestCase): def test_PUT_negative_delete_after(self): with save_globals(): controller = proxy_server.ObjectController(self.app, 'account', - 'container', 'object') + 'container', 'object') set_http_connect(200, 200, 201, 201, 201) self.app.memcache.store = {} req = Request.blank('/a/c/o', {}, - headers={'Content-Length': '0', 'Content-Type': 'foo/bar', - 'X-Delete-After': '-60'}) + headers={'Content-Length': '0', + 'Content-Type': 'foo/bar', + 'X-Delete-After': '-60'}) self.app.update_request(req) res = controller.PUT(req) self.assertEquals(res.status, '400 Bad Request') @@ -3250,14 +3329,15 @@ class TestObjectController(unittest.TestCase): given_headers.update(headers) controller = proxy_server.ObjectController(self.app, 'account', - 'container', 'object') + 'container', 'object') controller._connect_put_node = fake_connect_put_node set_http_connect(200, 200) self.app.memcache.store = {} t = str(int(time() + 100)) req = Request.blank('/a/c/o', {}, - headers={'Content-Length': '0', 'Content-Type': 'foo/bar', - 'X-Delete-At': t}) + headers={'Content-Length': '0', + 'Content-Type': 'foo/bar', + 'X-Delete-At': t}) self.app.update_request(req) controller.PUT(req) self.assertEquals(given_headers.get('X-Delete-At'), t) @@ -3267,8 +3347,9 @@ class TestObjectController(unittest.TestCase): t = str(int(time() + 100)) + '.1' req = Request.blank('/a/c/o', {}, - headers={'Content-Length': '0', 'Content-Type': 'foo/bar', - 'X-Delete-At': t}) + headers={'Content-Length': '0', + 'Content-Type': 'foo/bar', + 'X-Delete-At': t}) self.app.update_request(req) resp = controller.PUT(req) self.assertEquals(resp.status_int, 400) @@ -3276,8 +3357,9 @@ class TestObjectController(unittest.TestCase): t = str(int(time() - 100)) req = Request.blank('/a/c/o', {}, - headers={'Content-Length': '0', 'Content-Type': 'foo/bar', - 'X-Delete-At': t}) + headers={'Content-Length': '0', + 'Content-Type': 'foo/bar', + 'X-Delete-At': t}) self.app.update_request(req) resp = controller.PUT(req) self.assertEquals(resp.status_int, 400) @@ -3321,13 +3403,15 @@ class TestObjectController(unittest.TestCase): sock.close() self.assertEquals(before_request_instances, _request_instances) + class TestContainerController(unittest.TestCase): "Test swift.proxy_server.ContainerController" def setUp(self): self.app = proxy_server.Application(None, FakeMemcache(), - account_ring=FakeRing(), container_ring=FakeRing(), - object_ring=FakeRing()) + account_ring=FakeRing(), + container_ring=FakeRing(), + object_ring=FakeRing()) def assert_status_map(self, method, statuses, expected, raise_exc=False, missing_container=False): @@ -3339,14 +3423,14 @@ class TestContainerController(unittest.TestCase): set_http_connect(*statuses, **kwargs) self.app.memcache.store = {} req = Request.blank('/a/c', headers={'Content-Length': '0', - 'Content-Type': 'text/plain'}) + 'Content-Type': 'text/plain'}) self.app.update_request(req) res = method(req) self.assertEquals(res.status_int, expected) set_http_connect(*statuses, **kwargs) self.app.memcache.store = {} req = Request.blank('/a/c/', headers={'Content-Length': '0', - 'Content-Type': 'text/plain'}) + 'Content-Type': 'text/plain'}) self.app.update_request(req) res = method(req) self.assertEquals(res.status_int, expected) @@ -3354,7 +3438,7 @@ class TestContainerController(unittest.TestCase): def test_HEAD(self): with save_globals(): controller = proxy_server.ContainerController(self.app, 'account', - 'container') + 'container') def test_status_map(statuses, expected, **kwargs): set_http_connect(*statuses, **kwargs) @@ -3448,10 +3532,11 @@ class TestContainerController(unittest.TestCase): del dev['errors'] del dev['last_error'] controller = proxy_server.ContainerController(self.app, - 'account', 'container') + 'account', + 'container') if meth == 'PUT': set_http_connect(200, 200, 200, 200, 200, 200, - missing_container=True) + missing_container=True) else: set_http_connect(200, 200, 200, 200) self.app.memcache.store = {} @@ -3585,7 +3670,11 @@ class TestContainerController(unittest.TestCase): for test_header, test_value in ( ('X-Container-Meta-TestHeader', 'TestValue'), ('X-Container-Meta-TestHeader', ''), - ('X-Remove-Container-Meta-TestHeader', 'anything')): + ('X-Remove-Container-Meta-TestHeader', 'anything'), + ('X-Container-Read', '.r:*'), + ('X-Remove-Container-Read', 'anything'), + ('X-Container-Write', 'anyone'), + ('X-Remove-Container-Write', 'anything')): test_errors = [] def test_connect(ipaddr, port, device, partition, method, path, @@ -3609,7 +3698,7 @@ class TestContainerController(unittest.TestCase): proxy_server.ContainerController(self.app, 'a', 'c') set_http_connect(200, 201, 201, 201, give_connect=test_connect) req = Request.blank('/a/c', environ={'REQUEST_METHOD': method}, - headers={test_header: test_value}) + headers={test_header: test_value}) self.app.update_request(req) res = getattr(controller, method)(req) self.assertEquals(test_errors, []) @@ -3631,14 +3720,14 @@ class TestContainerController(unittest.TestCase): set_http_connect(201, 201, 201) req = Request.blank('/a/c', environ={'REQUEST_METHOD': method}, - headers={'X-Container-Meta-' + + headers={'X-Container-Meta-' + ('a' * MAX_META_NAME_LENGTH): 'v'}) self.app.update_request(req) resp = getattr(controller, method)(req) self.assertEquals(resp.status_int, 201) set_http_connect(201, 201, 201) req = Request.blank('/a/c', environ={'REQUEST_METHOD': method}, - headers={'X-Container-Meta-' + + headers={'X-Container-Meta-' + ('a' * (MAX_META_NAME_LENGTH + 1)): 'v'}) self.app.update_request(req) resp = getattr(controller, method)(req) @@ -3646,14 +3735,14 @@ class TestContainerController(unittest.TestCase): set_http_connect(201, 201, 201) req = Request.blank('/a/c', environ={'REQUEST_METHOD': method}, - headers={'X-Container-Meta-Too-Long': + headers={'X-Container-Meta-Too-Long': 'a' * MAX_META_VALUE_LENGTH}) self.app.update_request(req) resp = getattr(controller, method)(req) self.assertEquals(resp.status_int, 201) set_http_connect(201, 201, 201) req = Request.blank('/a/c', environ={'REQUEST_METHOD': method}, - headers={'X-Container-Meta-Too-Long': + headers={'X-Container-Meta-Too-Long': 'a' * (MAX_META_VALUE_LENGTH + 1)}) self.app.update_request(req) resp = getattr(controller, method)(req) @@ -3808,8 +3897,9 @@ class TestAccountController(unittest.TestCase): def setUp(self): self.app = proxy_server.Application(None, FakeMemcache(), - account_ring=FakeRing(), container_ring=FakeRing(), - object_ring=FakeRing) + account_ring=FakeRing(), + container_ring=FakeRing(), + object_ring=FakeRing) def assert_status_map(self, method, statuses, expected): with save_globals(): @@ -3850,15 +3940,14 @@ class TestAccountController(unittest.TestCase): controller = proxy_server.AccountController(self.app, 'account') self.app.memcache = FakeMemcacheReturnsNone() self.assert_status_map(controller.GET, - (404, 404, 404, 201, 201, 201, 204), 404) + (404, 404, 404, 201, 201, 201, 204), 404) controller.app.account_autocreate = True self.assert_status_map(controller.GET, - (404, 404, 404, 201, 201, 201, 204), 204) + (404, 404, 404, 201, 201, 201, 204), 204) self.assert_status_map(controller.GET, - (404, 404, 404, 403, 403, 403, 403), 403) + (404, 404, 404, 403, 403, 403, 403), 403) self.assert_status_map(controller.GET, - (404, 404, 404, 409, 409, 409, 409), 409) - + (404, 404, 404, 409, 409, 409, 409), 409) def test_HEAD(self): with save_globals(): @@ -3883,28 +3972,28 @@ class TestAccountController(unittest.TestCase): controller = proxy_server.AccountController(self.app, 'account') self.app.memcache = FakeMemcacheReturnsNone() self.assert_status_map(controller.HEAD, - (404, 404, 404, 201, 201, 201, 204), 404) + (404, 404, 404, 201, 201, 201, 204), 404) controller.app.account_autocreate = True self.assert_status_map(controller.HEAD, - (404, 404, 404, 201, 201, 201, 204), 204) + (404, 404, 404, 201, 201, 201, 204), 204) self.assert_status_map(controller.HEAD, - (404, 404, 404, 403, 403, 403, 403), 403) + (404, 404, 404, 403, 403, 403, 403), 403) self.assert_status_map(controller.HEAD, - (404, 404, 404, 409, 409, 409, 409), 409) + (404, 404, 404, 409, 409, 409, 409), 409) def test_POST_autocreate(self): with save_globals(): controller = proxy_server.AccountController(self.app, 'account') self.app.memcache = FakeMemcacheReturnsNone() self.assert_status_map(controller.POST, - (404, 404, 404, 201, 201, 201), 404) + (404, 404, 404, 201, 201, 201), 404) controller.app.account_autocreate = True self.assert_status_map(controller.POST, - (404, 404, 404, 201, 201, 201), 201) + (404, 404, 404, 201, 201, 201), 201) self.assert_status_map(controller.POST, - (404, 404, 404, 403, 403, 403, 403), 403) + (404, 404, 404, 403, 403, 403, 403), 403) self.assert_status_map(controller.POST, - (404, 404, 404, 409, 409, 409, 409), 409) + (404, 404, 404, 409, 409, 409, 409), 409) def test_connection_refused(self): self.app.account_ring.get_nodes('account') @@ -4022,7 +4111,7 @@ class TestAccountController(unittest.TestCase): proxy_server.AccountController(self.app, 'a') set_http_connect(201, 201, 201, give_connect=test_connect) req = Request.blank('/a/c', environ={'REQUEST_METHOD': method}, - headers={test_header: test_value}) + headers={test_header: test_value}) self.app.update_request(req) res = getattr(controller, method)(req) self.assertEquals(test_errors, []) @@ -4045,14 +4134,14 @@ class TestAccountController(unittest.TestCase): set_http_connect(201, 201, 201) req = Request.blank('/a/c', environ={'REQUEST_METHOD': method}, - headers={'X-Account-Meta-' + + headers={'X-Account-Meta-' + ('a' * MAX_META_NAME_LENGTH): 'v'}) self.app.update_request(req) resp = getattr(controller, method)(req) self.assertEquals(resp.status_int, 201) set_http_connect(201, 201, 201) req = Request.blank('/a/c', environ={'REQUEST_METHOD': method}, - headers={'X-Account-Meta-' + + headers={'X-Account-Meta-' + ('a' * (MAX_META_NAME_LENGTH + 1)): 'v'}) self.app.update_request(req) resp = getattr(controller, method)(req) @@ -4060,14 +4149,14 @@ class TestAccountController(unittest.TestCase): set_http_connect(201, 201, 201) req = Request.blank('/a/c', environ={'REQUEST_METHOD': method}, - headers={'X-Account-Meta-Too-Long': + headers={'X-Account-Meta-Too-Long': 'a' * MAX_META_VALUE_LENGTH}) self.app.update_request(req) resp = getattr(controller, method)(req) self.assertEquals(resp.status_int, 201) set_http_connect(201, 201, 201) req = Request.blank('/a/c', environ={'REQUEST_METHOD': method}, - headers={'X-Account-Meta-Too-Long': + headers={'X-Account-Meta-Too-Long': 'a' * (MAX_META_VALUE_LENGTH + 1)}) self.app.update_request(req) resp = getattr(controller, method)(req) @@ -4189,19 +4278,19 @@ class TestSegmentedIterable(unittest.TestCase): def test_load_next_segment_unexpected_error(self): # Iterator value isn't a dict self.assertRaises(Exception, - SegmentedIterable(self.controller, None, - [None])._load_next_segment) + SegmentedIterable(self.controller, None, + [None])._load_next_segment) self.assert_(self.controller.exception_args[0].startswith( - 'ERROR: While processing manifest')) + 'ERROR: While processing manifest')) def test_load_next_segment_with_no_segments(self): self.assertRaises(StopIteration, - SegmentedIterable(self.controller, 'lc', - [])._load_next_segment) + SegmentedIterable(self.controller, 'lc', + [])._load_next_segment) def test_load_next_segment_with_one_segment(self): segit = SegmentedIterable(self.controller, 'lc', [{'name': - 'o1'}]) + 'o1'}]) segit._load_next_segment() self.assertEquals(self.controller.GETorHEAD_base_args[4], '/a/lc/o1') data = ''.join(segit.segment_iter) @@ -4209,7 +4298,7 @@ class TestSegmentedIterable(unittest.TestCase): def test_load_next_segment_with_two_segments(self): segit = SegmentedIterable(self.controller, 'lc', [{'name': - 'o1'}, {'name': 'o2'}]) + 'o1'}, {'name': 'o2'}]) segit._load_next_segment() self.assertEquals(self.controller.GETorHEAD_base_args[4], '/a/lc/o1') data = ''.join(segit.segment_iter) @@ -4221,6 +4310,7 @@ class TestSegmentedIterable(unittest.TestCase): def test_load_next_segment_rate_limiting(self): sleep_calls = [] + def _stub_sleep(sleepy_time): sleep_calls.append(sleepy_time) orig_sleep = swift.proxy.controllers.obj.sleep @@ -4231,28 +4321,31 @@ class TestSegmentedIterable(unittest.TestCase): {'name': 'o1'}, {'name': 'o2'}, {'name': 'o3'}, {'name': 'o4'}, {'name': 'o5'}]) - # rate_limit_after_segment == 3, so the first 3 segments should invoke - # no sleeping. + # rate_limit_after_segment == 3, so the first 3 segments should + # invoke no sleeping. for _ in xrange(3): segit._load_next_segment() self.assertEquals([], sleep_calls) - self.assertEquals(self.controller.GETorHEAD_base_args[4], '/a/lc/o3') + self.assertEquals(self.controller.GETorHEAD_base_args[4], + '/a/lc/o3') # Loading of next (4th) segment starts rate-limiting. segit._load_next_segment() self.assertAlmostEqual(0.5, sleep_calls[0], places=2) - self.assertEquals(self.controller.GETorHEAD_base_args[4], '/a/lc/o4') + self.assertEquals(self.controller.GETorHEAD_base_args[4], + '/a/lc/o4') sleep_calls = [] segit._load_next_segment() self.assertAlmostEqual(0.5, sleep_calls[0], places=2) - self.assertEquals(self.controller.GETorHEAD_base_args[4], '/a/lc/o5') + self.assertEquals(self.controller.GETorHEAD_base_args[4], + '/a/lc/o5') finally: swift.proxy.controllers.obj.sleep = orig_sleep def test_load_next_segment_with_two_segments_skip_first(self): segit = SegmentedIterable(self.controller, 'lc', [{'name': - 'o1'}, {'name': 'o2'}]) + 'o1'}, {'name': 'o2'}]) segit.segment = 0 segit.listing.next() segit._load_next_segment() @@ -4262,14 +4355,14 @@ class TestSegmentedIterable(unittest.TestCase): def test_load_next_segment_with_seek(self): segit = SegmentedIterable(self.controller, 'lc', [{'name': - 'o1'}, {'name': 'o2'}]) + 'o1'}, {'name': 'o2'}]) segit.segment = 0 segit.listing.next() segit.seek = 1 segit._load_next_segment() self.assertEquals(self.controller.GETorHEAD_base_args[4], '/a/lc/o2') self.assertEquals(str(self.controller.GETorHEAD_base_args[0].range), - 'bytes=1-') + 'bytes=1-') data = ''.join(segit.segment_iter) self.assertEquals(data, '2') @@ -4280,17 +4373,17 @@ class TestSegmentedIterable(unittest.TestCase): self.controller.GETorHEAD_base = local_GETorHEAD_base self.assertRaises(Exception, - SegmentedIterable(self.controller, 'lc', [{'name': - 'o1'}])._load_next_segment) + SegmentedIterable(self.controller, 'lc', + [{'name': 'o1'}])._load_next_segment) self.assert_(self.controller.exception_args[0].startswith( - 'ERROR: While processing manifest')) + 'ERROR: While processing manifest')) self.assertEquals(str(self.controller.exception_info[1]), - 'Could not load object segment /a/lc/o1: 404') + 'Could not load object segment /a/lc/o1: 404') def test_iter_unexpected_error(self): # Iterator value isn't a dict self.assertRaises(Exception, ''.join, - SegmentedIterable(self.controller, None, [None])) + SegmentedIterable(self.controller, None, [None])) self.assert_(self.controller.exception_args[0].startswith( 'ERROR: While processing manifest')) @@ -4300,13 +4393,13 @@ class TestSegmentedIterable(unittest.TestCase): def test_iter_with_one_segment(self): segit = SegmentedIterable(self.controller, 'lc', [{'name': - 'o1'}]) + 'o1'}]) segit.response = Stub() self.assertEquals(''.join(segit), '1') def test_iter_with_two_segments(self): segit = SegmentedIterable(self.controller, 'lc', [{'name': - 'o1'}, {'name': 'o2'}]) + 'o1'}, {'name': 'o2'}]) segit.response = Stub() self.assertEquals(''.join(segit), '122') @@ -4317,18 +4410,19 @@ class TestSegmentedIterable(unittest.TestCase): self.controller.GETorHEAD_base = local_GETorHEAD_base self.assertRaises(Exception, ''.join, - SegmentedIterable(self.controller, 'lc', [{'name': - 'o1'}])) + SegmentedIterable(self.controller, 'lc', [{'name': + 'o1'}])) self.assert_(self.controller.exception_args[0].startswith( - 'ERROR: While processing manifest')) + 'ERROR: While processing manifest')) self.assertEquals(str(self.controller.exception_info[1]), - 'Could not load object segment /a/lc/o1: 404') + 'Could not load object segment /a/lc/o1: 404') def test_app_iter_range_unexpected_error(self): # Iterator value isn't a dict self.assertRaises(Exception, - SegmentedIterable(self.controller, None, - [None]).app_iter_range(None, None).next) + SegmentedIterable(self.controller, None, + [None]).app_iter_range(None, + None).next) self.assert_(self.controller.exception_args[0].startswith( 'ERROR: While processing manifest')) @@ -4380,18 +4474,18 @@ class TestSegmentedIterable(unittest.TestCase): def test_app_iter_range_with_many_segments(self): listing = [{'name': 'o1', 'bytes': 1}, {'name': 'o2', 'bytes': 2}, - {'name': 'o3', 'bytes': 3}, {'name': 'o4', 'bytes': 4}, {'name': - 'o5', 'bytes': 5}] + {'name': 'o3', 'bytes': 3}, {'name': 'o4', 'bytes': 4}, + {'name': 'o5', 'bytes': 5}] segit = SegmentedIterable(self.controller, 'lc', listing) segit.response = Stub() self.assertEquals(''.join(segit.app_iter_range(None, None)), - '122333444455555') + '122333444455555') segit = SegmentedIterable(self.controller, 'lc', listing) segit.response = Stub() self.assertEquals(''.join(segit.app_iter_range(3, None)), - '333444455555') + '333444455555') segit = SegmentedIterable(self.controller, 'lc', listing) segit.response = Stub()