Hi all,

this patch fixes problem described in the ticket [1]
that caused the test run to fail completely at every other or so run.
I took the liberty to fix most of the pep8 issues while I was at it.

Thanks to Jan Cholasta for help with identifying this one.

[1]: https://fedorahosted.org/freeipa/ticket/5192

Cheers,
Milan
From b467c5d81ff3cf54363da687132a3f205ef46d15 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Milan=20Kub=C3=ADk?= <mku...@redhat.com>
Date: Mon, 10 Aug 2015 16:16:54 +0200
Subject: [PATCH] tests: fix the list comprehension leak in python 2 and free
 all nss objects

The python 2 feature/bug that binds the last value in a list
comprehension to the variable caused the nss object in the test
being bound at the time when nss.nss_shutdown was called.

This caused an ```NSPRError: (SEC_ERROR_BUSY) NSS could not shutdown.
Objects are still in use.``` exception being thrown that was not caught.
The subsequent calls to nss module corrupted the NSS database and this
led to a cascade of another errors invalidating the whole test run.

The patch works around this python 2 issue.

Fixes: https://fedorahosted.org/freeipa/ticket/5192
---
 ipatests/test_ipaserver/test_otptoken_import.py | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/ipatests/test_ipaserver/test_otptoken_import.py b/ipatests/test_ipaserver/test_otptoken_import.py
index c8818a01ea4d4bad4b4a0f656357f7b32407b86a..7268ace35764df6f30036e2c17f8197bff01c6ea 100644
--- a/ipatests/test_ipaserver/test_otptoken_import.py
+++ b/ipatests/test_ipaserver/test_otptoken_import.py
@@ -19,7 +19,6 @@
 
 import os
 import sys
-import nose
 from nss import nss
 from ipalib.x509 import initialize_nss_database
 
@@ -27,6 +26,7 @@ from ipaserver.install.ipa_otptoken_import import PSKCDocument, ValidationError
 
 basename = os.path.join(os.path.dirname(__file__), "data")
 
+
 class test_otptoken_import(object):
 
     def teardown(self):
@@ -50,7 +50,7 @@ class test_otptoken_import(object):
         assert doc.keyname is None
         try:
             [(t.id, t.options) for t in doc.getKeyPackages()]
-        except ValidationError: # Referenced keys are not supported.
+        except ValidationError:  # Referenced keys are not supported.
             pass
         else:
             assert False
@@ -60,7 +60,7 @@ class test_otptoken_import(object):
         assert doc.keyname is None
         try:
             [(t.id, t.options) for t in doc.getKeyPackages()]
-        except ValidationError: # PIN Policy is not supported.
+        except ValidationError:  # PIN Policy is not supported.
             pass
         else:
             assert False
@@ -79,6 +79,10 @@ class test_otptoken_import(object):
                     'ipatokenhotpcounter': 0,
                     'ipatokenotpdigits': 8,
                     'type': u'hotp'})]
+            # should fix the list comprehension leak in python 2
+            # python -c '[x for x in [1, 2]]; print(x)'
+            if sys.version_info.major == 2:
+                del t
         finally:
             nss.nss_shutdown()
 
@@ -95,6 +99,9 @@ class test_otptoken_import(object):
                     'ipatokenserial': u'987654321',
                     'ipatokenotpdigits': 8,
                     'type': u'hotp'})]
+
+            if sys.version_info.major == 2:
+                del t
         finally:
             nss.nss_shutdown()
 
@@ -102,7 +109,7 @@ class test_otptoken_import(object):
         nss.nss_init_nodb()
         try:
             doc = PSKCDocument(os.path.join(basename, "pskc-figure8.xml"))
-        except NotImplementedError: # X.509 is not supported.
+        except NotImplementedError:  # X.509 is not supported.
             pass
         else:
             assert False
@@ -113,7 +120,7 @@ class test_otptoken_import(object):
         nss.nss_init_nodb()
         try:
             doc = PSKCDocument(os.path.join(basename, "pskc-invalid.xml"))
-        except ValueError: # File is invalid.
+        except ValueError:  # File is invalid.
             pass
         else:
             assert False
@@ -125,7 +132,10 @@ class test_otptoken_import(object):
         try:
             doc = PSKCDocument(os.path.join(basename, "pskc-mini.xml"))
             [(t.id, t.options) for t in doc.getKeyPackages()]
-        except ValidationError: # Unsupported token type.
+
+            if sys.version_info.major == 2:
+                del t
+        except ValidationError:  # Unsupported token type.
             pass
         else:
             assert False
@@ -152,5 +162,8 @@ class test_otptoken_import(object):
                     'ipatokenotpdigits': 8,
                     'type': u'hotp',
                 })]
+
+            if sys.version_info.major == 2:
+                del t
         finally:
             nss.nss_shutdown()
-- 
2.5.0

-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to