|
30 | 30 | import signal
|
31 | 31 | import socket
|
32 | 32 | import string
|
| 33 | +import sys |
33 | 34 | import subprocess
|
34 | 35 | import tempfile
|
35 | 36 | import unittest
|
@@ -150,15 +151,36 @@ def __init__(self, realm='KRBTEST.COM', portbase=61000,
|
150 | 151 | self.kinit(self.user_princ, self.password('user'))
|
151 | 152 | self.klist()
|
152 | 153 |
|
| 154 | + def _discover_path(self, name, default, paths): |
| 155 | + stderr_out = getattr(subprocess, 'DEVNULL', subprocess.PIPE) |
| 156 | + try: |
| 157 | + path = subprocess.check_output(['which', name], |
| 158 | + stderr=stderr_out).strip() |
| 159 | + path = path.decode(sys.getfilesystemencoding() or |
| 160 | + sys.getdefaultencoding()) |
| 161 | + print("Using discovered path for {name} ({path}".format( |
| 162 | + name=name, path=path)) |
| 163 | + return path |
| 164 | + except subprocess.CalledProcessError as e: |
| 165 | + path = paths.get(name, default) |
| 166 | + print("Using default path for {name} ({path}): {err}".format( |
| 167 | + name=name, path=path, err=e)) |
| 168 | + return path |
| 169 | + |
153 | 170 | def _init_paths(self, **paths):
|
154 |
| - self.kdb5_util = paths.get('kdb5_util', '/usr/sbin/kdb5_util') |
155 |
| - self.krb5kdc = paths.get('krb5kdc', '/usr/sbin/krb5kdc') |
156 |
| - self.kadmin_local = paths.get('kadmin_local', '/usr/sbin/kadmin.local') |
157 |
| - self.kprop = paths.get('kprop', '/usr/sbin/kprop') |
158 |
| - self.kadmind = paths.get('kadmind', '/usr/sbin/kadmind') |
159 |
| - |
160 |
| - self._kinit = paths.get('kinit', '/usr/bin/kinit') |
161 |
| - self._klist = paths.get('klist', '/usr/bin/klist') |
| 171 | + self.kdb5_util = self._discover_path('kdb5_util', |
| 172 | + '/usr/sbin/kdb5_util', paths) |
| 173 | + self.krb5kdc = self._discover_path('krb5kdc', |
| 174 | + '/usr/sbin/krb5kdc', paths) |
| 175 | + self.kadmin_local = self._discover_path('kadmin_local', |
| 176 | + '/usr/sbin/kadmin.local', |
| 177 | + paths) |
| 178 | + self.kprop = self._discover_path('kprop', '/usr/sbin/kprop', paths) |
| 179 | + self.kadmind = self._discover_path('kadmind', |
| 180 | + '/usr/sbin/kadmind', paths) |
| 181 | + |
| 182 | + self._kinit = self._discover_path('kinit', '/usr/bin/kinit', paths) |
| 183 | + self._klist = self._discover_path('klist', '/usr/bin/klist', paths) |
162 | 184 |
|
163 | 185 | def _create_conf(self, profile, filename):
|
164 | 186 | with open(filename, 'w') as conf_file:
|
|
0 commit comments