[SSSD] [PATCH] SSSDConfigTest: Use unique temporary directory

Lukas Slebodnik lslebodn at redhat.com
Mon May 25 13:28:30 UTC 2015


On (22/05/15 16:13), Jakub Hrozek wrote:
>On Thu, May 21, 2015 at 01:43:19PM +0200, Lukas Slebodnik wrote:
>> ehlo,
>> 
>> There were some failed tests in ci log
>> http://sssd-ci.duckdns.org/logs/job/12/67/fedora_rawhide/ci.html
>> http://sssd-ci.duckdns.org/logs/job/14/07/fedora_rawhide/ci.html
>> http://sssd-ci.duckdns.org/logs/job/14/97/debian_testing/ci.html
>> 
>> Attached patch should fix race condition between two SSSDConfigTest tests.
>> The problem is just in master due to python{2,3} changes.
>> 
>> LS
>
>The intent is good, but I would prefer using the setUp() and tearDown()
>methods for creating and removing the directory.
I wanted to left temp dir for analysis,
but code is stable and in case of problem it's easy
to debug with "python -m pdb"

>It's safe because the Python documentation says:
>    If setUp() succeeded, the tearDown() method will be run whether
>    runTest() succeeded or not.
Updated version of attached.

LS
-------------- next part --------------
>From de7bc473b780717402d1642118febb4e3f1896a9 Mon Sep 17 00:00:00 2001
From: Lukas Slebodnik <lslebodn at redhat.com>
Date: Thu, 21 May 2015 13:20:35 +0200
Subject: [PATCH] SSSDConfigTest: Use unique temporary directory

Test SSSDConfigTest is executed twice with make check
if python2 and python3 are available.
Tests are executed in parallel with new automake
and therefore it caused sometimes failures e.g.

ERROR: testModifyExistingConfig (__main__.SSSDConfigTestValid)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/sssd/src/config/SSSDConfigTest.py", line 215, in testModifyExistingConfig
    mode = os.stat(of)[ST_MODE]
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/testModifyExistingConfig.conf'
---
 Makefile.am                  |  1 +
 src/config/SSSDConfigTest.py | 23 +++++++++++++++--------
 2 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 030cf7462186868ff8837b3ff15efb3cf8f7cfaf..cb253158a779591bf6b66cbad7b264f7f8d1794e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1282,6 +1282,7 @@ endif
 # Feature Tests #
 #################
 TESTS_ENVIRONMENT = LDB_MODULES_PATH=$(abs_top_builddir)/ldb_mod_test_dir \
+                    SSS_TEST_DIR=$(TEST_DIR) \
                     $(AUX_TESTS_ENVIRONMENT)
 
 ldb_mod_test_dir: memberof.la
diff --git a/src/config/SSSDConfigTest.py b/src/config/SSSDConfigTest.py
index db16bc433cf4c47c6a15760d85b322a6655aa0c1..ab9d51211e7c33eb9e8ada459a4d6ab4fab174af 100755
--- a/src/config/SSSDConfigTest.py
+++ b/src/config/SSSDConfigTest.py
@@ -6,6 +6,8 @@ Created on Sep 18, 2009
 '''
 import unittest
 import os
+import shutil
+import tempfile
 from stat import *
 
 import sys
@@ -19,12 +21,17 @@ else:
 import SSSDConfig
 
 
+def create_temp_dir():
+    test_dir = os.environ.get('SSS_TEST_DIR') or "."
+    return tempfile.mkdtemp(dir=test_dir)
+
+
 class SSSDConfigTestValid(unittest.TestCase):
     def setUp(self):
-        pass
+        self.tmp_dir = create_temp_dir()
 
     def tearDown(self):
-        pass
+        shutil.rmtree(self.tmp_dir)
 
     def testServices(self):
         sssdconfig = SSSDConfig.SSSDConfig(srcdir + "/etc/sssd.api.conf",
@@ -132,7 +139,7 @@ class SSSDConfigTestValid(unittest.TestCase):
         local_domain.set_active(True)
         sssdconfig.save_domain(local_domain)
 
-        of = '/tmp/testCreateNewLocalConfig.conf'
+        of = self.tmp_dir + '/testCreateNewLocalConfig.conf'
 
         #Ensure the output file doesn't exist
         try:
@@ -166,7 +173,7 @@ class SSSDConfigTestValid(unittest.TestCase):
         ldap_domain.set_active(True)
         sssdconfig.save_domain(ldap_domain)
 
-        of = '/tmp/testCreateNewLDAPConfig.conf'
+        of = self.tmp_dir + '/testCreateNewLDAPConfig.conf'
 
         #Ensure the output file doesn't exist
         try:
@@ -200,7 +207,7 @@ class SSSDConfigTestValid(unittest.TestCase):
         ldap_domain.set_active(True)
         sssdconfig.save_domain(ldap_domain)
 
-        of = '/tmp/testModifyExistingConfig.conf'
+        of = self.tmp_dir + '/testModifyExistingConfig.conf'
 
         #Ensure the output file doesn't exist
         try:
@@ -1134,10 +1141,10 @@ class SSSDConfigTestSSSDDomain(unittest.TestCase):
 
 class SSSDConfigTestSSSDConfig(unittest.TestCase):
     def setUp(self):
-        pass
+        self.tmp_dir = create_temp_dir()
 
     def tearDown(self):
-        pass
+        shutil.rmtree(self.tmp_dir)
 
     def testInit(self):
         # Positive test
@@ -1753,7 +1760,7 @@ class SSSDConfigTestSSSDConfig(unittest.TestCase):
 
         sssdconfig.save_domain(domain)
 
-        of = '/tmp/testSaveDomain.out'
+        of = self.tmp_dir + '/testSaveDomain.out'
 
         #Ensure the output file doesn't exist
         try:
-- 
2.4.1



More information about the sssd-devel mailing list