Merge "Add part/suffix/hash to tempdir only where needed" into feature/deep

This commit is contained in:
Zuul 2017-12-09 04:48:13 +00:00 committed by Gerrit Code Review
commit 7e5472d2c1
3 changed files with 17 additions and 18 deletions

View File

@ -431,27 +431,19 @@ def temptree(files, contents=''):
rmtree(tempdir)
def get_tempdir():
basedir = mkdtemp()
# add swift path structure needed for some tests
tempdir = os.path.join(basedir, 'part', 'suffix', 'hash')
os.makedirs(tempdir)
return basedir, tempdir
def with_tempdir(f):
"""
Decorator to give a single test a tempdir as argument to test method.
"""
@functools.wraps(f)
def wrapped(*args, **kwargs):
basedir, tempdir = get_tempdir()
tempdir = mkdtemp()
args = list(args)
args.append(tempdir)
try:
return f(*args, **kwargs)
finally:
rmtree(basedir)
rmtree(tempdir)
return wrapped

View File

@ -1015,12 +1015,13 @@ class TestContainerBroker(unittest.TestCase):
@with_tempdir
def test_get_items_since_with_shard_db(self, tempdir):
acct = 'account'
cont = 'continer'
cont = 'container'
hsh = hash_path(acct, cont)
db_file = "%s.db" % hsh
db_shard_file = "%s_shard.db" % hsh
db_path = os.path.join(tempdir, db_file)
db_shard_path = os.path.join(tempdir, db_shard_file)
db_path = os.path.join(tempdir, 'part', 'suffix', 'hash', db_file)
db_shard_path = os.path.join(
tempdir, 'part', 'suffix', 'hash', db_shard_file)
ts = make_timestamp_iter()
broker = ContainerBroker(db_path, account=acct, container=cont)
@ -2810,8 +2811,10 @@ class TestContainerBroker(unittest.TestCase):
@with_tempdir
def test_set_sharding_states(self, tempdir):
ts_iter = make_timestamp_iter()
db_path = os.path.join(tempdir, 'container.db')
new_db_path = os.path.join(tempdir, 'container_shard.db')
db_path = os.path.join(
tempdir, 'part', 'suffix', 'hash', 'container.db')
new_db_path = os.path.join(
tempdir, 'part', 'suffix', 'hash', 'container_shard.db')
broker = ContainerBroker(
db_path, account='a', container='c')
broker.initialize(next(ts_iter).internal, 0)

View File

@ -15,6 +15,7 @@
import os
import shutil
from contextlib import contextmanager
from tempfile import mkdtemp
import mock
import unittest
@ -27,8 +28,7 @@ from swift.container.sharder import ContainerSharder, RangeAnalyser, \
from swift.common.utils import ShardRange, Timestamp, hash_path, \
encode_timestamps
from test.unit import FakeLogger, debug_logger, FakeRing, \
make_timestamp_iter, get_tempdir
from test.unit import FakeLogger, debug_logger, FakeRing, make_timestamp_iter
class TestRangeAnalyser(unittest.TestCase):
@ -302,7 +302,11 @@ class TestRangeAnalyser(unittest.TestCase):
class TestSharder(unittest.TestCase):
def setUp(self):
self.tempdir_base, self.tempdir = get_tempdir()
self.tempdir_base = mkdtemp()
# add swift path structure needed for some tests
self.tempdir = os.path.join(
self.tempdir_base, 'part', 'suffix', 'hash')
os.makedirs(self.tempdir)
self.ts_iter = make_timestamp_iter()
def ts_internal(self):