git » kxd » commit 2af6c08

tests: Use $LOGNAME instead of os.getlogin()

author Alberto Bertogli
2014-07-17 22:38:40 UTC
committer Alberto Bertogli
2014-07-17 22:38:40 UTC
parent 65d281acfc99d0c67bfc2e7d5c1582f79f9dcb3a

tests: Use $LOGNAME instead of os.getlogin()

The tests use os.getlogin() to get the user they're running under, which is
used just for informational names to make troubleshooting easier.

However, that function fails when the controlling terminal isn't a tty; this
is triggered for example by the Debian automated build process, which is how
this bug was originally reported (http://bugs.debian.org/755036).

To fix that, we can just try to get $LOGNAME from the environment, and fall
back to "unknown" if missing, which is harmless.

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>

tests/run_tests +6 -2

diff --git a/tests/run_tests b/tests/run_tests
index a967b3e..23bfadf 100755
--- a/tests/run_tests
+++ b/tests/run_tests
@@ -48,6 +48,10 @@ DEVNULL = open("/dev/null", "w")
 
 TEMPDIR = "/does/not/exist"
 
+# User the script is running as. Just informational, for troubleshooting
+# purposes, so we don't care if it's missing.
+LOGNAME = os.environ.get('LOGNAME', 'unknown')
+
 
 def setUpModule():    # pylint: disable=invalid-name
     if not os.path.isfile(BINS + "/kxd"):
@@ -90,7 +94,7 @@ class Config(object):
         req_args = ["openssl", "req", "-new", "-batch",
                     "-subj", ("/commonName=*" +
                               "/organizationalUnitName=kxd-tests-%s:%s@%s" % (
-                                  self.name, os.getlogin(), platform.node())),
+                                  self.name, LOGNAME, platform.node())),
                     "-key", "%s/key.pem" % self.path]
         if self_sign:
             req_args.extend(["-x509", "-out", "%s/cert.pem" % self.path])
@@ -127,7 +131,7 @@ class CA(object):
                      "-config", OPENSSL_CONF,
                      "-subj", ("/commonName=*" +
                                "/organizationalUnitName=kxd-tests-ca:%s@%s" % (
-                                   os.getlogin(), platform.node())),
+                                   LOGNAME, platform.node())),
                      "-extensions", "v3_ca", "-nodes",
                      "-keyout", "cakey.pem",
                      "-out", "cacert.pem"],