147 lines
5.3 KiB
Diff
147 lines
5.3 KiB
Diff
|
From c53781ec735a14c346fa111749ac02030e550fb5 Mon Sep 17 00:00:00 2001
|
||
|
From: Lukas Slebodnik <lslebodn@redhat.com>
|
||
|
Date: Wed, 13 Jan 2016 15:06:06 +0100
|
||
|
Subject: [PATCH 56/86] TESTS: Fix race condition in python test
|
||
|
|
||
|
Python tests for pyhbac and pysss_murmur created symbolic
|
||
|
links in shared directory ".libs". It happened that both
|
||
|
tests created symbolic link in the same time and therefore
|
||
|
python2 test could try to import link to python3 module
|
||
|
which caused failures in tests.
|
||
|
|
||
|
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
|
||
|
(cherry picked from commit 9e1de5c83371d91e200254cceef70852f5f94fd2)
|
||
|
(cherry picked from commit 94bafaad2401bc647a31a22953ad2d985c88b06e)
|
||
|
---
|
||
|
src/tests/pyhbac-test.py | 33 ++++++++++++++++-----------------
|
||
|
src/tests/pysss_murmur-test.py | 33 ++++++++++++++++-----------------
|
||
|
2 files changed, 32 insertions(+), 34 deletions(-)
|
||
|
|
||
|
diff --git a/src/tests/pyhbac-test.py b/src/tests/pyhbac-test.py
|
||
|
index 9d8fd1a333bf54ecf21d14d3b6293f7294a0d53e..09867311ed42cad1e3b44e10616edb084716ce10 100755
|
||
|
--- a/src/tests/pyhbac-test.py
|
||
|
+++ b/src/tests/pyhbac-test.py
|
||
|
@@ -5,11 +5,12 @@ import unittest
|
||
|
import sys
|
||
|
import os
|
||
|
import copy
|
||
|
-import sys
|
||
|
-import errno
|
||
|
+import tempfile
|
||
|
+
|
||
|
+BUILD_DIR = os.getenv('builddir') or "."
|
||
|
+TEST_DIR = os.getenv('SSS_TEST_DIR') or "."
|
||
|
+MODPATH = tempfile.mkdtemp(prefix="tp_pyhbac_", dir=TEST_DIR)
|
||
|
|
||
|
-srcdir = os.getenv('builddir') or "."
|
||
|
-MODPATH = srcdir + "/.libs" #FIXME - is there a way to get this from libtool?
|
||
|
|
||
|
if sys.version_info[0] > 2:
|
||
|
unicode = str
|
||
|
@@ -40,22 +41,15 @@ class PyHbacImport(unittest.TestCase):
|
||
|
def testImport(self):
|
||
|
" Import the module and assert it comes from tree "
|
||
|
try:
|
||
|
- cwd_backup = os.getcwd()
|
||
|
+ dest_module_path = MODPATH + "/pyhbac.so"
|
||
|
|
||
|
- try:
|
||
|
- os.unlink(MODPATH + "/pyhbac.so")
|
||
|
- except OSError as e:
|
||
|
- if e.errno == errno.ENOENT:
|
||
|
- pass
|
||
|
- else:
|
||
|
- raise e
|
||
|
-
|
||
|
- os.chdir(MODPATH)
|
||
|
if sys.version_info[0] > 2:
|
||
|
- os.symlink("_py3hbac.so", "pyhbac.so")
|
||
|
+ src_module_path = BUILD_DIR + "/.libs/_py3hbac.so"
|
||
|
else:
|
||
|
- os.symlink("_py2hbac.so", "pyhbac.so")
|
||
|
- os.chdir(cwd_backup)
|
||
|
+ src_module_path = BUILD_DIR + "/.libs/_py2hbac.so"
|
||
|
+
|
||
|
+ src_module_path = os.path.abspath(src_module_path)
|
||
|
+ os.symlink(src_module_path, dest_module_path)
|
||
|
|
||
|
import pyhbac
|
||
|
except ImportError as e:
|
||
|
@@ -456,6 +450,11 @@ class PyHbacRequestTest(unittest.TestCase):
|
||
|
self.assertRaises(TypeError, req.evaluate, (allow_rule, None))
|
||
|
|
||
|
class PyHbacModuleTest(unittest.TestCase):
|
||
|
+ @classmethod
|
||
|
+ def tearDownClass(cls):
|
||
|
+ os.unlink(MODPATH + "/pyhbac.so")
|
||
|
+ os.rmdir(MODPATH)
|
||
|
+
|
||
|
def testHasResultTypes(self):
|
||
|
assert hasattr(pyhbac, "HBAC_EVAL_ALLOW")
|
||
|
assert hasattr(pyhbac, "HBAC_EVAL_DENY")
|
||
|
diff --git a/src/tests/pysss_murmur-test.py b/src/tests/pysss_murmur-test.py
|
||
|
index faa8bb2d33b9d94d380b8f7045ba45aa06ac4793..1cbbe4d03172804ef16b630d3dd1c3a22e09a20a 100755
|
||
|
--- a/src/tests/pysss_murmur-test.py
|
||
|
+++ b/src/tests/pysss_murmur-test.py
|
||
|
@@ -22,11 +22,12 @@ from __future__ import print_function
|
||
|
import unittest
|
||
|
import sys
|
||
|
import os
|
||
|
-import copy
|
||
|
-import errno
|
||
|
+import tempfile
|
||
|
+
|
||
|
+BUILD_DIR = os.getenv('builddir') or "."
|
||
|
+TEST_DIR = os.getenv('SSS_TEST_DIR') or "."
|
||
|
+MODPATH = tempfile.mkdtemp(prefix="tp_pysss_murmur_", dir=TEST_DIR)
|
||
|
|
||
|
-srcdir = os.getenv('builddir') or "."
|
||
|
-MODPATH = srcdir + "/.libs" #FIXME - is there a way to get this from libtool?
|
||
|
|
||
|
def compat_assertItemsEqual(this, expected_seq, actual_seq, msg=None):
|
||
|
return this.assertEqual(sorted(expected_seq), sorted(actual_seq))
|
||
|
@@ -56,22 +57,15 @@ class PySssMurmurImport(unittest.TestCase):
|
||
|
def testImport(self):
|
||
|
" Import the module and assert it comes from tree "
|
||
|
try:
|
||
|
- cwd_backup = os.getcwd()
|
||
|
+ dest_module_path = MODPATH + "/pysss_murmur.so"
|
||
|
|
||
|
- try:
|
||
|
- os.unlink(MODPATH + "/pysss_murmur.so")
|
||
|
- except OSError as e:
|
||
|
- if e.errno == errno.ENOENT:
|
||
|
- pass
|
||
|
- else:
|
||
|
- raise e
|
||
|
-
|
||
|
- os.chdir(MODPATH)
|
||
|
if sys.version_info[0] > 2:
|
||
|
- os.symlink("_py3sss_murmur.so", "pysss_murmur.so")
|
||
|
+ src_module_path = BUILD_DIR + "/.libs/_py3sss_murmur.so"
|
||
|
else:
|
||
|
- os.symlink("_py2sss_murmur.so", "pysss_murmur.so")
|
||
|
- os.chdir(cwd_backup)
|
||
|
+ src_module_path = BUILD_DIR + "/.libs/_py2sss_murmur.so"
|
||
|
+
|
||
|
+ src_module_path = os.path.abspath(src_module_path)
|
||
|
+ os.symlink(src_module_path, dest_module_path)
|
||
|
|
||
|
import pysss_murmur
|
||
|
except ImportError as e:
|
||
|
@@ -80,6 +74,11 @@ class PySssMurmurImport(unittest.TestCase):
|
||
|
self.assertEqual(pysss_murmur.__file__, MODPATH + "/pysss_murmur.so")
|
||
|
|
||
|
class PySssMurmurTest(unittest.TestCase):
|
||
|
+ @classmethod
|
||
|
+ def tearDownClass(cls):
|
||
|
+ os.unlink(MODPATH + "/pysss_murmur.so")
|
||
|
+ os.rmdir(MODPATH)
|
||
|
+
|
||
|
def testExpectedHash(self):
|
||
|
hash = pysss_murmur.murmurhash3("S-1-5-21-2153326666-2176343378-3404031434", 41, 0xdeadbeef)
|
||
|
self.assertEqual(hash, 93103853)
|
||
|
--
|
||
|
2.5.0
|
||
|
|