Skip to content

Commit

Permalink
pre-pr changes
Browse files Browse the repository at this point in the history
  • Loading branch information
stone-w4tch3r committed Apr 5, 2024
1 parent ba476ed commit fb187f4
Show file tree
Hide file tree
Showing 9 changed files with 6 additions and 32 deletions.
16 changes: 2 additions & 14 deletions pyinfra/api/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,25 +223,13 @@ def execute(self, state: "State", host: "Host", connector_arguments: ConnectorAr
if "state" in argspec.args and "host" in argspec.args:
return self.function(state, host, *self.args, **self.kwargs)

# Note: we use try/except here to catch any exception inside the greenlet
# and bubble that back out as a return value before re-raising outside.
# This is because gevent dumps stack traces when raised within a greenlet
# and we want to handle that ourselves.
def execute_function():
with ctx_config.use(state.config.copy()):
with ctx_host.use(host):
try:
self.function(*self.args, **self.kwargs)
except Exception as e:
return e
else:
return True
self.function(*self.args, **self.kwargs)

greenlet = gevent.spawn(execute_function)
res = greenlet.get()
if isinstance(res, Exception):
raise res
return res
return greenlet.get()


class RsyncCommand(PyinfraCommand):
Expand Down
6 changes: 0 additions & 6 deletions pyinfra/api/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ class PyinfraError(Exception):
"""


class NoMoreHostsError(PyinfraError):
"""
Exception raised when pyinfra runs out of hosts (they all failed).
"""


class ConnectError(PyinfraError):
"""
Exception raised when connecting fails.
Expand Down
4 changes: 1 addition & 3 deletions pyinfra/api/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,7 @@ def execute_immediately(state, host, op_hash):
op_data = state.get_op_data_for_host(host, op_hash)
op_data.parent_op_hash = host.executing_op_hash
log_operation_start(op_meta, op_types=["nested"], prefix="")
status = run_host_op(state, host, op_hash)
if status is False:
state.fail_hosts({host})
run_host_op(state, host, op_hash)


def _get_arg_value(arg):
Expand Down
2 changes: 1 addition & 1 deletion pyinfra/operations/dnf.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def rpm(src: str, present=True):
)
"""

yield from ensure_rpm(state, host, src, present, "dnf")
yield from ensure_rpm(host, src, present, "dnf")


@operation(is_idempotent=False)
Expand Down
2 changes: 0 additions & 2 deletions pyinfra/operations/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ def user(
mysql_host: str = None,
mysql_port: int = None,
):
...
"""
Add/remove/update MySQL users.
Expand Down Expand Up @@ -297,7 +296,6 @@ def database(
mysql_host: str = None,
mysql_port: int = None,
):
...
"""
Add/remove MySQL databases.
Expand Down
3 changes: 0 additions & 3 deletions pyinfra/operations/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
The Python module allows you to execute Python code within the context of a deploy.
"""

from inspect import getfullargspec
from typing import Callable

from pyinfra import logger
from pyinfra.api import FunctionCommand, operation


Expand Down
1 change: 0 additions & 1 deletion pyinfra/operations/util/packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ def ensure_packages(


def ensure_rpm(
state: State,
host: Host,
source: str,
present: bool,
Expand Down
2 changes: 1 addition & 1 deletion pyinfra/operations/yum.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def rpm(src: str, present=True):
)
"""

yield from ensure_rpm(state, host, src, present, "yum")
yield from ensure_rpm(host, src, present, "yum")


@operation(is_idempotent=False)
Expand Down
2 changes: 1 addition & 1 deletion pyinfra/operations/zypper.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def rpm(src, present=True):
)
"""

yield from ensure_rpm(state, host, src, present, "zypper --non-interactive")
yield from ensure_rpm(host, src, present, "zypper --non-interactive")


@operation(is_idempotent=False)
Expand Down

0 comments on commit fb187f4

Please sign in to comment.