Skip to content

Commit

Permalink
keep ruff only
Browse files Browse the repository at this point in the history
Signed-off-by: Sylvain Hellegouarch <[email protected]>
  • Loading branch information
Lawouach committed Mar 18, 2024
1 parent bf6c7cf commit 81d8e92
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 214 deletions.
2 changes: 1 addition & 1 deletion chaosaddons/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
try:
__version__ = version("chaostoolkit-addons")
except PackageNotFoundError: # pragma: no cover
__version__ = 'unknown'
__version__ = "unknown"
29 changes: 19 additions & 10 deletions chaosaddons/controls/bypass.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,33 @@
from chaoslib.types import Activity


__all__ = ["before_experiment_control", "before_activity_control",
"after_activity_control"]
__all__ = [
"before_experiment_control",
"before_activity_control",
"after_activity_control",
]
logger = logging.getLogger("chaostoolkit")


def before_experiment_control(target_type: str = None,
target_names: List[str] = None, **kwargs):
def before_experiment_control(
target_type: str = None, target_names: List[str] = None, **kwargs
):
if target_type:
logger.warning(
"No '{}' will be executed as configured by the bypass "
"control".format(target_type))
"control".format(target_type)
)
if target_names:
logger.warning(
"The following activities will not be executed: {}".format(
", ".join(target_names)))
", ".join(target_names)
)
)


def before_activity_control(context: Activity, target_type: str = None,
target_names: List[str] = None):
def before_activity_control(
context: Activity, target_type: str = None, target_names: List[str] = None
):
"""
Sets the `dry` property on the activity so it is not actually executed
"""
Expand All @@ -74,8 +82,9 @@ def before_activity_control(context: Activity, target_type: str = None,
context["dry"] = True


def after_activity_control(context: Activity, target_type: str = None,
target_names: List[str] = None):
def after_activity_control(
context: Activity, target_type: str = None, target_names: List[str] = None
):
"""
Removes the `dry` property that was previously set
"""
Expand Down
39 changes: 21 additions & 18 deletions chaosaddons/controls/repeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@
from copy import deepcopy
from typing import List

from chaoslib.types import Activity, Experiment, Run
from chaoslib.types import Activity, Experiment, Run

__all__ = ["after_activity_control"]
logger = logging.getLogger("chaostoolkit")


def after_activity_control(context: Activity, experiment: Experiment,
state: Run, repeat_count: int = 0,
break_if_previous_iteration_failed: bool = False
) -> None:
def after_activity_control(
context: Activity,
experiment: Experiment,
state: Run,
repeat_count: int = 0,
break_if_previous_iteration_failed: bool = False,
) -> None:
"""
Repeat the activity a certain number of times.
Expand Down Expand Up @@ -72,28 +75,28 @@ def after_activity_control(context: Activity, experiment: Experiment,
if break_if_previous_iteration_failed and last_status != "succeeded":
logger.debug(
"Last iteration failed so stopping our iterations "
f"of '{activity_name}'")
f"of '{activity_name}'"
)
return

hypothesis_activities = experiment.get(
"steady-state-hypothesis", {}).get("probes", [])
repeat_activity(
activity, hypothesis_activities, repeat_count=repeat_count)
hypothesis_activities = experiment.get("steady-state-hypothesis", {}).get(
"probes", []
)
repeat_activity(activity, hypothesis_activities, repeat_count=repeat_count)

method_activities = experiment.get("method", [])
repeat_activity(
activity, method_activities, repeat_count=repeat_count)
repeat_activity(activity, method_activities, repeat_count=repeat_count)

rollback_activities = experiment.get("rollbacks", [])
repeat_activity(
activity, rollback_activities, repeat_count=repeat_count)
repeat_activity(activity, rollback_activities, repeat_count=repeat_count)


###############################################################################
# Internals
###############################################################################
def repeat_activity(activity: Activity, activities: List[Activity],
repeat_count: int = 0) -> None:
def repeat_activity(
activity: Activity, activities: List[Activity], repeat_count: int = 0
) -> None:
if not activities:
return

Expand All @@ -102,8 +105,8 @@ def repeat_activity(activity: Activity, activities: List[Activity],

for pos, a in enumerate(copy_activities):
if a["name"] == activity_name:
for index in range(1, repeat_count+1):
for index in range(1, repeat_count + 1):
new_activity = deepcopy(activity)
new_activity["iteration_index"] = index
activities.insert(pos+index, new_activity)
activities.insert(pos + index, new_activity)
break
Loading

0 comments on commit 81d8e92

Please sign in to comment.