[apparmor] [PATCH v2 8/8] utils: Fix apparmor.easyprof import in test-aa-easyprof.py
Tyler Hicks
tyhicks at canonical.com
Wed Mar 1 20:52:06 UTC 2017
The test-aa-easyprof.py script was attempting to do its own special
setup to import the in-tree easyprof module. However, this proved to be
very flaky and resulted in the test periodically failing due to an
AttributeError the first time easyprof.parse_args() was called.
This patch removes the flakiness by trusting that PYTHONPATH is set up
appropriately before the test script is ran. PYTHONPATH is already
initialized appropriately by utils/test/Makefile according to the
USE_SYSTEM make variable.
Signed-off-by: Tyler Hicks <tyhicks at canonical.com>
Cc: Christian Boltz <apparmor at cboltz.de>
---
utils/test/test-aa-easyprof.py | 26 ++------------------------
1 file changed, 2 insertions(+), 24 deletions(-)
diff --git a/utils/test/test-aa-easyprof.py b/utils/test/test-aa-easyprof.py
index e7916de..ff69c42 100755
--- a/utils/test/test-aa-easyprof.py
+++ b/utils/test/test-aa-easyprof.py
@@ -18,6 +18,8 @@ import sys
import tempfile
import unittest
+import apparmor.easyprof as easyprof
+
topdir = None
debugging = False
@@ -2673,40 +2675,16 @@ POLICYGROUPS_DIR="%s/templates"
# Main
#
if __name__ == '__main__':
- def cleanup(files):
- for f in files:
- if os.path.exists(f):
- os.unlink(f)
-
absfn = os.path.abspath(sys.argv[0])
topdir = os.path.dirname(os.path.dirname(absfn))
if len(sys.argv) > 1 and (sys.argv[1] == '-d' or sys.argv[1] == '--debug'):
debugging = True
- created = []
-
- # Create the necessary files to import aa-easyprof
- init = os.path.join(os.path.dirname(absfn), '__init__.py')
- if not os.path.exists(init):
- open(init, 'a').close()
- created.append(init)
-
- symlink = os.path.join(os.path.dirname(absfn), 'easyprof.py')
- if not os.path.exists(symlink):
- os.symlink(os.path.join(topdir, 'apparmor', 'easyprof.py'), symlink)
- created.append(symlink)
- created.append(symlink + 'c')
-
- # Now that we have everything we need, import aa-easyprof
- import easyprof
-
# run the tests
suite = unittest.TestSuite()
suite.addTest(unittest.TestLoader().loadTestsFromTestCase(T))
rc = unittest.TextTestRunner(verbosity=2).run(suite)
- cleanup(created)
-
if not rc.wasSuccessful():
sys.exit(1)
--
2.7.4
More information about the AppArmor
mailing list