def test_list_no_versions_with_delimiter(self): self.app.register( 'GET', '/v1/a/c?delimiter=%2F&format=json', swob.HTTPOk, {}, '''[ {"subdir": "v1/"}, {"hash": "8de4989188593b0419d387099c9e9872", "name": "magic", "last_modified": "2018-11-14T16:20:43.000000", "bytes": 113, "version": 1542212443748591, "content_type": "text/plain"} ]''') cache = FakeCache({ 'sysmeta': { 'versions-location': 'c' + versioned_writes.VERSIONING_SUFFIX } }) req = Request.blank('/v1/a/c' + versioned_writes.VERSIONING_SUFFIX + '?delimiter=%2F', environ={ 'REQUEST_METHOD': 'GET', 'swift.cache': cache, 'CONTENT_LENGTH': '0' }) status, _headers, body = self.call_vw(req) self.assertEqual(status, '200 OK') # Subdir should be listed here, but the object is the latest # version, and should not be listed either. self.assertEqual('[{"subdir": "v1/"}]', body)
def test_delete_latest_version_no_marker_success(self): self.app.register( 'GET', '/v1/a/ver_cont?prefix=003sym/&marker=&reverse=on', swob.HTTPOk, {}, '[{"hash": "y", ' '"last_modified": "2014-11-21T14:23:02.206740", ' '"bytes": 0, ' '"name": "003sym/2", ' '"content_type": "text/plain"}, ' '{"hash": "x", ' '"last_modified": "2014-11-21T14:14:27.409100", ' '"bytes": 0, ' '"name": "003sym/1", ' '"content_type": "text/plain"}]') self.app.register( 'GET', '/v1/a/ver_cont/003sym/2', swob.HTTPCreated, {'content-length': '0', 'X-Object-Sysmeta-Symlink-Target': 'c/tgt'}, None) self.app.register( 'PUT', '/v1/a/c/sym', swob.HTTPCreated, {'X-Symlink-Target': 'c/tgt', 'X-Symlink-Target-Account': 'a'}, None) self.app.register( 'DELETE', '/v1/a/ver_cont/003sym/2', swob.HTTPOk, {}, None) cache = FakeCache({'sysmeta': {'versions-location': 'ver_cont'}}) req = Request.blank( '/v1/a/c/sym', headers={'X-If-Delete-At': 1}, environ={'REQUEST_METHOD': 'DELETE', 'swift.cache': cache, 'CONTENT_LENGTH': '0', 'swift.trans_id': 'fake_trans_id'}) status, headers, body = self.call_vw(req) self.assertEqual(status, '200 OK') self.assertEqual(len(self.authorized), 1) self.assertRequestEqual(req, self.authorized[0]) self.assertEqual(4, self.app.call_count) self.assertEqual(['VW', 'VW', 'VW', 'VW'], self.app.swift_sources) self.assertEqual({'fake_trans_id'}, set(self.app.txn_ids)) calls = self.app.calls_with_headers method, path, req_headers = calls[2] self.assertEqual('PUT', method) self.assertEqual('/v1/a/c/sym', path) self.assertEqual( 'c/tgt', req_headers['X-Object-Sysmeta-Symlink-Target'])
def test_put_first_object_success(self): self.app.register('PUT', '/v1/a/c/o', swob.HTTPOk, {}, 'passed') self.app.register('GET', '/v1/a/c/o', swob.HTTPNotFound, {}, None) cache = FakeCache({'sysmeta': {'versions-location': 'ver_cont'}}) req = Request.blank('/v1/a/c/o', environ={ 'REQUEST_METHOD': 'PUT', 'swift.cache': cache, 'CONTENT_LENGTH': '100', 'swift.trans_id': 'fake_trans_id' }) status, headers, body = self.call_vw(req) self.assertEqual(status, '200 OK') self.assertEqual(len(self.authorized), 1) self.assertRequestEqual(req, self.authorized[0]) self.assertEqual(1, self.app.call_count) self.assertEqual([None], self.app.swift_sources) self.assertEqual({'fake_trans_id'}, set(self.app.txn_ids))
def test_new_symlink_version_success(self): self.app.register( 'PUT', '/v1/a/c/symlink', swob.HTTPCreated, { 'X-Symlink-Target': 'new_cont/new_tgt', 'X-Symlink-Target-Account': 'a' }, None) self.app.register( 'GET', '/v1/a/c/symlink', swob.HTTPOk, { 'last-modified': 'Thu, 1 Jan 1970 00:00:01 GMT', 'X-Object-Sysmeta-Symlink-Target': 'old_cont/old_tgt', 'X-Object-Sysmeta-Symlink-Target-Account': 'a' }, '') self.app.register( 'PUT', '/v1/a/ver_cont/007symlink/0000000001.00000', swob.HTTPCreated, { 'X-Symlink-Target': 'old_cont/old_tgt', 'X-Symlink-Target-Account': 'a' }, None) cache = FakeCache({'sysmeta': {'versions-location': 'ver_cont'}}) req = Request.blank('/v1/a/c/symlink', headers={'X-Symlink-Target': 'new_cont/new_tgt'}, environ={ 'REQUEST_METHOD': 'PUT', 'swift.cache': cache, 'CONTENT_LENGTH': '0', 'swift.trans_id': 'fake_trans_id' }) status, headers, body = self.call_vw(req) self.assertEqual(status, '201 Created') # authorized twice now because versioned_writes now makes a check on # PUT self.assertEqual(len(self.authorized), 2) self.assertRequestEqual(req, self.authorized[0]) self.assertEqual(['VW', 'VW', None], self.app.swift_sources) self.assertEqual({'fake_trans_id'}, set(self.app.txn_ids)) calls = self.app.calls_with_headers method, path, req_headers = calls[2] self.assertEqual('PUT', method) self.assertEqual('/v1/a/c/symlink', path) self.assertEqual('new_cont/new_tgt', req_headers['X-Object-Sysmeta-Symlink-Target'])
def test_delete_first_object_success(self): self.app.register('DELETE', '/v1/a/c/o', swob.HTTPOk, {}, 'passed') self.app.register( 'GET', '/v1/a/ver_cont?format=json&prefix=001o/&marker=&reverse=on', swob.HTTPOk, {}, '[]') cache = FakeCache({'sysmeta': {'versions-location': 'ver_cont'}}) req = Request.blank('/v1/a/c/o', environ={ 'REQUEST_METHOD': 'DELETE', 'swift.cache': cache, 'CONTENT_LENGTH': '0' }) status, headers, body = self.call_vw(req) self.assertEqual(status, '200 OK') self.assertEqual(len(self.authorized), 1) self.assertRequestEqual(req, self.authorized[0]) self.assertEqual(self.app.calls, [ ('DELETE', '/v1/a/c/o'), ])
def test_put_versioned_object_including_url_encoded_name_success(self): self.app.register('PUT', '/v1/a/c/%ff', swob.HTTPOk, {}, 'passed') self.app.register('GET', '/v1/a/c/%ff', swob.HTTPNotFound, {}, None) cache = FakeCache({'sysmeta': {'versions-location': 'ver_cont'}}) req = Request.blank('/v1/a/c/%25ff', environ={ 'REQUEST_METHOD': 'PUT', 'swift.cache': cache, 'CONTENT_LENGTH': '100', 'swift.trans_id': 'fake_trans_id', 'swift.source': 'test' }) status, headers, body = self.call_vw(req) self.assertEqual(status, '200 OK') # XXX: oioswift's versioned_writes only does one request # (genuine versioned_writes does 2) self.assertEqual(len(self.authorized), 1) self.assertRequestEqual(req, self.authorized[0]) self.assertEqual(1, self.app.call_count) self.assertEqual(['test'], self.app.swift_sources) self.assertEqual({'fake_trans_id'}, set(self.app.txn_ids))
def test_put_request_is_dlo_manifest_with_container_config_true(self): # oio-swift's versioned_writes does not use a version container, # but relies on oio-sds versioning features. It does not do a GET # request since this will be checked internally by oio-sds. self.app.register('PUT', '/v1/a/c/o', swob.HTTPCreated, {}, 'passed') self.app.register('GET', '/v1/a/c/o', swob.HTTPOk, {'last-modified': 'Thu, 1 Jan 1970 00:01:00 GMT'}, 'old version') # self.app.register( # 'PUT', '/v1/a/ver_cont/001o/0000000060.00000', swob.HTTPCreated, # {}, '') cache = FakeCache({'versions': 'ver_cont'}) req = Request.blank('/v1/a/c/o', headers={'X-Object-Manifest': 'req/manifest'}, environ={ 'REQUEST_METHOD': 'PUT', 'swift.cache': cache, 'CONTENT_LENGTH': '100' }) status, headers, body = self.call_vw(req) self.assertEqual(status, '201 Created') # self.assertEqual(len(self.authorized), 2) self.assertEqual(len(self.authorized), 1) self.assertRequestEqual(req, self.authorized[0]) # self.assertRequestEqual(req, self.authorized[1]) # self.assertEqual(3, self.app.call_count) self.assertEqual(1, self.app.call_count) self.assertEqual( [ # ('GET', '/v1/a/c/o'), # ('PUT', '/v1/a/ver_cont/001o/0000000060.00000'), ('PUT', '/v1/a/c/o'), ], self.app.calls) self.assertIn( 'x-object-manifest', # self.app.calls_with_headers[2].headers) self.app.calls_with_headers[0].headers)
def test_new_version_success(self): self.app.register('PUT', '/v1/a/c/o', swob.HTTPCreated, {}, 'passed') self.app.register('GET', '/v1/a/c/o', swob.HTTPOk, {'last-modified': 'Thu, 1 Jan 1970 00:00:01 GMT'}, 'passed') self.app.register('PUT', '/v1/a/ver_cont/001o/0000000001.00000', swob.HTTPCreated, {}, None) cache = FakeCache({'sysmeta': {'versions-location': 'ver_cont'}}) req = Request.blank('/v1/a/c/o', environ={ 'REQUEST_METHOD': 'PUT', 'swift.cache': cache, 'CONTENT_LENGTH': '100', 'swift.trans_id': 'fake_trans_id' }) status, headers, body = self.call_vw(req) self.assertEqual(status, '201 Created') # authorized twice now because versioned_writes now makes a check on # PUT self.assertEqual(len(self.authorized), 1) self.assertRequestEqual(req, self.authorized[0]) self.assertEqual([None], self.app.swift_sources) self.assertEqual({'fake_trans_id'}, set(self.app.txn_ids))