def _create_ondisk_file(self, df, data, timestamp, metadata=None): """ create the data amd meta data file""" if timestamp is None: timestamp = time() timestamp = normalize_timestamp(timestamp) if not metadata: metadata = {} if 'X-Timestamp' not in metadata: metadata['X-Timestamp'] = normalize_timestamp(timestamp) if 'ETag' not in metadata: etag = md5() etag.update(data) metadata['ETag'] = etag.hexdigest() if 'name' not in metadata: metadata['name'] = '/a/c/o' if 'Content-Length' not in metadata: metadata['Content-Length'] = str(len(data)) hash_name = df._name_hash mkdirs(df._datadir) mkdirs(df._metadir) data_file = os.path.join(df._datadir, df._name_hash + ".data") meta_file = os.path.join(df._metadir, df._name_hash + ".meta") with open(data_file, 'wb') as f: f.write(data) with open(meta_file, 'wb') as f: f.write(pickle.dumps(metadata, diskfile.PICKLE_PROTOCOL)) f.write("EOF")
def test_POST_old_timestamp(self): ts = time() timestamp = normalize_timestamp(ts) req = Request.blank('/fs1/a1/d1/o1/a/c/o', environ={ 'REQUEST_METHOD': 'PUT', 'HTTP_X_GLOBAL_MAP_VERSION': 4.0 }, headers={ 'X-Timestamp': timestamp, 'Content-Type': 'application/x-test', 'X-Object-Meta-1': 'One', 'X-Object-Meta-Two': 'Two', 'X-Container-Host': '1.2.3:0000' }) req.body = 'VERIFY' resp = req.get_response(self.object_controller) self.assertEquals(resp.status_int, 201) # Same timestamp should result in 409 req = Request.blank('/fs1/a1/d1/o1/a/c/o', environ={ 'REQUEST_METHOD': 'POST', 'HTTP_X_GLOBAL_MAP_VERSION': 4.0 }, headers={ 'X-Timestamp': timestamp, 'X-Object-Meta-3': 'Three', 'X-Object-Meta-4': 'Four', 'Content-Encoding': 'gzip', 'Content-Type': 'application/x-test', 'X-Container-Host': '1.2.3:0000' }) resp = req.get_response(self.object_controller) self.assertEquals(resp.status_int, 409) # Earlier timestamp should result in 409 timestamp = normalize_timestamp(ts - 1) req = Request.blank('/fs1/a1/d1/o1/a/c/o', environ={ 'REQUEST_METHOD': 'POST', 'HTTP_X_GLOBAL_MAP_VERSION': 4.0 }, headers={ 'X-Timestamp': timestamp, 'X-Object-Meta-5': 'Five', 'X-Object-Meta-6': 'Six', 'Content-Encoding': 'gzip', 'Content-Type': 'application/x-test', 'X-Container-Host': '1.2.3:0000' }) resp = req.get_response(self.object_controller) self.assertEquals(resp.status_int, 409)
def create_container_record(cls, name, hash, info, deleted): """An interface to create an object of ContainerRecord, from info map""" if 'x-object-count' not in info: info['x-object-count'] = 0 if not info['x-put-timestamp']: info['x-put-timestamp'] = '0' if not info['x-delete-timestamp']: info['x-delete-timestamp'] = '0' return libaccountLib.ContainerRecord(0, name, hash, \ normalize_timestamp(str(info['x-put-timestamp'])), \ normalize_timestamp(str(info['x-delete-timestamp'])), \ long(info['x-object-count']), \ long(info['x-bytes-used']), deleted)
def test_DELETE_File_Not_Exists(self): with mock.patch('osd.objectService.diskfile.remove_file', side_effect=OSError): object_server.ObjectController.container_update = mock.MagicMock() timestamp = normalize_timestamp(time()) req = Request.blank('/fs1/a1/d1/o1/a/c/o', environ={ 'REQUEST_METHOD': 'DELETE', 'HTTP_X_GLOBAL_MAP_VERSION': 4.0 }, headers={ 'X-Timestamp': timestamp, 'X-Container-Host': '1.2.3:0000' }) resp = req.get_response(self.object_controller) self.assertEquals(resp.status_int, 404) self.assertFalse( object_server.ObjectController.container_update.called) timestamp = normalize_timestamp(time()) req = Request.blank('/fs1/a1/d1/o1/a/c/o', environ={ 'REQUEST_METHOD': 'PUT', 'HTTP_X_GLOBAL_MAP_VERSION': 4.0 }, headers={ 'X-Timestamp': timestamp, 'Content-Type': 'application/x-test', 'X-Object-Meta-1': 'One', 'X-Object-Meta-Two': 'Two', 'X-Container-Host': '1.2.3:0000' }) req.body = 'VERIFY' resp = req.get_response(self.object_controller) self.assertEquals(resp.status_int, 201) timestamp = normalize_timestamp(time()) req = Request.blank('/fs1/a1/d1/o1/a/c/o', environ={ 'REQUEST_METHOD': 'DELETE', 'HTTP_X_GLOBAL_MAP_VERSION': 4.0 }, headers={ 'X-Timestamp': timestamp, 'X-Container-Host': '1.2.3:0000' }) resp = req.get_response(self.object_controller) self.assertEquals(resp.status_int, 204) self.assertTrue(object_server.ObjectController.container_update.called)
def test_PUT_client_timeout(self): class FakeTimeout(BaseException): def __enter__(self): raise self def __exit__(self, typ, value, tb): pass # This is just so the test fails when run on older object server code # instead of exploding. if not hasattr(object_server, 'ChunkReadTimeout'): object_server.ChunkReadTimeout = None with mock.patch.object(object_server, 'ChunkReadTimeout', FakeTimeout): timestamp = normalize_timestamp(time()) req = Request.blank('/fs1/a1/d1/o1/a/c/o', environ={'REQUEST_METHOD': 'PUT'}, headers={ 'X-Timestamp': timestamp, 'Content-Type': 'text/plain', 'Content-Length': '6', 'X-Container-Host': '1.2.3:0000', 'X-GLOBAL-MAP-VERSION': 4.0 }) req.environ['wsgi.input'] = StringIO('VERIFY') resp = req.get_response(self.object_controller) self.assertEquals(resp.status_int, 408)
def create_container_record_for_updater(cls, name, hash, info): """An interface to create an object of ContainerRecord for account \ updater, from info map """ if 'x-object-count' not in info: info['x-object-count'] = 0 if not info['put_timestamp']: info['put_timestamp'] = '0' if not info['delete_timestamp']: info['delete_timestamp'] = '0' return libaccountLib.ContainerRecord(0, name, hash, \ normalize_timestamp(str(info['put_timestamp'])), \ normalize_timestamp(str(info['delete_timestamp'])), \ long(info['object_count']), \ long(info['bytes_used']), \ info['deleted'])
def _backend_requests(self, req, n_outgoing, account_node, account_filesystem, account_directory, global_map_version, component_number, account_component_number): additional = {'X-Timestamp': normalize_timestamp(time.time())} headers = [ self.generate_request_headers(global_map_version, component_number, req, transfer=True, additional=additional) for _junk in range(n_outgoing) ] # for i, account in enumerate(accounts): for i, account in enumerate(account_node): try: i = i % len(headers) except ZeroDivisionError: raise # headers[i]['X-Account-Partition'] = account_partition # headers[i]['X-Account-Host'] = csv_append( # headers[i].get('X-Account-Host'), # '%(ip)s:%(port)s' % account) # headers[i]['X-Account-Device'] = csv_append( # headers[i].get('X-Account-Device'), # account['device']) headers[i]['X-Account-FileSystem'] = account_filesystem headers[i]['X-Account-Directory'] = account_directory headers[i]['X-Account-Host'] = '%(ip)s:%(port)s' % account headers[i]['X-Account-Component-Number'] = account_component_number return headers
def test_POST_read_metadata_exception(self): with self.read_meta_manage(): diskfile.DiskFile.read_metadata = mock.MagicMock( side_effect=DiskFileNotExist) object_server.ObjectController.remove_trans_id = mock.MagicMock() object_server.ObjectController.release_lock = mock.MagicMock() timestamp = normalize_timestamp(time()) req = Request.blank('/fs1/a1/d1/o1/a/c/o', environ={ 'REQUEST_METHOD': 'POST ', 'HTTP_X_GLOBAL_MAP_VERSION': 4.0 }, headers={ 'X-Timestamp': timestamp, 'X-Object-Meta-1': 'One', 'X-Object-Meta-2': 'Two', 'Content-Type': 'text/plain', 'X-Container-Host': '1.2.3:0000' }) resp = req.get_response(self.object_controller) self.assertEqual(resp.status_int, 404) object_server.ObjectController.remove_trans_id.assert_called_once_with( "fd2d8dafa0570422b397941531342ca4/6eff33b3ff33852f4cfb514aaa7f5199/d1c91d91068a170a6bcf220efe77711d", "123") self.assertTrue(object_server.ObjectController.release_lock.called) self.assertFalse( self.lock_mgr_obj.is_exists( 'fd2d8dafa0570422b397941531342ca4/6eff33b3ff33852f4cfb514aaa7f5199/d1c91d91068a170a6bcf220efe77711d' ))
def test_write_metdata(self): df = self._create_test_file('1234567890') timestamp = normalize_timestamp(time()) metadata = {'X-Timestamp': timestamp, 'X-Object-Meta-test': 'data'} metadata['name'] = '/a/c/o' metadata['Content-Length'] = '10' df.write_metadata(metadata) metadata = df.read_metadata() self.assertEquals(metadata['X-Object-Meta-test'], 'data')
def get_info(self): now = normalize_timestamp(time.time()) return { 'container_count': 0, 'object_count': 0, 'bytes_used': 0, 'created_at': now, 'put_timestamp': now }
def test_POST_read_metadata_wrong_timestamp(self): timestamp = normalize_timestamp(time()) req = Request.blank('/fs1/a1/d1/o1/a/c/o', environ={ 'REQUEST_METHOD': 'PUT', 'HTTP_X_GLOBAL_MAP_VERSION': 4.0 }, headers={ 'X-Timestamp': timestamp, 'Content-Type': 'application/x-test', 'X-Object-Meta-1': 'One', 'X-Object-Meta-Two': 'Two', 'X-Container-Host': '1.2.3:0000' }) req.body = 'VERIFY' resp = req.get_response(self.object_controller) self.assertEquals(resp.status_int, 201) object_server.ObjectController.remove_trans_id = mock.MagicMock() object_server.ObjectController.release_lock = mock.MagicMock() with self.read_meta_manage(): diskfile.DiskFile.read_metadata = mock.MagicMock( return_value={ 'X-Timestamp': str(float(timestamp) + 1), 'Content-Length': 0 }) req = Request.blank('/fs1/a1/d1/o1/a/c/o', environ={ 'REQUEST_METHOD': 'DELETE', 'HTTP_X_GLOBAL_MAP_VERSION': 4.0 }, headers={ 'X-Timestamp': timestamp, 'X-Container-Host': '1.2.3:0000' }) resp = req.get_response(self.object_controller) self.assertEqual(resp.status_int, 409) with self.read_meta_manage(): diskfile.DiskFile.read_metadata = mock.MagicMock( return_value={ 'X-Timestamp': str(float(timestamp) - 1), 'Content-Length': 0 }) req = Request.blank('/fs1/a1/d1/o1/a/c/o', environ={ 'REQUEST_METHOD': 'DELETE', 'HTTP_X_GLOBAL_MAP_VERSION': 4.0 }, headers={ 'X-Timestamp': timestamp, 'X-Container-Host': '1.2.3:0000' }) resp = req.get_response(self.object_controller) self.assertEqual(resp.status_int, 204)
def create_AccountStat_object(cls, info): """An interface to create an object of AccountStat, from info map""" if 'account' not in info: info['account'] = '-1' if 'created_at' not in info: info['created_at'] = '0' if 'put_timestamp' not in info: info['put_timestamp'] = '0' if 'delete_timestamp' not in info: info['delete_timestamp'] = '0' if 'container_count' not in info: info['container_count'] = 0 if 'object_count' not in info: info['object_count'] = 0 if 'bytes_used' not in info: info['bytes_used'] = 0 if 'hash' not in info: info['hash'] = '-1' if 'id' not in info: info['id'] = '-1' if 'status' not in info: info['status'] = '-1' if 'status_changed_at' not in info: info['status_changed_at'] = '0' if 'metadata' not in info: info['metadata'] = {} return libaccountLib.AccountStat( info['account'], info['created_at'], normalize_timestamp(\ info['put_timestamp']), normalize_timestamp(\ info['delete_timestamp']), info['container_count'], info['object_count'], info['bytes_used'], info['hash'], info['id'], info['status'], info['status_changed_at'], info['metadata'] )
def test_PUT_no_etag(self): req = Request.blank('/fs1/a1/d1/o1/a/c/o', environ={'REQUEST_METHOD': 'PUT'}, headers={ 'X-Timestamp': normalize_timestamp(time()), 'Content-Type': 'text/plain', 'X-Container-Host': '1.2.3:0000', 'X-GLOBAL-MAP-VERSION': 4.0 }) req.body = 'test' resp = req.get_response(self.object_controller) self.assertEquals(resp.status_int, 201)
def test_PUT_old_timestamp(self): ts = time() req = Request.blank('/fs1/a1/d1/o1/a/c/o', environ={'REQUEST_METHOD': 'PUT'}, headers={ 'X-Timestamp': normalize_timestamp(ts), 'Content-Length': '6', 'Content-Type': 'application/octet-stream', 'X-Container-Host': '1.2.3:0000', 'X-GLOBAL-MAP-VERSION': 4.0 }) req.body = 'VERIFY' resp = req.get_response(self.object_controller) self.assertEquals(resp.status_int, 201) req = Request.blank('/fs1/a1/d1/o1/a/c/o', environ={'REQUEST_METHOD': 'PUT'}, headers={ 'X-Timestamp': normalize_timestamp(ts), 'Content-Type': 'text/plain', 'Content-Encoding': 'gzip', 'X-Container-Host': '1.2.3:0000', 'X-GLOBAL-MAP-VERSION': 4.0 }) req.body = 'VERIFY TWO' resp = req.get_response(self.object_controller) self.assertEquals(resp.status_int, 409) req = Request.blank('/fs1/a1/d1/o1/a/c/o', environ={'REQUEST_METHOD': 'PUT'}, headers={ 'X-Timestamp': normalize_timestamp(ts - 1), 'Content-Type': 'text/plain', 'Content-Encoding': 'gzip', 'X-Container-Host': '1.2.3:0000', 'X-GLOBAL-MAP-VERSION': 4.0 }) req.body = 'VERIFY THREE' resp = req.get_response(self.object_controller) self.assertEquals(resp.status_int, 409)
def test_DELETE_acquire_lock_fail_400(self): timestamp = normalize_timestamp(time()) req = Request.blank('/fs1/a1/d1/o1/a/c/o', environ={ 'REQUEST_METHOD': 'DELETE', 'HTTP_X_GLOBAL_MAP_VERSION': 4.0 }, headers={ 'X-Timestamp': timestamp, 'X-Container-Host': '1.2.3:0000' }) resp = req.get_response(self.object_controller) self.assertEqual(resp.status_int, 503)
def test_PUT_acquire_lock_fail_400(self): timestamp = normalize_timestamp(time()) req = Request.blank('/fs1/a1/d1/o1/a/c/o', environ={'REQUEST_METHOD': 'PUT'}, headers={ 'X-Timestamp': timestamp, 'Content-Length': '0', 'Content-Type': 'text/plain', 'X-Container-Host': '1.2.3:0000', 'X-GLOBAL-MAP-VERSION': 4.0 }) resp = req.get_response(self.object_controller) self.assertEqual(resp.status_int, 503)
def test_DELETE_acquire_lock_exception(self): acquire_lock_orig = TranscationManager.acquire_lock TranscationManager.acquire_lock = mock.MagicMock(side_effect=Exception) timestamp = normalize_timestamp(time()) req = Request.blank('/fs1/a1/d1/o1/a/c/o', environ={ 'REQUEST_METHOD': 'DELETE', 'HTTP_X_GLOBAL_MAP_VERSION': 4.0 }, headers={'X-Timestamp': timestamp}) resp = req.get_response(self.object_controller) self.assertEqual(resp.status_int, 503) TranscationManager.acquire_lock = acquire_lock_orig
def test_PUT_zero_content_length(self): req = Request.blank('/fs1/a1/d1/o1/a/c/o', environ={'REQUEST_METHOD': 'PUT'}, headers={ 'X-Timestamp': normalize_timestamp(time()), 'Content-Type': 'application/octet-stream', 'X-Container-Host': '1.2.3:0000', 'X-GLOBAL-MAP-VERSION': 4.0 }) req.body = '' self.assertEquals(req.headers['Content-Length'], '0') resp = req.get_response(self.object_controller) self.assertEquals(resp.status_int, 201)
def test_PUT_bad_transfer_encoding(self): req = Request.blank('/fs1/a1/d1/o1/a/c/o', environ={'REQUEST_METHOD': 'PUT'}, headers={ 'X-Timestamp': normalize_timestamp(time()), 'Content-Type': 'application/octet-stream', 'X-Container-Host': '1.2.3:0000', 'X-GLOBAL-MAP-VERSION': 4.0 }) req.body = 'VERIFY' req.headers['Transfer-Encoding'] = 'bad' resp = req.get_response(self.object_controller) self.assertEqual(resp.status_int, 400)
def put_container(self, filesystem, acc_dir, cont_dir, \ account, container, metadata, req): """ Handles PUT request for container param:filesystem: Filesystem name param:account: Account name param:container: Container name param:req: HTTP Request object """ try: # create path path = self.create_path(filesystem, acc_dir, cont_dir, account, container) # Remove this after container library update self.logger.debug(('PUT container called for path: %(path)s'), {'path' : path}) if not os.path.exists(path): os.makedirs(path) timestamp = normalize_timestamp(req.headers['x-timestamp']) created_at = normalize_timestamp(time.time()) # create container stat object cont_stat = ContainerStat(account, container, created_at, \ timestamp, '0', 0, 0, '', str(uuid4()), 'ADDED', '', metadata) #get component number component_name = req.headers['x-component-number'] # call container library to create container status_obj = self.__create_cont(path, filesystem, cont_stat, component_name) status = status_obj.get_return_status() self.logger.info(('Status from container library comes ' 'out to be: %(status)s'), {'status' : status}) return status, cont_stat except Exception as err: self.logger.error(('PUT request failed for account/container:' ' %(account)s/%(container)s ' 'close failure: %(exc)s : %(stack)s'), {'account' : account, 'container' : container, 'exc': err, 'stack': ''.join(traceback.format_stack())}) raise err
def test_PUT_invalid_content_type(self): req = Request.blank('/fs1/a1/d1/o1/a/c/o', environ={'REQUEST_METHOD': 'PUT'}, headers={ 'X-Timestamp': normalize_timestamp(time()), 'Content-Length': '6', 'Content-Type': '\xff\xff', 'X-Container-Host': '1.2.3:0000', 'X-GLOBAL-MAP-VERSION': 4.0 }) req.body = 'VERIFY' resp = req.get_response(self.object_controller) self.assertEquals(resp.status_int, 400) self.assert_('Content-Type' in resp.body)
def container_update(self, metadata, duplicate=False, method='PUT', host=None, unknown=False): ''' Send request to container service for info file update :param metadata: object metadata :param duplicate: If set to true, then container update request will contain 'x-duplicate-update: True' header else it not contain any additional header. :param method: method name :param host: host IP and port :returns: True, If update successful False, otherwise. ''' if not metadata: header = HeaderKeyDict({'x-timestamp': \ normalize_timestamp(time.time())}) file_system, directory = '', '' else: host, directory, file_system = self.__get_service_details(metadata, host=host) try: header = HeaderKeyDict({ 'x-global-map-version': '-1', 'x-size': metadata['Content-Length'], 'x-content-type': metadata['Content-Type'], 'x-timestamp': metadata['X-Timestamp'], 'x-etag': metadata['ETag']}) except KeyError: return False header.update({'x-object-path': metadata['name']}) if duplicate: header.update({'x-duplicate-update': True}) if unknown: header.update({'x-duplicate-unknown': True}) try: resp = http_connection(host, file_system, directory, \ header, method) except (Exception, Timeout): self._logger.exception(__( 'ERROR container update failed ' '%(host)s/%(fs)s '), {'host': host, 'fs': file_system}) return False resp.read() if not is_success(resp.status): return False return True
def test_PUT_acquire_lock_exception(self): acquire_lock_orig = TranscationManager.acquire_lock TranscationManager.acquire_lock = mock.MagicMock(side_effect=Exception) timestamp = normalize_timestamp(time()) req = Request.blank('/fs1/a1/d1/o1/a/c/o', environ={'REQUEST_METHOD': 'PUT'}, headers={ 'X-Timestamp': timestamp, 'Content-Length': '0', 'Content-Type': 'text/plain', 'X-Container-Host': '1.2.3:0000', 'X-GLOBAL-MAP-VERSION': 4.0 }) resp = req.get_response(self.object_controller) self.assertEqual(resp.status_int, 503) TranscationManager.acquire_lock = acquire_lock_orig
def test_POST_acquire_lock_fail_503(self): timestamp = normalize_timestamp(time()) req = Request.blank('/fs1/a1/d1/o1/a/c/o', environ={ 'REQUEST_METHOD': 'POST', 'HTTP_X_GLOBAL_MAP_VERSION': 4.0 }, headers={ 'X-Timestamp': timestamp, 'X-Object-Meta-1': 'One', 'X-Object-Meta-2': 'Two', 'Content-Type': 'text/plain', 'X-Container-Host': '1.2.3:0000' }) resp = req.get_response(self.object_controller) self.assertEqual(resp.status_int, 503)
def test_PUT_invalid_etag(self): object_server.ObjectController.release_lock = mock.MagicMock() object_server.ObjectController.remove_trans_id = mock.MagicMock() req = Request.blank('/fs1/a1/d1/o1/a/c/o', environ={'REQUEST_METHOD': 'PUT'}, headers={ 'X-Timestamp': normalize_timestamp(time()), 'Content-Type': 'text/plain', 'ETag': 'invalid', 'X-Container-Host': '1.2.3:0000', 'X-GLOBAL-MAP-VERSION': 4.0 }) req.body = 'test' resp = req.get_response(self.object_controller) self.assertEquals(resp.status_int, 422) self.assertTrue(object_server.ObjectController.release_lock.called) self.assertTrue(object_server.ObjectController.remove_trans_id.called)
def test_PUT_common(self): timestamp = normalize_timestamp(time()) req = Request.blank('/fs1/a1/d1/o1/a/c/o', environ={'REQUEST_METHOD': 'PUT'}, headers={ 'X-Timestamp': timestamp, 'Content-Length': '6', 'Content-Type': 'application/octet-stream', 'X-Container-Host': '1.2.3:0000', 'X-GLOBAL-MAP-VERSION': 4.0 }) req.body = 'VERIFY' print req, "-------------------" resp = req.get_response(self.object_controller) print "-------status", resp.status self.assertEquals(resp.status_int, 201) print "----hello", self.filesystems print "----hello2", self.filesystems objfile = os.path.join(self.filesystems, "fs1", "a1", hash_path("a"), "d1", hash_path("a", "c"), "o1", "data", hash_path('a', 'c', 'o')) + ".data" metafile = os.path.join(self.filesystems, "fs1", "a1", hash_path("a"), "d1", hash_path("a", "c"), "o1", "meta", hash_path('a', 'c', 'o')) + ".meta" print objfile, metafile try: self.assert_(os.path.isfile(objfile)) except: print os.path.isfile(objfile) try: self.assert_(os.path.isfile(metafile)) except: print os.path.isfile(metafile), "------------" self.assertEquals(open(objfile, 'r').read(), 'VERIFY') self.assertEquals( read_metadata(metafile), { 'X-Timestamp': timestamp, 'Content-Length': '6', 'ETag': '0b4c12d7e0a73840c1c4f148fda3b037', 'Content-Type': 'application/octet-stream', 'name': '/a/c/o' })
def test_DELETE_add_exception(self): LockManager.add = mock.MagicMock(side_effect=Exception) object_server.ObjectController.release_lock = mock.MagicMock() timestamp = normalize_timestamp(time()) req = Request.blank('/fs1/a1/d1/o1/a/c/o', environ={ 'REQUEST_METHOD': 'DELETE', 'HTTP_X_GLOBAL_MAP_VERSION': 4.0 }, headers={ 'X-Timestamp': timestamp, 'X-Container-Host': '1.2.3:0000' }) resp = req.get_response(self.object_controller) self.assertEqual(resp.status_int, 500) self.assertTrue(object_server.ObjectController.release_lock.called) self.assertFalse( self.lock_mgr_obj.is_exists( 'fd2d8dafa0570422b397941531342ca4/6eff33b3ff33852f4cfb514aaa7f5199/d1c91d91068a170a6bcf220efe77711d' ))
def test_PUT_read_metadata_exception(self): with self.read_meta_manage(): diskfile.DiskFile.read_metadata = mock.MagicMock( side_effect=DiskFileNotExist) timestamp = normalize_timestamp(time()) req = Request.blank('/fs1/a1/d1/o1/a/c/o', environ={'REQUEST_METHOD': 'PUT'}, headers={ 'X-Timestamp': timestamp, 'Content-Length': '0', 'Content-Type': 'text/plain', 'X-Container-Host': '1.2.3:0000', 'X-GLOBAL-MAP-VERSION': 4.0 }) resp = req.get_response(self.object_controller) self.assertEqual(resp.status_int, 201) self.assertFalse( self.lock_mgr_obj.is_exists( 'fd2d8dafa0570422b397941531342ca4/6eff33b3ff33852f4cfb514aaa7f5199/d1c91d91068a170a6bcf220efe77711d' ))
def put_object(self, filesystem, acc_dir, cont_dir, account, container, obj, req): """ Handles PUT request for object param:filesystem: Filesystem name param:account: Account name param:container: Container name param:obj: Object name param:req: HTTP Request object """ try: # create path path = self.create_path(filesystem, acc_dir, cont_dir, account, container) self.logger.debug(('PUT object in container called for path:' ' %(path)s'), {'path' : path}) # create object stat deleted = 1 if 'x-duplicate-update' in req.headers: deleted = 3 elif 'x-duplicate-unknown' in req.headers: deleted = 255 else: pass created_at = normalize_timestamp(req.headers['x-timestamp']) size = int(float(req.headers['x-size'])) old_size = int(float(req.headers.get('x-old-size', 0))) # create object record object obj_stat = ObjectRecord(1, obj, created_at, size, \ req.headers['x-content-type'], req.headers['x-etag'], \ deleted, old_size) # call container library to update container status_obj = self.__update_container(path, obj_stat) status = status_obj.get_return_status() self.logger.info(('Status from container library comes' 'out to be: %(status)s'), {'status' : status}) return status except Exception as err: self.logger.error(('container update failed for new object PUT', 'close failure: %(exc)s : %(stack)s'), {'exc': err, 'stack': ''.join(traceback.format_stack())}) raise err
def delete_object(self, filesystem, acc_dir, cont_dir, \ account, container, obj, req): """ Handles DELETE request for object param:filesystem: Filesystem name param:account: Account name param:container: Container name param:obj: Object name param:req: HTTP Request object """ try: # create path path = self.create_path(filesystem, acc_dir, cont_dir, account, container) self.logger.debug(('Delete object called for path: %(path)s'), {'path' : path}) deleted = 2 if 'x-duplicate-unknown' in req.headers: deleted = 254 size = 0 if 'x-size' in req.headers: size = int(float(req.headers['x-size'])) # create object stat created_at = normalize_timestamp(req.headers['x-timestamp']) # create object record object old_size = int(float(req.headers.get('x-old-size', 0))) obj_stat = ObjectRecord(1, obj, created_at, size, \ 'application/deleted', 'noetag', deleted, old_size) # call container library to update container status_obj = self.__update_container(path, obj_stat) status = status_obj.get_return_status() self.logger.info(('Status from container library comes ' 'out to be: %(status)s'), {'status' : status}) return status except Exception as err: self.logger.error(('DELETE object in container failed for:' ' %(obj)s ' 'close failure: %(exc)s : %(stack)s'), {'obj' : obj, 'exc': err, 'stack': ''.join(traceback.format_stack())}) raise err