Skip to content

Commit e4a05b2

Browse files
CarstenGrohmannphilpep
authored andcommitted
Add check for the existance of ssh control path directory
1 parent 35d6dec commit e4a05b2

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

testinfra/backend/ssh.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def __init__(
2727
ssh_config: Optional[str] = None,
2828
ssh_identity_file: Optional[str] = None,
2929
timeout: int = 10,
30-
controlpath: str = "",
30+
controlpath: Optional[str] = None,
3131
controlpersist: int = 60,
3232
ssh_extra_args: Optional[str] = None,
3333
*args: Any,

testinfra/utils/ansible_runner.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,18 @@ def get_config(
187187

188188
control_path = config.get("ssh_connection", "control_path", fallback="", raw=True)
189189
if control_path:
190-
directory = config.get(
190+
control_path_dir = config.get(
191191
"persistent_connection", "control_path_dir", fallback="~/.ansible/cp"
192192
)
193-
control_path = control_path % ({"directory": directory}) # noqa: S001
194-
# restore original "%%"
195-
control_path = control_path.replace("%", "%%")
196-
kwargs["controlpath"] = control_path
193+
control_path_dir = os.path.expanduser(control_path_dir)
194+
control_path_dir = os.path.normpath(control_path_dir)
195+
196+
if os.path.isdir(control_path_dir):
197+
control_path = control_path % ( # noqa: S001
198+
{"directory": control_path_dir}
199+
)
200+
control_path = control_path.replace("%", "%%") # restore original "%%"
201+
kwargs["controlpath"] = control_path
197202

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

0 commit comments

Comments
 (0)