Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a HOSTNAME environment variable instead of socket.getfqdn() in ResultLog #1616

Merged
merged 1 commit into from Jul 14, 2020

Conversation

hroncok
Copy link
Contributor

@hroncok hroncok commented Jul 14, 2020

This makes it possible to prevent an undesired DNS query.

Fixes #1615

Thanks for contributing a pull request!

If you are contributing for the first time or provide a trivial fix don't worry too
much about the checklist - we will help you get started.

Contribution checklist:

(also see CONTRIBUTING.rst for details)

  • wrote descriptive pull request text
  • added/updated test(s)
  • updated/extended the documentation
  • added relevant issue keyword in message body
  • added news fragment in changelog folder
  • added yourself to CONTRIBUTORS (preserving alphabetical order)

Not quite sure where to document this behavior.

…sultLog

This makes it possible to prevent an undesired DNS query.

Fixes tox-dev#1615
@gaborbernat gaborbernat merged commit cfe66fd into tox-dev:master Jul 14, 2020
1 check passed
@hroncok hroncok deleted the hostname_env branch Jul 14, 2020
@hroncok
Copy link
Contributor Author

hroncok commented Jul 14, 2020

Weird that the tests passed here, but when I try to package 3.17.0, I get:

==================================== ERRORS ====================================
___________________ ERROR at teardown of test_pre_set_header ___________________
[gw5] linux -- Python 3.9.0 /usr/bin/python3

    @pytest.fixture(autouse=True)
    def check_os_environ_stable():
        old = os.environ.copy()
    
        to_clean = {
            k: os.environ.pop(k, None)
            for k in {
                PARALLEL_ENV_VAR_KEY_PRIVATE,
                PARALLEL_ENV_VAR_KEY_PUBLIC,
                str("TOX_WORK_DIR"),
                str("PYTHONPATH"),
            }
        }
    
        yield
    
        for key, value in to_clean.items():
            if value is not None:
                os.environ[key] = value
    
        new = os.environ
        extra = {k: new[k] for k in set(new) - set(old)}
        miss = {k: old[k] for k in set(old) - set(new)}
        diff = {
            "{} = {} vs {}".format(k, old[k], new[k])
            for k in set(old) & set(new)
            if old[k] != new[k] and not k.startswith("PYTEST_")
        }
        if extra or miss or diff:
            msg = "test changed environ"
            if extra:
                msg += " extra {}".format(extra)
            if miss:
                msg += " miss {}".format(miss)
            if diff:
                msg += " diff {}".format(diff)
>           pytest.fail(msg)
E           Failed: test changed environ miss {'HOSTNAME': ''}

diff       = set()
extra      = {}
key        = 'TOX_PARALLEL_ENV'
miss       = {'HOSTNAME': ''}
msg        = "test changed environ miss {'HOSTNAME': ''}"
new        = environ({'PATH': '/builddir/build/BUILDROOT/python-tox-3.17.0-1.fc33.x86_64/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr...64/python3.9/site-packages:/builddir/build/BUILDROOT/python-tox-3.17.0-1.fc33.x86_64/usr/lib/python3.9/site-packages'})
old        = {'CFLAGS': '-O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,...-fstack-clash-protection -fcf-protection', 'CONFIG_SITE': 'NONE', 'HISTCONTROL': 'ignoredups', 'HISTSIZE': '1000', ...}
to_clean   = {'PYTHONPATH': '/builddir/build/BUILDROOT/python-tox-3.17.0-1.fc33.x86_64/usr/lib64/python3.9/site-packages:/builddir/...c33.x86_64/usr/lib/python3.9/site-packages', 'TOX_PARALLEL_ENV': None, 'TOX_WORK_DIR': None, '_TOX_PARALLEL_ENV': None}
value      = None

../../BUILDROOT/python-tox-3.17.0-1.fc33.x86_64/usr/lib/python3.9/site-packages/tox/_pytestplugin.py:100: Failed
=========================== short test summary info ============================
ERROR tests/unit/test_result.py::test_pre_set_header - Failed: test changed e...
======== 564 passed, 5 skipped, 1 warning, 1 error in 101.90s (0:01:41) ========

@hroncok
Copy link
Contributor Author

hroncok commented Jul 14, 2020

Right, because when the HOSTNAME is '', it doesn't work properly.

hroncok added a commit to hroncok/tox that referenced this pull request Jul 14, 2020
@hroncok
Copy link
Contributor Author

hroncok commented Jul 14, 2020

Followup: #1618

hroncok added a commit to hroncok/tox that referenced this pull request Jul 15, 2020
Use a pytest provided fixture instead of implementing our own.

See tox-dev#1616 (comment)

This is a fixup of cfe66fd.
hroncok added a commit to hroncok/tox that referenced this pull request Jul 15, 2020
Use a pytest provided fixture instead of implementing our own.

See tox-dev#1616 (comment)

This is a fixup of cfe66fd.
asottile pushed a commit that referenced this pull request Jul 15, 2020
Use a pytest provided fixture instead of implementing our own.

See #1616 (comment)

This is a fixup of cfe66fd.
ssbarnea pushed a commit to ssbarnea/tox that referenced this pull request Apr 19, 2021
…sultLog (tox-dev#1616)

This makes it possible to prevent an undesired DNS query.

Fixes tox-dev#1615
ssbarnea pushed a commit to ssbarnea/tox that referenced this pull request Apr 19, 2021
Use a pytest provided fixture instead of implementing our own.

See tox-dev#1616 (comment)

This is a fixup of cfe66fd.
amoralej pushed a commit to rdo-common/pyproject-rpm-macros that referenced this pull request Jun 30, 2022
Tox calls socket.getfqdn() and that call does a DNS query.
In mock with disabled networking, it takes a minute until that times out.
When a spec file uses %pyproject_buildrequires -t and %tox, it is a 3 minute delay.

Since 3.17, tox does not call socket.getfqdn() when HOSTNAME variable is set to a value:

tox-dev/tox#1616

The value is only used in result log, so setting it to "rpmbuild"
actually makes the logs more reproducible as well.

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1856356
when tox is used in %pyproject_buildrequires -t or %tox.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RFE: Use a HOSTNAME environment variable instead of socket.getfqdn() in ResultLog
2 participants