Update Copyright header point to COPYING file
[cascardo/ipsilon.git] / tests / tests.py
index 4690442..7a7b168 100755 (executable)
@@ -1,31 +1,16 @@
 #!/usr/bin/python
 #
-# Copyright (C) 2014  Simo Sorce <simo@redhat.com>
-#
-# see file 'COPYING' for use and warranty information
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+# Copyright (C) 2014 Ipsilon project Contributors, for license see COPYING
 
 import argparse
-from datetime import datetime
 import inspect
 from ipsilon.util import plugin
-import logging
 import os
 import sys
 import subprocess
+import time
 import traceback
+from helpers.common import WRAP_HOSTNAME  # pylint: disable=relative-import
 
 
 logger = None
@@ -52,22 +37,6 @@ def parse_args():
     return vars(parser.parse_args())
 
 
-def openlogs(path, name):
-    global logger  # pylint: disable=W0603
-    logger = logging.getLogger()
-    try:
-        datestr = datetime.now().strftime("%Y-%m-%d_%H:%M:%S")
-        filename = '%s/test-%s-%s.log' % (path, name, datestr)
-        lh = logging.FileHandler(filename)
-    except IOError, e:
-        print >> sys.stderr, 'Unable to open %s (%s)' % (filename, str(e))
-        lh = logging.StreamHandler(sys.stderr)
-    formatter = logging.Formatter('[%(asctime)s] %(message)s')
-    lh.setFormatter(formatter)
-    logger.addHandler(lh)
-    logger.setLevel(logging.DEBUG)
-
-
 def try_wrappers(base, wrappers):
     if wrappers == 'no':
         return {}
@@ -80,12 +49,27 @@ def try_wrappers(base, wrappers):
         else:
             raise ValueError('Socket Wrappers not available')
 
+    pkgcfg = subprocess.Popen(['pkg-config', '--exists', 'nss_wrapper'])
+    pkgcfg.wait()
+    if pkgcfg.returncode != 0:
+        if wrappers == 'auto':
+            return {}
+        else:
+            raise ValueError('Nss Wrappers not available')
+
     wrapdir = os.path.join(base, 'wrapdir')
     os.mkdir(wrapdir)
 
-    wenv = {'LD_PRELOAD': 'libsocket_wrapper.so',
+    hosts_file = os.path.join(base, 'hosts')
+    with open(hosts_file, 'w+') as f:
+        f.write('127.0.0.9 %s\n' % WRAP_HOSTNAME)
+
+    wenv = {'LD_PRELOAD': 'libsocket_wrapper.so libnss_wrapper.so',
             'SOCKET_WRAPPER_DIR': wrapdir,
-            'SOCKET_WRAPPER_DEFAULT_IFACE': '9'}
+            'SOCKET_WRAPPER_DEFAULT_IFACE': '9',
+            'SOCKET_WRAPPER_DEBUGLEVEL': '1',
+            'NSS_WRAPPER_HOSTNAME': WRAP_HOSTNAME,
+            'NSS_WRAPPER_HOSTS': hosts_file}
 
     return wenv
 
@@ -103,12 +87,11 @@ if __name__ == '__main__':
     if not os.path.exists(args['path']):
         os.makedirs(args['path'])
 
-    openlogs(args['path'], args['test'])
-
     test.setup_base(args['path'], test)
 
     env = try_wrappers(test.testdir, args['wrappers'])
     env['PYTHONPATH'] = test.rootdir
+    env['TESTDIR'] = test.testdir
 
     try:
         test.setup_servers(env)
@@ -123,4 +106,6 @@ if __name__ == '__main__':
     finally:
         test.wait()
 
+    # Wait until all of the sockets are closed by the OS
+    time.sleep(0.5)
     print "FINISHED"