fix dlo manifest file getting versioned

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>
This commit is contained in:
Thiago da Silva 2014-12-08 21:29:30 -05:00
parent cc2f0f4ed6
commit 24330771af
3 changed files with 47 additions and 13 deletions

View File

@ -515,7 +515,9 @@ class ObjectController(Controller):
req.headers['X-Timestamp'] = Timestamp(time.time()).internal req.headers['X-Timestamp'] = Timestamp(time.time()).internal
if object_versions and not req.environ.get('swift_versioned_copy'): 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 # This is a version manifest and needs to be handled
# differently. First copy the existing data to a new object, # differently. First copy the existing data to a new object,
# then write the data from this request to the version manifest # then write the data from this request to the version manifest

View File

@ -2515,6 +2515,34 @@ class TestObjectVersioning(Base):
versioned_obj.delete() versioned_obj.delete()
self.assertRaises(ResponseError, versioned_obj.read) 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): class TestObjectVersioningUTF8(Base2, TestObjectVersioning):
set_up = False set_up = False

View File

@ -4249,18 +4249,22 @@ class TestObjectController(unittest.TestCase):
exp = 'HTTP/1.1 404' exp = 'HTTP/1.1 404'
self.assertEquals(headers[:len(exp)], exp) self.assertEquals(headers[:len(exp)], exp)
# make sure manifest files don't get versioned # make sure dlo manifest files don't get versioned
sock = connect_tcp(('localhost', prolis.getsockname()[1])) for _junk in xrange(1, versions_to_create):
fd = sock.makefile() sleep(.01) # guarantee that the timestamp changes
fd.write('PUT /v1/a/%s/%s HTTP/1.1\r\nHost: ' sock = connect_tcp(('localhost', prolis.getsockname()[1]))
'localhost\r\nConnection: close\r\nX-Storage-Token: ' fd = sock.makefile()
't\r\nContent-Length: 0\r\nContent-Type: text/jibberish0\r\n' fd.write('PUT /v1/a/%s/%s HTTP/1.1\r\nHost: '
'Foo: barbaz\r\nX-Object-Manifest: %s/foo_\r\n\r\n' 'localhost\r\nConnection: close\r\nX-Storage-Token: '
% (oc, vc, o)) 't\r\nContent-Length: 0\r\n'
fd.flush() 'Content-Type: text/jibberish0\r\n'
headers = readuntil2crlfs(fd) 'Foo: barbaz\r\nX-Object-Manifest: %s/%s/\r\n\r\n'
exp = 'HTTP/1.1 201' % (oc, o, oc, o))
self.assertEquals(headers[:len(exp)], exp) fd.flush()
headers = readuntil2crlfs(fd)
exp = 'HTTP/1.1 201'
self.assertEquals(headers[:len(exp)], exp)
# Ensure we have no saved versions # Ensure we have no saved versions
sock = connect_tcp(('localhost', prolis.getsockname()[1])) sock = connect_tcp(('localhost', prolis.getsockname()[1]))
fd = sock.makefile() fd = sock.makefile()