Skip to content

Commit

Permalink
Add check for the existance of ssh control path directory
Browse files Browse the repository at this point in the history
  • Loading branch information
CarstenGrohmann authored and philpep committed May 26, 2024
1 parent 35d6dec commit e4a05b2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion testinfra/backend/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(
ssh_config: Optional[str] = None,
ssh_identity_file: Optional[str] = None,
timeout: int = 10,
controlpath: str = "",
controlpath: Optional[str] = None,
controlpersist: int = 60,
ssh_extra_args: Optional[str] = None,
*args: Any,
Expand Down
15 changes: 10 additions & 5 deletions testinfra/utils/ansible_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,18 @@ def get_config(

control_path = config.get("ssh_connection", "control_path", fallback="", raw=True)
if control_path:
directory = config.get(
control_path_dir = config.get(
"persistent_connection", "control_path_dir", fallback="~/.ansible/cp"
)
control_path = control_path % ({"directory": directory}) # noqa: S001
# restore original "%%"
control_path = control_path.replace("%", "%%")
kwargs["controlpath"] = control_path
control_path_dir = os.path.expanduser(control_path_dir)
control_path_dir = os.path.normpath(control_path_dir)

if os.path.isdir(control_path_dir):
control_path = control_path % ( # noqa: S001
{"directory": control_path_dir}
)
control_path = control_path.replace("%", "%%") # restore original "%%"
kwargs["controlpath"] = control_path

spec = "{}://".format(connection)

Expand Down

0 comments on commit e4a05b2

Please sign in to comment.