avocado: Pass prefix on calls to tempfile.mkdtemp()

Make sure we have avocado_ + __name__ prefixes to the dirs
created with tempfile, so that we have an easy way to spot
when we are not cleaning up directories properly. This mostly
concerns unittests, although the kernel_build lib and the
iso9660 lib also uses that API.
Signed-off-by: NLucas Meneghel Rodrigues <lmr@redhat.com>
上级 ce97b402
......@@ -127,7 +127,7 @@ class Job(object):
self.logdir = data_dir.create_job_logs_dir(logdir=logdir,
unique_id=self.unique_id)
else:
self.logdir = tempfile.mkdtemp(prefix='avocado-')
self.logdir = tempfile.mkdtemp(prefix='avocado_' + __name__)
else:
if logdir is None:
self.logdir = data_dir.create_job_logs_dir(unique_id=self.unique_id)
......
......@@ -69,7 +69,7 @@ def make_dir_and_populate(basedir='/tmp'):
:rtype: str
"""
try:
path = tempfile.mkdtemp(prefix='avocado-make-dir-and-populate',
path = tempfile.mkdtemp(prefix='avocado_' + __name__,
dir=basedir)
n_files = _RAND_POOL.randint(100, 150)
for _ in xrange(n_files):
......
......@@ -231,7 +231,7 @@ class Iso9660IsoRead(BaseIso9660):
def __init__(self, path):
super(Iso9660IsoRead, self).__init__(path)
self.temp_dir = tempfile.mkdtemp()
self.temp_dir = tempfile.mkdtemp(prefix='avocado_' + __name__)
def read(self, path):
temp_file = os.path.join(self.temp_dir, path)
......@@ -261,7 +261,7 @@ class Iso9660Mount(BaseIso9660):
:type path: str
"""
super(Iso9660Mount, self).__init__(path)
self.mnt_dir = tempfile.mkdtemp()
self.mnt_dir = tempfile.mkdtemp(prefix='avocado_' + __name__)
process.run('mount -t iso9660 -v -o loop,ro %s %s' %
(path, self.mnt_dir))
......
......@@ -46,7 +46,7 @@ class KernelBuild(object):
self.version = version
self.config_path = config_path
if work_dir is None:
work_dir = tempfile.mkdtemp()
work_dir = tempfile.mkdtemp(prefix='avocado_' + __name__)
self.work_dir = work_dir
self.build_dir = os.path.join(self.work_dir, 'build')
if not os.path.isdir(self.build_dir):
......
......@@ -57,7 +57,7 @@ class VMCleanup(Test):
'been given. Please edit the "vm-cleanup.yaml" file '
'with the appropriate parameters')
self.tmpdir = tempfile.mkdtemp()
self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__)
clean_test = os.path.join(self.tmpdir, 'clean.py')
self.clean_test_path = script.make_script(clean_test, CLEAN_TEST)
dirty_test = os.path.join(self.tmpdir, 'dirty.py')
......
......@@ -58,7 +58,7 @@ class HelloWorld(Plugin):
class RunnerOperationTest(unittest.TestCase):
def setUp(self):
self.tmpdir = tempfile.mkdtemp()
self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__)
def test_runner_all_ok(self):
os.chdir(basedir)
......@@ -264,7 +264,7 @@ class RunnerOperationTest(unittest.TestCase):
class RunnerHumanOutputTest(unittest.TestCase):
def setUp(self):
self.tmpdir = tempfile.mkdtemp()
self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__)
def test_output_pass(self):
os.chdir(basedir)
......@@ -306,11 +306,14 @@ class RunnerHumanOutputTest(unittest.TestCase):
(expected_rc, result))
self.assertIn('skiponsetup.py:SkipOnSetupTest.test_wont_be_executed: SKIP', result.stdout)
def tearDown(self):
shutil.rmtree(self.tmpdir)
class RunnerSimpleTest(unittest.TestCase):
def setUp(self):
self.tmpdir = tempfile.mkdtemp()
self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__)
self.pass_script = script.TemporaryScript(
'avocado_pass.sh',
PASS_SCRIPT_CONTENTS,
......@@ -402,7 +405,7 @@ class RunnerSimpleTest(unittest.TestCase):
class InnerRunnerTest(unittest.TestCase):
def setUp(self):
self.tmpdir = tempfile.mkdtemp()
self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__)
self.pass_script = script.TemporaryScript(
'pass',
PASS_SHELL_CONTENTS,
......@@ -456,8 +459,8 @@ class InnerRunnerTest(unittest.TestCase):
class ExternalPluginsTest(unittest.TestCase):
def setUp(self):
self.base_sourcedir = tempfile.mkdtemp(prefix='avocado_source_plugins')
self.tmpdir = tempfile.mkdtemp()
self.base_sourcedir = tempfile.mkdtemp(prefix='avocado_' + __name__)
self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__)
def test_void_plugin(self):
self.void_plugin = script.make_script(
......@@ -498,7 +501,7 @@ class ExternalPluginsTest(unittest.TestCase):
class AbsPluginsTest(object):
def setUp(self):
self.base_outputdir = tempfile.mkdtemp(prefix='avocado_plugins')
self.base_outputdir = tempfile.mkdtemp(prefix='avocado_' + __name__)
def tearDown(self):
shutil.rmtree(self.base_outputdir)
......@@ -592,7 +595,7 @@ class ParseXMLError(Exception):
class PluginsXunitTest(AbsPluginsTest, unittest.TestCase):
def setUp(self):
self.tmpdir = tempfile.mkdtemp()
self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__)
super(PluginsXunitTest, self).setUp()
def run_and_check(self, testname, e_rc, e_ntests, e_nerrors,
......@@ -662,7 +665,7 @@ class ParseJSONError(Exception):
class PluginsJSONTest(AbsPluginsTest, unittest.TestCase):
def setUp(self):
self.tmpdir = tempfile.mkdtemp()
self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__)
super(PluginsJSONTest, self).setUp()
def run_and_check(self, testname, e_rc, e_ntests, e_nerrors,
......
......@@ -38,7 +38,7 @@ test "$AVOCADO_VERSION" = "{version}" -a \
class EnvironmentVariablesTest(unittest.TestCase):
def setUp(self):
self.tmpdir = tempfile.mkdtemp()
self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__)
self.script = script.TemporaryScript(
'version.sh',
SCRIPT_CONTENT,
......
......@@ -14,7 +14,7 @@ basedir = os.path.abspath(basedir)
class GDBPluginTest(unittest.TestCase):
def setUp(self):
self.tmpdir = tempfile.mkdtemp()
self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__)
def test_gdb_prerun_commands(self):
os.chdir(basedir)
......
......@@ -50,7 +50,7 @@ if __name__ == "__main__":
class InterruptTest(unittest.TestCase):
def setUp(self):
self.tmpdir = tempfile.mkdtemp()
self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__)
def test_badly_behaved(self):
"""
......
......@@ -52,7 +52,7 @@ class JobTimeOutTest(unittest.TestCase):
PYTHON_CONTENT,
'avocado_timeout_functional')
self.py.save()
self.tmpdir = tempfile.mkdtemp()
self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__)
os.chdir(basedir)
def run_and_check(self, cmd_line, e_rc, e_ntests, e_nerrors, e_nfailures,
......
......@@ -17,7 +17,7 @@ class JournalPluginTests(unittest.TestCase):
def setUp(self):
os.chdir(basedir)
self.tmpdir = tempfile.mkdtemp()
self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__)
self.cmd_line = ('./scripts/avocado run --job-results-dir %s --sysinfo=off --json - '
'--journal examples/tests/passtest.py' % self.tmpdir)
self.result = process.run(self.cmd_line, ignore_status=True)
......
......@@ -63,7 +63,7 @@ class LoaderTestFunctional(unittest.TestCase):
def setUp(self):
os.chdir(basedir)
self.tmpdir = tempfile.mkdtemp()
self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__)
def _test(self, name, content, exp_str, mode=0664):
test_script = script.TemporaryScript(name, content,
......
......@@ -31,7 +31,7 @@ DEBUG_OUT = """Variant 16: amd@examples/mux-environment.yaml, virtio@examples
class MultiplexTests(unittest.TestCase):
def setUp(self):
self.tmpdir = tempfile.mkdtemp()
self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__)
def run_and_check(self, cmd_line, expected_rc):
os.chdir(basedir)
......
......@@ -22,7 +22,7 @@ basedir = os.path.abspath(basedir)
class OutputTest(unittest.TestCase):
def setUp(self):
self.tmpdir = tempfile.mkdtemp()
self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__)
def test_output_doublefree(self):
os.chdir(basedir)
......@@ -45,7 +45,7 @@ class OutputTest(unittest.TestCase):
class OutputPluginTest(unittest.TestCase):
def setUp(self):
self.tmpdir = tempfile.mkdtemp()
self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__)
def check_output_files(self, debug_log):
base_dir = os.path.dirname(debug_log)
......@@ -129,9 +129,9 @@ class OutputPluginTest(unittest.TestCase):
pass
def test_output_compatible_setup_3(self):
tmpfile = tempfile.mktemp()
tmpfile2 = tempfile.mktemp()
tmpdir = tempfile.mkdtemp()
tmpfile = tempfile.mktemp(prefix='avocado_' + __name__)
tmpfile2 = tempfile.mktemp(prefix='avocado_' + __name__)
tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__)
tmpfile3 = tempfile.mktemp(dir=tmpdir)
os.chdir(basedir)
cmd_line = ('./scripts/avocado run --job-results-dir %s --sysinfo=off --xunit %s --json %s --html %s passtest' %
......
......@@ -24,7 +24,7 @@ echo "Hello, avocado!"
class RunnerSimpleTest(unittest.TestCase):
def setUp(self):
self.tmpdir = tempfile.mkdtemp()
self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__)
self.output_script = script.TemporaryScript(
'output_check.sh',
OUTPUT_SCRIPT_CONTENTS,
......
......@@ -18,7 +18,7 @@ basedir = os.path.abspath(basedir)
class SysInfoTest(unittest.TestCase):
def setUp(self):
self.tmpdir = tempfile.mkdtemp()
self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__)
def test_sysinfo_enabled(self):
os.chdir(basedir)
......
......@@ -118,7 +118,7 @@ if __name__ == '__main__':
class ProcessTest(unittest.TestCase):
def setUp(self):
self.base_logdir = tempfile.mkdtemp(prefix='avocado_process_functional')
self.base_logdir = tempfile.mkdtemp(prefix='avocado_' + __name__)
self.fake_vmstat = os.path.join(self.base_logdir, 'vmstat')
with open(self.fake_vmstat, 'w') as fake_vmstat_obj:
fake_vmstat_obj.write(FAKE_VMSTAT_CONTENTS)
......
......@@ -25,7 +25,7 @@ exec -- $@
class WrapperTest(unittest.TestCase):
def setUp(self):
self.tmpdir = tempfile.mkdtemp()
self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__)
self.tmpfile = tempfile.mktemp()
self.script = script.TemporaryScript(
'success.sh',
......
......@@ -13,7 +13,7 @@ from avocado.utils import data_factory
class ArchiveTest(unittest.TestCase):
def setUp(self):
self.basedir = tempfile.mkdtemp(prefix='archive_datadir_unittest')
self.basedir = tempfile.mkdtemp(prefix='avocado_' + __name__)
self.compressdir = tempfile.mkdtemp(dir=self.basedir)
self.decompressdir = tempfile.mkdtemp(dir=self.basedir)
self.sys_random = random.SystemRandom()
......
......@@ -20,7 +20,7 @@ def _get_bogus_settings(args):
class DataDirTest(unittest.TestCase):
def setUp(self):
tbase = tempfile.mkdtemp(prefix='avocado_datadir_unittest')
tbase = tempfile.mkdtemp(prefix='avocado_' + __name__)
tdir = os.path.join(tbase, 'tests')
tdata = os.path.join(tbase, 'data')
tlogs = os.path.join(tbase, 'logs')
......
......@@ -42,7 +42,7 @@ class JSONResultTest(unittest.TestCase):
pass
self.tmpfile = tempfile.mkstemp()
self.tmpdir = tempfile.mkdtemp()
self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__)
args = argparse.Namespace(json_output=self.tmpfile[1])
stream = _Stream()
stream.logfile = 'debug.log'
......
......@@ -30,7 +30,7 @@ class TestClassTest(unittest.TestCase):
self.assertTrue(variable)
self.whiteboard = 'foo'
self.base_logdir = tempfile.mkdtemp(prefix='avocado_test_unittest')
self.base_logdir = tempfile.mkdtemp(prefix='avocado_' + __name__)
self.tst_instance_pass = AvocadoPass(base_logdir=self.base_logdir)
self.tst_instance_pass.run_avocado()
self.tst_instance_pass_new = AvocadoPass(base_logdir=self.base_logdir)
......@@ -74,7 +74,7 @@ class TestClassTest(unittest.TestCase):
class SimpleTestClassTest(unittest.TestCase):
def setUp(self):
self.tmpdir = tempfile.mkdtemp()
self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__)
self.pass_script = script.TemporaryScript(
'avocado_pass.sh',
PASS_SCRIPT_CONTENTS,
......
......@@ -46,7 +46,7 @@ class xUnitSucceedTest(unittest.TestCase):
pass
self.tmpfile = tempfile.mkstemp()
self.tmpdir = tempfile.mkdtemp()
self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__)
args = argparse.Namespace()
args.xunit_output = self.tmpfile[1]
self.test_result = xunit.xUnitTestResult(stream=_Stream(), args=args)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册