Rename DiskFile.writer to create
Change-Id: I3af71c64dd4c61e665fe128a0b5241fd87ba71e0 Signed-off-by: Peter Portante <peter.portante@redhat.com>
This commit is contained in:
parent
f1940bb05a
commit
9e7c56a2c9
|
@ -274,7 +274,7 @@ def get_hashes(partition_dir, recalculate=None, do_listdir=False,
|
|||
class DiskWriter(object):
|
||||
"""
|
||||
Encapsulation of the write context for servicing PUT REST API
|
||||
requests. Serves as the context manager object for DiskFile's writer()
|
||||
requests. Serves as the context manager object for DiskFile's create()
|
||||
method.
|
||||
"""
|
||||
def __init__(self, disk_file, fd, tmppath, threadpool):
|
||||
|
@ -629,9 +629,9 @@ class DiskFile(object):
|
|||
int(self.metadata['X-Delete-At']) <= time.time())
|
||||
|
||||
@contextmanager
|
||||
def writer(self, size=None):
|
||||
def create(self, size=None):
|
||||
"""
|
||||
Context manager to write a file. We create a temporary file first, and
|
||||
Context manager to create a file. We create a temporary file first, and
|
||||
then return a DiskWriter object to encapsulate the state.
|
||||
|
||||
:param size: optional initial size of file to explicitly allocate on
|
||||
|
@ -666,7 +666,7 @@ class DiskFile(object):
|
|||
:param tombstone: whether or not we are writing a tombstone
|
||||
"""
|
||||
extension = '.ts' if tombstone else '.meta'
|
||||
with self.writer() as writer:
|
||||
with self.create() as writer:
|
||||
writer.put(metadata, extension=extension)
|
||||
|
||||
def _drop_cache(self, fd, offset, length):
|
||||
|
|
|
@ -362,7 +362,7 @@ class ObjectController(object):
|
|||
etag = md5()
|
||||
elapsed_time = 0
|
||||
try:
|
||||
with disk_file.writer(size=fsize) as writer:
|
||||
with disk_file.create(size=fsize) as writer:
|
||||
reader = request.environ['wsgi.input'].read
|
||||
for chunk in iter(lambda: reader(self.network_chunk_size), ''):
|
||||
start_time = time.time()
|
||||
|
|
|
@ -63,7 +63,7 @@ class TestAuditor(unittest.TestCase):
|
|||
self.auditor = auditor.AuditorWorker(self.conf, self.logger)
|
||||
data = '0' * 1024
|
||||
etag = md5()
|
||||
with self.disk_file.writer() as writer:
|
||||
with self.disk_file.create() as writer:
|
||||
writer.write(data)
|
||||
etag.update(data)
|
||||
etag = etag.hexdigest()
|
||||
|
@ -92,7 +92,7 @@ class TestAuditor(unittest.TestCase):
|
|||
data = '0' * 1024
|
||||
etag = md5()
|
||||
timestamp = str(normalize_timestamp(time.time()))
|
||||
with self.disk_file.writer() as writer:
|
||||
with self.disk_file.create() as writer:
|
||||
writer.write(data)
|
||||
etag.update(data)
|
||||
etag = etag.hexdigest()
|
||||
|
@ -117,7 +117,7 @@ class TestAuditor(unittest.TestCase):
|
|||
etag = etag.hexdigest()
|
||||
metadata['ETag'] = etag
|
||||
|
||||
with self.disk_file.writer() as writer:
|
||||
with self.disk_file.create() as writer:
|
||||
writer.write(data)
|
||||
writer.put(metadata)
|
||||
|
||||
|
@ -147,7 +147,7 @@ class TestAuditor(unittest.TestCase):
|
|||
pre_errors = self.auditor.errors
|
||||
data = '0' * 1024
|
||||
etag = md5()
|
||||
with self.disk_file.writer() as writer:
|
||||
with self.disk_file.create() as writer:
|
||||
writer.write(data)
|
||||
etag.update(data)
|
||||
etag = etag.hexdigest()
|
||||
|
@ -169,7 +169,7 @@ class TestAuditor(unittest.TestCase):
|
|||
pre_quarantines = self.auditor.quarantines
|
||||
data = '0' * 1024
|
||||
etag = md5()
|
||||
with self.disk_file.writer() as writer:
|
||||
with self.disk_file.create() as writer:
|
||||
writer.write(data)
|
||||
etag.update(data)
|
||||
etag = etag.hexdigest()
|
||||
|
@ -190,7 +190,7 @@ class TestAuditor(unittest.TestCase):
|
|||
pre_quarantines = self.auditor.quarantines
|
||||
data = '0' * 1024
|
||||
etag = md5()
|
||||
with self.disk_file.writer() as writer:
|
||||
with self.disk_file.create() as writer:
|
||||
writer.write(data)
|
||||
etag.update(data)
|
||||
etag = etag.hexdigest()
|
||||
|
@ -210,7 +210,7 @@ class TestAuditor(unittest.TestCase):
|
|||
pre_quarantines = self.auditor.quarantines
|
||||
data = '0' * 10
|
||||
etag = md5()
|
||||
with self.disk_file.writer() as writer:
|
||||
with self.disk_file.create() as writer:
|
||||
writer.write(data)
|
||||
etag.update(data)
|
||||
etag = etag.hexdigest()
|
||||
|
@ -225,7 +225,7 @@ class TestAuditor(unittest.TestCase):
|
|||
'ob', self.logger)
|
||||
data = '1' * 10
|
||||
etag = md5()
|
||||
with self.disk_file.writer() as writer:
|
||||
with self.disk_file.create() as writer:
|
||||
writer.write(data)
|
||||
etag.update(data)
|
||||
etag = etag.hexdigest()
|
||||
|
@ -244,7 +244,7 @@ class TestAuditor(unittest.TestCase):
|
|||
self.auditor.log_time = 0
|
||||
data = '0' * 1024
|
||||
etag = md5()
|
||||
with self.disk_file.writer() as writer:
|
||||
with self.disk_file.create() as writer:
|
||||
writer.write(data)
|
||||
etag.update(data)
|
||||
etag = etag.hexdigest()
|
||||
|
@ -284,7 +284,7 @@ class TestAuditor(unittest.TestCase):
|
|||
fp.close()
|
||||
|
||||
etag = md5()
|
||||
with self.disk_file.writer() as writer:
|
||||
with self.disk_file.create() as writer:
|
||||
etag = etag.hexdigest()
|
||||
metadata = {
|
||||
'ETag': etag,
|
||||
|
|
|
@ -486,7 +486,7 @@ class TestDiskFile(unittest.TestCase):
|
|||
tmpdir = os.path.join(self.testdir, 'sda1', 'tmp')
|
||||
os.rmdir(tmpdir)
|
||||
with diskfile.DiskFile(self.testdir, 'sda1', '0', 'a', 'c',
|
||||
'o', FakeLogger()).writer():
|
||||
'o', FakeLogger()).create():
|
||||
self.assert_(os.path.exists(tmpdir))
|
||||
|
||||
def test_iter_hook(self):
|
||||
|
@ -538,7 +538,7 @@ class TestDiskFile(unittest.TestCase):
|
|||
timestamp = ts
|
||||
else:
|
||||
timestamp = str(normalize_timestamp(time()))
|
||||
with df.writer() as writer:
|
||||
with df.create() as writer:
|
||||
writer.write(data)
|
||||
etag.update(data)
|
||||
etag = etag.hexdigest()
|
||||
|
|
Loading…
Reference in New Issue