Leave less garbage in /var/tmp

All our tests that invoked broker.set_sharding_state() created
/var/tmp/tmp, when it called DatabaseBroker.get_device_path(),
then added "tmp" to it. We provided 1 less level, so it walked up
ouside of the test's temporary directory.

The case of "cleanUp" instead of "tearDown" didn't break out of
jail, but left trash in /var/tmp all the same.

Change-Id: I8030ea49e2a977ebb7048e1d5dcf17338c1616df
This commit is contained in:
Pete Zaitcev 2019-02-11 21:42:34 -06:00 committed by Tim Burke
parent 64e5fd364a
commit ac01d186b4
2 changed files with 22 additions and 19 deletions

View File

@ -1823,7 +1823,7 @@ class TestHandoffsOnly(unittest.TestCase):
# part 2 does not belong on sdq
self._make_fake_db('sdq', 2, 'bcbcbcbc15d3835053d568c57e2c83b5')
def cleanUp(self):
def tearDown(self):
rmtree(self.root, ignore_errors=True)
def test_scary_warnings(self):

View File

@ -128,7 +128,7 @@ class TestContainerBroker(unittest.TestCase):
# Test ContainerBroker.is_deleted() and get_info_is_deleted()
ts_iter = make_timestamp_iter()
db_path = os.path.join(
tempdir, 'part', 'suffix', 'hash', 'container.db')
tempdir, 'containers', 'part', 'suffix', 'hash', 'container.db')
broker = ContainerBroker(db_path, account='a', container='c')
broker.initialize(next(ts_iter).internal, 0)
@ -235,7 +235,7 @@ class TestContainerBroker(unittest.TestCase):
# Test ContainerBroker.empty
ts_iter = make_timestamp_iter()
db_path = os.path.join(
tempdir, 'part', 'suffix', 'hash', 'container.db')
tempdir, 'containers', 'part', 'suffix', 'hash', 'container.db')
broker = ContainerBroker(db_path, account='a', container='c')
broker.initialize(next(ts_iter).internal, 0)
self.assertTrue(broker.is_root_container())
@ -340,7 +340,7 @@ class TestContainerBroker(unittest.TestCase):
# usage should not be considered
ts_iter = make_timestamp_iter()
db_path = os.path.join(
tempdir, 'part', 'suffix', 'hash', 'container.db')
tempdir, 'containers', 'part', 'suffix', 'hash', 'container.db')
broker = ContainerBroker(db_path, account='.shards_a', container='cc')
broker.initialize(next(ts_iter).internal, 0)
broker.set_sharding_sysmeta('Root', 'a/c')
@ -478,7 +478,7 @@ class TestContainerBroker(unittest.TestCase):
@with_tempdir
def test_reclaim_deadlock(self, tempdir):
db_path = os.path.join(
tempdir, 'part', 'suffix', 'hash', '%s.db' % uuid4())
tempdir, 'containers', 'part', 'suffix', 'hash', '%s.db' % uuid4())
broker = ContainerBroker(db_path, account='a', container='c')
broker.initialize(Timestamp(100).internal, 0)
# there's some magic count here that causes the failure, something
@ -507,7 +507,7 @@ class TestContainerBroker(unittest.TestCase):
def test_reclaim_shard_ranges(self, tempdir):
ts_iter = make_timestamp_iter()
db_path = os.path.join(
tempdir, 'part', 'suffix', 'hash', '%s.db' % uuid4())
tempdir, 'containers', 'part', 'suffix', 'hash', '%s.db' % uuid4())
broker = ContainerBroker(db_path, account='a', container='c')
broker.initialize(next(ts_iter).internal, 0)
older = next(ts_iter)
@ -1415,7 +1415,7 @@ class TestContainerBroker(unittest.TestCase):
@with_tempdir
def test_sharding_initiated_and_required(self, tempdir):
db_path = os.path.join(
tempdir, 'part', 'suffix', 'hash', '%s.db' % uuid4())
tempdir, 'containers', 'part', 'suffix', 'hash', '%s.db' % uuid4())
broker = ContainerBroker(db_path, account='a', container='c')
broker.initialize(Timestamp.now().internal, 0)
# no shard ranges
@ -1857,7 +1857,8 @@ class TestContainerBroker(unittest.TestCase):
@with_tempdir
def test_get_info_sharding_states(self, tempdir):
ts_iter = make_timestamp_iter()
db_path = os.path.join(tempdir, 'part', 'suffix', 'hash', 'hash.db')
db_path = os.path.join(
tempdir, 'containers', 'part', 'suffix', 'hash', 'hash.db')
broker = ContainerBroker(
db_path, account='myaccount', container='mycontainer')
broker.initialize(next(ts_iter).internal, 0)
@ -2016,7 +2017,8 @@ class TestContainerBroker(unittest.TestCase):
@with_tempdir
def test_get_replication_info(self, tempdir):
ts_iter = make_timestamp_iter()
db_path = os.path.join(tempdir, 'part', 'suffix', 'hash', 'hash.db')
db_path = os.path.join(
tempdir, 'containers', 'part', 'suffix', 'hash', 'hash.db')
broker = ContainerBroker(
db_path, account='myaccount', container='mycontainer')
broker.initialize(next(ts_iter).internal, 0)
@ -2065,7 +2067,8 @@ class TestContainerBroker(unittest.TestCase):
def do_setup():
db_path = os.path.join(
tempdir, 'part', 'suffix', 'hash', '%s.db' % uuid4())
tempdir, 'containers', 'part', 'suffix',
'hash', '%s.db' % uuid4())
broker = ContainerBroker(db_path, account='a', container='c')
broker.initialize(Timestamp.now().internal, 0)
for obj in objects:
@ -3943,7 +3946,7 @@ class TestContainerBroker(unittest.TestCase):
def test_set_db_states(self, tempdir):
ts_iter = make_timestamp_iter()
db_path = os.path.join(
tempdir, 'part', 'suffix', 'hash', 'container.db')
tempdir, 'containers', 'part', 'suffix', 'hash', 'container.db')
broker = ContainerBroker(db_path, account='a', container='c')
broker.initialize(next(ts_iter).internal, 0)
@ -3989,8 +3992,8 @@ class TestContainerBroker(unittest.TestCase):
state=ShardRange.ACTIVE)
broker.merge_shard_ranges([own_sr] + shard_ranges + [deleted_range])
ts_epoch = next(ts_iter)
new_db_path = os.path.join(tempdir, 'part', 'suffix', 'hash',
'container_%s.db' % ts_epoch.normal)
new_db_path = os.path.join(tempdir, 'containers', 'part', 'suffix',
'hash', 'container_%s.db' % ts_epoch.normal)
def check_broker_properties(broker):
# these broker properties should remain unchanged as state changes
@ -4136,7 +4139,7 @@ class TestContainerBroker(unittest.TestCase):
def test_set_sharding_state_errors(self, tempdir):
ts_iter = make_timestamp_iter()
db_path = os.path.join(
tempdir, 'part', 'suffix', 'hash', 'container.db')
tempdir, 'containers', 'part', 'suffix', 'hash', 'container.db')
broker = ContainerBroker(db_path, account='a', container='c',
logger=FakeLogger())
broker.initialize(next(ts_iter).internal, 0)
@ -4172,7 +4175,7 @@ class TestContainerBroker(unittest.TestCase):
def test_set_sharded_state_errors(self, tempdir):
ts_iter = make_timestamp_iter()
retiring_db_path = os.path.join(
tempdir, 'part', 'suffix', 'hash', 'container.db')
tempdir, 'containers', 'part', 'suffix', 'hash', 'container.db')
broker = ContainerBroker(retiring_db_path, account='a', container='c',
logger=FakeLogger())
broker.initialize(next(ts_iter).internal, 0)
@ -4217,7 +4220,7 @@ class TestContainerBroker(unittest.TestCase):
def test_get_brokers(self, tempdir):
ts_iter = make_timestamp_iter()
retiring_db_path = os.path.join(
tempdir, 'part', 'suffix', 'hash', 'container.db')
tempdir, 'containers', 'part', 'suffix', 'hash', 'container.db')
broker = ContainerBroker(retiring_db_path, account='a', container='c',
logger=FakeLogger())
broker.initialize(next(ts_iter).internal, 0)
@ -4272,7 +4275,7 @@ class TestContainerBroker(unittest.TestCase):
ts_iter = make_timestamp_iter()
ts = [next(ts_iter) for _ in range(13)]
db_path = os.path.join(
tempdir, 'part', 'suffix', 'hash', 'container.db')
tempdir, 'containers', 'part', 'suffix', 'hash', 'container.db')
broker = ContainerBroker(
db_path, account='a', container='c')
broker.initialize(next(ts_iter).internal, 0)
@ -4370,7 +4373,7 @@ class TestContainerBroker(unittest.TestCase):
def test_merge_shard_ranges_state(self, tempdir):
ts_iter = make_timestamp_iter()
db_path = os.path.join(
tempdir, 'part', 'suffix', 'hash', 'container.db')
tempdir, 'containers', 'part', 'suffix', 'hash', 'container.db')
broker = ContainerBroker(db_path, account='a', container='c')
broker.initialize(next(ts_iter).internal, 0)
expected_shard_ranges = []
@ -4416,7 +4419,7 @@ class TestContainerBroker(unittest.TestCase):
# common setup and assertions for root and shard containers
ts_iter = make_timestamp_iter()
db_path = os.path.join(
tempdir, 'part', 'suffix', 'hash', 'container.db')
tempdir, 'containers', 'part', 'suffix', 'hash', 'container.db')
broker = ContainerBroker(
db_path, account=a, container=c)
broker.initialize(next(ts_iter).internal, 0)