pyinfra-dev / pyinfra

pyinfra turns Python code into shell commands and runs them on your servers. Execute ad-hoc commands and write declarative operations. Target SSH servers, local machine and Docker containers. Fast and scales from one server to thousands.
https://pyinfra.com
MIT License
3.85k stars 374 forks source link

Something is broken with host.get_fact in version 2.5.2 #910

Closed julienlavergne closed 1 year ago

julienlavergne commented 1 year ago

Describe the bug

host.get_fact(File, path=remote_file_path, _sudo=True) works in 2.5.1 and raises an exception in 2.5.2:

    user_home_link_fact = host.get_fact(Link, path=user_home_link_path, _sudo=True)
  File "/myhome/.local/lib/python3.9/site-packages/pyinfra/api/host.py", line 250, in get_fact
    return get_host_fact(self.state, self, name_or_cls, args=args, kwargs=kwargs)
  File "/myhome/.local/lib/python3.9/site-packages/pyinfra/api/facts.py", line 339, in get_host_fact
    fact_hash = _get_fact_hash(state, host, cls, args, kwargs)
  File "/myhome/.local/lib/python3.9/site-packages/pyinfra/api/facts.py", line 328, in _get_fact_hash
    kwargs = getcallargs(cls().command, *args, **kwargs)
  File "/opt/tools/python-3.9.4/lib/python3.9/inspect.py", line 1396, in getcallargs
    raise TypeError("%s() got an unexpected keyword argument %r" %
TypeError: command() got an unexpected keyword argument '_sudo'

New code in _get_fact_hash seems to be the culprit.

To Reproduce

I suppose any host.get_fact with _sudo=True.

Meta

--> Support information:

    If you are having issues with pyinfra or wish to make feature requests, please
    check out the GitHub issues at https://github.com/Fizzadar/pyinfra/issues .
    When adding an issue, be sure to include the following:

    System: Linux
      Platform: Linux-3.10.0-1160.76.1.el7.x86_64-x86_64-with-glibc2.17
      Release: 3.10.0-1160.76.1.el7.x86_64
      Machine: x86_64
    pyinfra: v2.5.2
    Executable: /opt/tools/python/bin/pyinfra
    Python: 3.9.4 (CPython, GCC 10.3.0)
Fizzadar commented 1 year ago

Argh, this is bad! Really should be tested... now done in https://github.com/Fizzadar/pyinfra/commit/53dc0e16f907e2217846a790f3d848e53281618b. Actual fix in https://github.com/Fizzadar/pyinfra/commit/0a27fff181199505baf8bbe522fb9ca6c5e03168, will roll 2.5.3 shortly.

Fizzadar commented 1 year ago

Thank you for raising this issue!