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

Add add_steps function to BaseStep #292

Merged
merged 3 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions cou/apps/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,11 +502,9 @@ def generate_upgrade_plan(self, target: OpenStackRelease) -> ApplicationUpgradeP
upgrade_plan = ApplicationUpgradePlan(
description=f"Upgrade plan for '{self.name}' to {target}",
)
upgrade_plan.sub_steps = [
*self.pre_upgrade_steps(target),
*self.upgrade_steps(target),
*self.post_upgrade_steps(target),
]
upgrade_plan.add_steps(self.pre_upgrade_steps(target))
upgrade_plan.add_steps(self.upgrade_steps(target))
upgrade_plan.add_steps(self.post_upgrade_steps(target))

return upgrade_plan

Expand All @@ -522,13 +520,13 @@ def _get_upgrade_current_release_packages_step(self) -> PreUpgradeStep:
),
parallel=True,
)
for unit in self.units:
step.add_step(
UnitUpgradeStep(
description=f"Upgrade software packages on unit {unit.name}",
coro=upgrade_packages(unit.name, self.model, self.packages_to_hold),
)
step.add_steps(
UnitUpgradeStep(
description=f"Upgrade software packages on unit {unit.name}",
coro=upgrade_packages(unit.name, self.model, self.packages_to_hold),
)
for unit in self.units
)

return step

Expand Down
9 changes: 9 additions & 0 deletions cou/steps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,15 @@ def add_step(self, step: BaseStep) -> None:

self._sub_steps.append(step)

def add_steps(self, steps: Iterable[BaseStep]) -> None:
"""Add multiple steps.

:param steps: Sequence of BaseStep to be added as sub steps.
:type steps: Iterable[BaseStep]
"""
for step in steps:
self.add_step(step)

def cancel(self, safe: bool = True) -> None:
"""Cancel step and all its sub steps.

Expand Down
12 changes: 12 additions & 0 deletions tests/unit/steps/test_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,18 @@ def test_step_add_step_failed():
plan.add_step(MagicMock())


def test_step_add_steps():
"""Test BaseStep adding sub steps at once."""
exp_sub_steps = 3
plan = BaseStep(description="plan")
plan.add_steps(
[BaseStep(description=f"sub-step-{i}", coro=mock_coro()) for i in range(exp_sub_steps)]
+ [BaseStep(description="empty-step")] # we also check that empty step will not be added
)

assert len(plan.sub_steps) == exp_sub_steps


def test_step_cancel_safe():
"""Test step safe cancel."""
plan = BaseStep(description="plan")
Expand Down
Loading