Skip to content

Commit

Permalink
fix dlo manifest file getting versioned
Browse files Browse the repository at this point in the history
According to documentation dlo manifest files should not
be versioned. This patch fixes this issue and adds
some unit and functional for this scenario.

Change-Id: Ib5b29a19e1d577026deb50fc9d26064a8da81cd7
Signed-off-by: Thiago da Silva <thiago@redhat.com>
  • Loading branch information
Thiago da Silva committed Dec 18, 2014
1 parent cc2f0f4 commit 2433077
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 13 deletions.
4 changes: 3 additions & 1 deletion swift/proxy/controllers/obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,9 @@ def PUT(self, req):
req.headers['X-Timestamp'] = Timestamp(time.time()).internal

if object_versions and not req.environ.get('swift_versioned_copy'):
if hresp.status_int != HTTP_NOT_FOUND:
is_manifest = 'X-Object-Manifest' in req.headers or \
'X-Object-Manifest' in hresp.headers
if hresp.status_int != HTTP_NOT_FOUND and not is_manifest:
# This is a version manifest and needs to be handled
# differently. First copy the existing data to a new object,
# then write the data from this request to the version manifest
Expand Down
28 changes: 28 additions & 0 deletions test/functional/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2515,6 +2515,34 @@ def test_overwriting(self):
versioned_obj.delete()
self.assertRaises(ResponseError, versioned_obj.read)

def test_versioning_dlo(self):
container = self.env.container
versions_container = self.env.versions_container
obj_name = Utils.create_name()

for i in ('1', '2', '3'):
time.sleep(.01) # guarantee that the timestamp changes
obj_name_seg = obj_name + '/' + i
versioned_obj = container.file(obj_name_seg)
versioned_obj.write(i)
versioned_obj.write(i + i)

self.assertEqual(3, versions_container.info()['object_count'])

man_file = container.file(obj_name)
man_file.write('', hdrs={"X-Object-Manifest": "%s/%s/" %
(self.env.container.name, obj_name)})

# guarantee that the timestamp changes
time.sleep(.01)

# write manifest file again
man_file.write('', hdrs={"X-Object-Manifest": "%s/%s/" %
(self.env.container.name, obj_name)})

self.assertEqual(3, versions_container.info()['object_count'])
self.assertEqual("112233", man_file.read())


class TestObjectVersioningUTF8(Base2, TestObjectVersioning):
set_up = False
Expand Down
28 changes: 16 additions & 12 deletions test/unit/proxy/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4249,18 +4249,22 @@ def test_version_manifest(self, oc='versions', vc='vers', o='name'):
exp = 'HTTP/1.1 404'
self.assertEquals(headers[:len(exp)], exp)

# make sure manifest files don't get versioned
sock = connect_tcp(('localhost', prolis.getsockname()[1]))
fd = sock.makefile()
fd.write('PUT /v1/a/%s/%s 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: %s/foo_\r\n\r\n'
% (oc, vc, o))
fd.flush()
headers = readuntil2crlfs(fd)
exp = 'HTTP/1.1 201'
self.assertEquals(headers[:len(exp)], exp)
# make sure dlo manifest files don't get versioned
for _junk in xrange(1, versions_to_create):
sleep(.01) # guarantee that the timestamp changes
sock = connect_tcp(('localhost', prolis.getsockname()[1]))
fd = sock.makefile()
fd.write('PUT /v1/a/%s/%s HTTP/1.1\r\nHost: '
'localhost\r\nConnection: close\r\nX-Storage-Token: '
't\r\nContent-Length: 0\r\n'
'Content-Type: text/jibberish0\r\n'
'Foo: barbaz\r\nX-Object-Manifest: %s/%s/\r\n\r\n'
% (oc, o, oc, o))
fd.flush()
headers = readuntil2crlfs(fd)
exp = 'HTTP/1.1 201'
self.assertEquals(headers[:len(exp)], exp)

# Ensure we have no saved versions
sock = connect_tcp(('localhost', prolis.getsockname()[1]))
fd = sock.makefile()
Expand Down

0 comments on commit 2433077

Please sign in to comment.