def pickle_async_update(self, device, account, container, obj, data, timestamp, policy): # This should be using the JSON blob stuff instead of a pickle. # Didn't we deprecate it? device_path = self.construct_dev_path(device) async_dir = os.path.join(device_path, get_async_dir(policy)) ohash = hash_path(account, container, obj) write_pickle( data, os.path.join(async_dir, ohash[-3:], ohash + '-' + normalize_timestamp(timestamp)), os.path.join(device_path, 'tmp')) self.logger.increment('async_pendings')
def test_write_pickle(self): td = tempfile.mkdtemp() try: fpp = os.path.join(td, 'pp') # FIXME: Remove this patch when coverage.py can handle eventlet with patch("swiftonhpss.swift.common.fs_utils.do_fsync", _mock_os_fsync): utils.write_pickle('pickled peppers', fpp) with open(fpp, "rb") as f: contents = f.read() s = pickle.loads(contents) assert s == 'pickled peppers', repr(s) finally: shutil.rmtree(td)
def test_write_pickle_ignore_tmp(self): tf = tempfile.NamedTemporaryFile() td = tempfile.mkdtemp() try: fpp = os.path.join(td, 'pp') # Also test an explicity pickle protocol # FIXME: Remove this patch when coverage.py can handle eventlet with patch("swiftonhpss.swift.common.fs_utils.do_fsync", _mock_os_fsync): utils.write_pickle('pickled peppers', fpp, tmp=tf.name, pickle_protocol=2) with open(fpp, "rb") as f: contents = f.read() s = pickle.loads(contents) assert s == 'pickled peppers', repr(s) with open(tf.name, "rb") as f: contents = f.read() assert contents == '' finally: shutil.rmtree(td)