Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def host(request, tmpdir_factory):
fname = f"_docker_container_{spec.name}_{scope}"
docker_id, docker_host, port = request.getfixturevalue(fname)

hostname = None
if kw["connection"] == "docker":
hostname = docker_id
elif kw["connection"] in ("ansible", "ssh", "paramiko", "safe-ssh"):
Expand All @@ -154,7 +155,7 @@ def host(request, tmpdir_factory):
key = tmpdir.join("ssh_key")
with open(os.path.join(BASETESTDIR, "ssh_key")) as f:
key.write(f.read())
key.chmod(384) # octal 600
key.chmod(0o600)
if kw["connection"] == "ansible":
setup_ansible_config(
tmpdir, hostname, docker_host, spec.user or "root", port, str(key)
Expand Down Expand Up @@ -184,10 +185,10 @@ def host(request, tmpdir_factory):
while not service(service_name).is_running:
time.sleep(0.5)

if kw["connection"] != "ansible":
hostspec = (spec.user or "root") + "@" + hostname
else:
if kw["connection"] == "ansible":
hostspec = spec.name
else:
hostspec = f"{spec.user or 'root'}@{hostname or spec.name}"

b = testinfra.host.get_host(hostspec, **kw)
b.backend.get_hostname = lambda: image
Expand Down
7 changes: 2 additions & 5 deletions testinfra/modules/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def _iter_sockets(self, listening):
splitted = line.split()
# FreeBSD: tcp4/tcp6
# OpeNBSD/NetBSD: tcp/tcp6
if splitted[0] in ("tcp", "udp", "udp4", "tcp4", "tcp6", "udp6"):
if splitted[0] in ("tcp", "tcp4", "tcp6", "udp", "udp4", "udp6"):
address = splitted[3]
if address == "*.*":
# On OpenBSD 6.3 (issue #338)
Expand All @@ -337,10 +337,7 @@ def _iter_sockets(self, listening):

if host == "*":
host = "::" if splitted[0] in ("udp6", "tcp6") else "0.0.0.0"
if splitted[0] in ("udp", "udp6", "udp4"):
protocol = "udp"
elif splitted[0] in ("tcp", "tcp6", "tcp4"):
protocol = "tcp"
protocol = "udp" if splitted[0] in ("udp", "udp6", "udp4") else "tcp"

remote = splitted[4]
if remote == "*.*" and listening:
Expand Down