This repository has been archived by the owner on Apr 24, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable parallel multi-user integration tests with Kerberos (#707)
- Loading branch information
Showing
3 changed files
with
81 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# This file is automatically loaded and run by pytest during its setup process, | ||
# meaning it happens before any of the tests in this directory are run. | ||
# See the pytest documentation on conftest files for more information: | ||
# https://docs.pytest.org/en/2.7.3/plugins.html#conftest-py-plugins | ||
|
||
import os | ||
import subprocess | ||
import threading | ||
import time | ||
|
||
from tests.cook import util | ||
|
||
def _sudo_check(username): | ||
""" | ||
Check if the current user can sudo as a test user. | ||
This is necessary to obtain Kerberos auth headers for multi-user tests. | ||
""" | ||
sudo_ok = (0 == subprocess.call(f'sudo -nu {username} echo CACHED SUDO', shell=True)) | ||
assert sudo_ok, "You need to pre-cache your sudo credentials. (Run a simple sudo command as a test user.)" | ||
|
||
def _sudo_checker_task(username): | ||
"""Periodically check sudo ability to ensure the credentials stay cached.""" | ||
while True: | ||
_sudo_check(username) | ||
time.sleep(60) | ||
|
||
if util.kerberos_enabled() and os.getenv('COOK_MAX_TEST_USERS'): | ||
username = next(util._test_user_names()) | ||
_sudo_check(username) | ||
threading.Thread(target=_sudo_checker_task, args=[username], daemon=True).start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters