@@ -146,6 +146,7 @@ def host(request, tmpdir_factory):
146
146
fname = f"_docker_container_{ spec .name } _{ scope } "
147
147
docker_id , docker_host , port = request .getfixturevalue (fname )
148
148
149
+ hostname = None
149
150
if kw ["connection" ] == "docker" :
150
151
hostname = docker_id
151
152
elif kw ["connection" ] in ("ansible" , "ssh" , "paramiko" , "safe-ssh" ):
@@ -154,7 +155,7 @@ def host(request, tmpdir_factory):
154
155
key = tmpdir .join ("ssh_key" )
155
156
with open (os .path .join (BASETESTDIR , "ssh_key" )) as f :
156
157
key .write (f .read ())
157
- key .chmod (384 ) # octal 600
158
+ key .chmod (0o600 )
158
159
if kw ["connection" ] == "ansible" :
159
160
setup_ansible_config (
160
161
tmpdir , hostname , docker_host , spec .user or "root" , port , str (key )
@@ -184,10 +185,10 @@ def host(request, tmpdir_factory):
184
185
while not service (service_name ).is_running :
185
186
time .sleep (0.5 )
186
187
187
- if kw ["connection" ] != "ansible" :
188
- hostspec = (spec .user or "root" ) + "@" + hostname
189
- else :
188
+ if kw ["connection" ] == "ansible" :
190
189
hostspec = spec .name
190
+ else :
191
+ hostspec = f"{ spec .user or 'root' } @{ hostname or spec .name } "
191
192
192
193
b = testinfra .host .get_host (hostspec , ** kw )
193
194
b .backend .get_hostname = lambda : image
0 commit comments