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

--fail-percent not working when using server.shell #1195

Open
avrilmaomao opened this issue Sep 4, 2024 · 0 comments
Open

--fail-percent not working when using server.shell #1195

avrilmaomao opened this issue Sep 4, 2024 · 0 comments

Comments

@avrilmaomao
Copy link

Describe the bug

In the pyinfra cli, I added the parameters " --serial" and "--fail-percent 0" to let the deploy run one host at a time , and if one host encountered error, the deploy process would stop.
When I use "exec" to execute adhoc command, the --fail-percent worked as expected.But when I switch to a .py file which using "server.shell" to execute the same command, the deploy was still executed on all hosts even the first host had failed.

To Reproduce

  • Operation code & usage
  1. write a simple deploy file(eg. test_fail_percent.py), using server.shell to execute a command that does not exist.
import pyinfra.operations.server as server

server.shell('uptim')
  1. run pyinfra with the above file with multiple hosts
    pyinfra -y --serial --fail-percent 0 --debug host1,host2 test_fail_percent.py
  • Target system information
    ubuntu 22.04

Expected behavior

The deploy should be stopped for other hosts when the first host encountered error during the "server.shell" execution

Meta

  • Include output of pyinfra --support.
    System: Linux
    Platform: Linux-5.15.0-101-generic-x86_64-with-glibc2.35
    Release: 5.15.0-101-generic
    Machine: x86_64
    pyinfra: v3.1
    click: v8.1.7
    configparser: v7.0.0
    distro: v1.9.0
    gevent: v24.2.1
    jinja2: v3.1.3
    packaging: v24.1
    paramiko: v3.4.0
    python-dateutil: v2.9.0.post0
    pywinrm: v0.4.3
    setuptools: v74.1.1
    typeguard: v4.3.0
    typing-extensions: v4.12.2
    wheel: v0.44.0
    Executable: /usr/sbin/pyinfra
    Python: 3.10.12 (CPython, GCC 11.4.0)
  • How was pyinfra installed (source/pip)?
    pip
  • Consider including output with -vv and --debug.

-> Loading config...
--> Loading inventory...
[pyinfra_cli.inventory] Creating fake inventory...
[pyinfra_cli.inventory] Checking possible group_data at: /var/lib/jenkins/group_data

--> Connecting to hosts...
[pyinfra.connectors.ssh] Connecting to: host1 ({'allow_agent': True, 'look_for_keys': True, '_pyinfra_ssh_forward_agent': False, '_pyinfra_ssh_config_file': None, '_pyinfra_ssh_known_hosts_file': None, '_pyinfra_ssh_strict_host_key_checking': 'accept-new', '_pyinfra_ssh_paramiko_connect_kwargs': None, 'timeout': 10})
[pyinfra.connectors.sshuserclient.client] Loading SSH config: None
[pyinfra.connectors.ssh] Connecting to: host2 ({'allow_agent': True, 'look_for_keys': True, '_pyinfra_ssh_forward_agent': False, '_pyinfra_ssh_config_file': None, '_pyinfra_ssh_known_hosts_file': None, '_pyinfra_ssh_strict_host_key_checking': 'accept-new', '_pyinfra_ssh_paramiko_connect_kwargs': None, 'timeout': 10})
[host1] Connected
[host2] Connected
[pyinfra.api.state] Activating host: host1
[pyinfra.api.state] Activating host: host2

--> Preparing operations...
--> Preparing Operations...
Loading: test_op.py
[pyinfra.api.operation] Adding operation, {'server.shell'}, opOrder=(0, 3), opHash=cedda09f9ebcba03bb3a36b21a0111fc8b7c3ec0
[host2] Ready: test_op.py
[pyinfra.api.operation] Adding operation, {'server.shell'}, opOrder=(0, 3), opHash=cedda09f9ebcba03bb3a36b21a0111fc8b7c3ec0
[host1] Ready: test_op.py

--> Skipping change detection
--> Beginning operation run...
[pyinfra.api.operations] Running all ops on host2

--> Starting operation: server.shell (uptim)
[pyinfra.api.operations] Starting operation {'server.shell'} on host2
[pyinfra.connectors.ssh] Running command on host2: (pty=False) sh -c uptim
[pyinfra.connectors.ssh] Waiting for exit status...
[pyinfra.connectors.ssh] Command exit status: 127
[host2] sh: 1: uptim: not found
[host2] Error: executed 0 commands
[pyinfra.api.state] Failing hosts: host2
[pyinfra.api.operations] Running all ops on host1

--> Starting operation: server.shell (uptim)
[pyinfra.api.operations] Starting operation {'server.shell'} on host1
[pyinfra.connectors.ssh] Running command on host1: (pty=False) sh -c uptim
[pyinfra.connectors.ssh] Waiting for exit status...
[pyinfra.connectors.ssh] Command exit status: 127
[host1] sh: 1: uptim: not found
[host1] Error: executed 0 commands
[pyinfra.api.state] Failing hosts: host1

@avrilmaomao avrilmaomao changed the title --fail-percent not working when using server.shell or server.script --fail-percent not working when using server.shell Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant