Skip to content

Commit

Permalink
Use a HOSTNAME environment variable instead of socket.getfqdn() in Re…
Browse files Browse the repository at this point in the history
…sultLog (#1616)

This makes it possible to prevent an undesired DNS query.

Fixes #1615
  • Loading branch information
hroncok authored Jul 14, 2020
1 parent 9e61b2d commit cfe66fd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
3 changes: 3 additions & 0 deletions docs/changelog/1615.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The ``ResultLog`` now prefers ``HOSTNAME`` environment variable value (if set) over the full qualified domain name of localhost.
This makes it possible to disable an undesired DNS lookup,
which happened on all ``tox`` invocations, including trivial ones - by :user:`hroncok`
3 changes: 2 additions & 1 deletion src/tox/logs/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import absolute_import, unicode_literals

import json
import os
import socket
import sys

Expand All @@ -21,7 +22,7 @@ def __init__(self):
"reportversion": "1",
"toxversion": __version__,
"platform": sys.platform,
"host": socket.getfqdn(),
"host": os.getenv(str("HOSTNAME")) or socket.getfqdn(),
"commands": command_log,
}

Expand Down
26 changes: 24 additions & 2 deletions tests/unit/test_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,23 @@ def create_fake_pkg(tmpdir):
return pkg


def test_pre_set_header():
@pytest.fixture()
def no_hostname_envvar():
hostname = os.getenv("HOSTNAME")
if hostname:
del os.environ["HOSTNAME"]
try:
yield
finally:
try:
del os.environ["HOSTNAME"]
except KeyError:
pass
if hostname:
os.environ["HOSTNAME"] = hostname


def test_pre_set_header(no_hostname_envvar):
replog = ResultLog()
d = replog.dict
assert replog.dict == d
Expand All @@ -30,7 +46,7 @@ def test_pre_set_header():
assert replog2.dict == replog.dict


def test_set_header(pkg):
def test_set_header(pkg, no_hostname_envvar):
replog = ResultLog()
d = replog.dict
assert replog.dict == d
Expand All @@ -48,6 +64,12 @@ def test_set_header(pkg):
assert replog2.dict == replog.dict


def test_hosname_via_envvar(no_hostname_envvar):
os.environ["HOSTNAME"] = "toxicity"
replog = ResultLog()
assert replog.dict["host"] == "toxicity"


def test_addenv_setpython(pkg):
replog = ResultLog()
envlog = replog.get_envlog("py36")
Expand Down

0 comments on commit cfe66fd

Please sign in to comment.