diff --git a/swift/proxy/server.py b/swift/proxy/server.py index 1c9da3f12e..3668ac81b5 100644 --- a/swift/proxy/server.py +++ b/swift/proxy/server.py @@ -1397,19 +1397,18 @@ class ObjectController(Controller): lcontainer = object_versions.split('/')[0] prefix_len = '%03x' % len(self.object_name) lprefix = prefix_len + self.object_name + '/' + last_item = None try: - raw_listing = self._listing_iter(lcontainer, lprefix, - req.environ) + for last_item in self._listing_iter(lcontainer, lprefix, + req.environ): + pass except ListingIterNotFound: - # set raw_listing so that the actual object is deleted - raw_listing = [] + # no worries, last_item is None + pass except ListingIterNotAuthorized, err: return err.aresp except ListingIterError: return HTTPServerError(request=req) - last_item = None - for item in raw_listing: # find the last item - last_item = item if last_item: # there are older versions so copy the previous version to the # current object and delete the previous version diff --git a/test/unit/proxy/test_server.py b/test/unit/proxy/test_server.py index 4019b0408f..8738091a61 100644 --- a/test/unit/proxy/test_server.py +++ b/test/unit/proxy/test_server.py @@ -2622,6 +2622,46 @@ class TestObjectController(unittest.TestCase): versions = [x for x in body.split('\n') if x] self.assertEquals(len(versions), 1) + # Check for when the versions target container doesn't exist + sock = connect_tcp(('localhost', prolis.getsockname()[1])) + fd = sock.makefile() + fd.write('PUT /v1/a/whoops HTTP/1.1\r\nHost: localhost\r\n' + 'Connection: close\r\nX-Storage-Token: t\r\n' + 'Content-Length: 0\r\nX-Versions-Location: none\r\n\r\n') + fd.flush() + headers = readuntil2crlfs(fd) + exp = 'HTTP/1.1 201' + self.assertEquals(headers[:len(exp)], exp) + # Create the versioned file + 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') + fd.flush() + headers = readuntil2crlfs(fd) + exp = 'HTTP/1.1 201' + self.assertEquals(headers[:len(exp)], exp) + # Create another version + 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') + fd.flush() + headers = readuntil2crlfs(fd) + exp = 'HTTP/1.1 412' + self.assertEquals(headers[:len(exp)], exp) + # 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.flush() + headers = readuntil2crlfs(fd) + exp = 'HTTP/1.1 2' # 2xx response + self.assertEquals(headers[:len(exp)], exp) + def test_chunked_put_lobjects(self): # Create a container for our segmented/manifest object testing (prolis, acc1lis, acc2lis, con2lis, con2lis, obj1lis, obj2lis) = \