Skip to content

Commit

Permalink
Merge branch 'main' into channel-downgrade-BSENG-2350
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielcocenza authored May 1, 2024
2 parents 5f1d6fb + 1d25afc commit a67e73e
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 23 deletions.
23 changes: 18 additions & 5 deletions cou/steps/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,21 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Execution logic."""

import asyncio
import logging
import sys
import time

from cou.exceptions import HaltUpgradeExecution, RunUpgradeError
from cou.steps import ApplicationUpgradePlan, BaseStep, UpgradeStep
from cou.steps import (
ApplicationUpgradePlan,
BaseStep,
HypervisorUpgradePlan,
UpgradeStep,
)
from cou.utils import print_and_debug, progress_indicator, prompt_input

GROUP_STEPS = (ApplicationUpgradePlan, HypervisorUpgradePlan)
AVAILABLE_OPTIONS = ["y", "yes", "n", "no"]

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -107,6 +113,9 @@ async def _run_step(step: BaseStep, prompt: bool, overwrite_progress: bool = Fal
in CLI output. True to overwrite and False (the default) to persist.
:type overwrite_progress: bool
"""
if isinstance(step, GROUP_STEPS):
start_time = time.time()

if isinstance(step, UpgradeStep):
progress_indicator.start(step.description)
await step.run()
Expand All @@ -117,7 +126,7 @@ async def _run_step(step: BaseStep, prompt: bool, overwrite_progress: bool = Fal

# The progress indication message of ApplicationUpgradePlan's sub-steps and all their
# sub-steps will get overwritten upon completion
overwrite_substeps_progress = overwrite_progress or isinstance(step, ApplicationUpgradePlan)
overwrite_substeps_progress = overwrite_progress or isinstance(step, GROUP_STEPS)

if step.parallel:
await _run_sub_steps_in_parallel(step, prompt, overwrite_substeps_progress)
Expand All @@ -126,8 +135,12 @@ async def _run_step(step: BaseStep, prompt: bool, overwrite_progress: bool = Fal

# Upon completion of all sub-steps of ApplicationUpgradePlan, replace the current progress
# indication message, if any, with a persistent application description message.
if isinstance(step, ApplicationUpgradePlan) and progress_indicator.spinner_id is not None:
progress_indicator.succeed(step.description)
if isinstance(step, GROUP_STEPS) and progress_indicator.spinner_id is not None:
end_time = time.time()
execution_time = round(end_time - start_time)
msg = f"{step.description} executed in {execution_time} seconds"
logger.info(msg)
progress_indicator.succeed(msg)


async def apply_step(step: BaseStep, prompt: bool, overwrite_progress: bool = False) -> None:
Expand Down
4 changes: 3 additions & 1 deletion cou/steps/hypervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import logging
from collections import defaultdict
from dataclasses import dataclass
from itertools import chain
from typing import Any

from cou.apps.base import OpenStackApplication
Expand Down Expand Up @@ -290,8 +291,9 @@ def generate_upgrade_plan(self, target: OpenStackRelease, force: bool) -> Upgrad
"""
plan = UpgradePlan("Upgrading all applications deployed on machines with hypervisor.")
for az, group in self.get_azs(target).items():
units = list(chain(*group.app_units.values()))
hypervisor_plan = HypervisorUpgradePlan(
f"Upgrade plan for '{group.name}' to '{target}'"
f"Upgrade plan for {units} in '{group.name}' to '{target}'"
)

# sanity checks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ plan: |
Upgrade plan for 'octavia-diskimage-retrofit' to 'victoria'
Upgrade 'octavia-diskimage-retrofit' from 'ussuri/stable' to the new channel: 'victoria/stable'
Upgrading all applications deployed on machines with hypervisor.
Upgrade plan for 'zone2' to 'victoria'
Upgrade plan for [cinder-volume/0, cinder-volume/2, cinder-volume/3, cinder-volume/9, nova-compute-kvm/0, nova-compute-kvm/2, nova-compute-kvm/3, nova-compute-kvm/9] in 'zone2' to 'victoria'
Upgrade software packages of 'cinder-volume' from the current APT repositories
Ψ Upgrade software packages on unit 'cinder-volume/0'
Ψ Upgrade software packages on unit 'cinder-volume/2'
Expand Down Expand Up @@ -321,7 +321,7 @@ plan: |
Enable nova-compute scheduler from unit: 'nova-compute-kvm/9'
Wait for up to 2400s for model '018346c5-f95c-46df-a34e-9a78bdec0018' to reach the idle state
Verify that the workload of 'nova-compute-kvm' has been upgraded on units: nova-compute-kvm/0, nova-compute-kvm/2, nova-compute-kvm/3, nova-compute-kvm/9
Upgrade plan for 'zone3' to 'victoria'
Upgrade plan for [cinder-volume/1, cinder-volume/10, cinder-volume/11, cinder-volume/5, nova-compute-kvm/1, nova-compute-kvm/10, nova-compute-kvm/11, nova-compute-kvm/5] in 'zone3' to 'victoria'
Upgrade software packages of 'cinder-volume' from the current APT repositories
Ψ Upgrade software packages on unit 'cinder-volume/1'
Ψ Upgrade software packages on unit 'cinder-volume/10'
Expand Down Expand Up @@ -388,7 +388,7 @@ plan: |
Enable nova-compute scheduler from unit: 'nova-compute-kvm/5'
Wait for up to 2400s for model '018346c5-f95c-46df-a34e-9a78bdec0018' to reach the idle state
Verify that the workload of 'nova-compute-kvm' has been upgraded on units: nova-compute-kvm/1, nova-compute-kvm/10, nova-compute-kvm/11, nova-compute-kvm/5
Upgrade plan for 'zone1' to 'victoria'
Upgrade plan for [cinder-volume/4, cinder-volume/6, cinder-volume/7, cinder-volume/8, nova-compute-kvm/4, nova-compute-kvm/6, nova-compute-kvm/7, nova-compute-kvm/8] in 'zone1' to 'victoria'
Upgrade software packages of 'cinder-volume' from the current APT repositories
Ψ Upgrade software packages on unit 'cinder-volume/4'
Ψ Upgrade software packages on unit 'cinder-volume/6'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ plan: |
Upgrade plan for 'octavia-ovn-chassis' to 'victoria'
WARNING: Changing 'octavia-ovn-chassis' channel from latest/stable to 22.03/stable. This may be a charm downgrade, which is generally not supported.
Upgrading all applications deployed on machines with hypervisor.
Upgrade plan for 'az1' to 'victoria'
Upgrade plan for [nova-compute/0, nova-compute/2, nova-compute/3] in 'az1' to 'victoria'
Disable nova-compute scheduler from unit: 'nova-compute/0'
Disable nova-compute scheduler from unit: 'nova-compute/2'
Disable nova-compute scheduler from unit: 'nova-compute/3'
Expand Down Expand Up @@ -343,7 +343,7 @@ plan: |
Enable nova-compute scheduler from unit: 'nova-compute/3'
Wait for up to 2400s for model '9eb9af6a-b919-4cf9-8f2f-9df16a1556be' to reach the idle state
Verify that the workload of 'nova-compute' has been upgraded on units: nova-compute/0, nova-compute/2, nova-compute/3
Upgrade plan for 'az3' to 'victoria'
Upgrade plan for [nova-compute/1, nova-compute/6, nova-compute/8] in 'az3' to 'victoria'
Disable nova-compute scheduler from unit: 'nova-compute/1'
Disable nova-compute scheduler from unit: 'nova-compute/6'
Disable nova-compute scheduler from unit: 'nova-compute/8'
Expand Down Expand Up @@ -375,7 +375,7 @@ plan: |
Enable nova-compute scheduler from unit: 'nova-compute/8'
Wait for up to 2400s for model '9eb9af6a-b919-4cf9-8f2f-9df16a1556be' to reach the idle state
Verify that the workload of 'nova-compute' has been upgraded on units: nova-compute/1, nova-compute/6, nova-compute/8
Upgrade plan for 'az2' to 'victoria'
Upgrade plan for [nova-compute/4, nova-compute/5, nova-compute/7] in 'az2' to 'victoria'
Disable nova-compute scheduler from unit: 'nova-compute/4'
Disable nova-compute scheduler from unit: 'nova-compute/5'
Disable nova-compute scheduler from unit: 'nova-compute/7'
Expand Down
2 changes: 1 addition & 1 deletion tests/mocked_plans/sample_plans/base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ plan: |
Refresh 'keystone-ldap' to the latest revision of 'ussuri/stable'
Upgrade 'keystone-ldap' from 'ussuri/stable' to the new channel: 'victoria/stable'
Upgrading all applications deployed on machines with hypervisor.
Upgrade plan for 'az-0' to 'victoria'
Upgrade plan for [nova-compute/0] in 'az-0' to 'victoria'
Disable nova-compute scheduler from unit: 'nova-compute/0'
Upgrade software packages of 'nova-compute' from the current APT repositories
Ψ Upgrade software packages on unit 'nova-compute/0'
Expand Down
5 changes: 4 additions & 1 deletion tests/unit/steps/test_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,16 @@ async def test_run_step_sequentially_application_upgrade_plan(
upgrade_step = MagicMock(spec_set=ApplicationUpgradePlan("test-app upgrade plan"))
upgrade_step.run = AsyncMock()
upgrade_step.parallel = False
upgrade_step.description = "Upgrade plan for 'app' to 'victoria'"

await _run_step(upgrade_step, False)

mock_indicator.start.assert_not_called()
upgrade_step.run.assert_awaited_once_with()
mock_run_sub_steps_sequentially.assert_awaited_once_with(upgrade_step, False, True)
mock_indicator.succeed.assert_called_once_with(upgrade_step.description)
mock_indicator.succeed.assert_called_once_with(
"Upgrade plan for 'app' to 'victoria' executed in 0 seconds"
)


@pytest.mark.asyncio
Expand Down
14 changes: 7 additions & 7 deletions tests/unit/steps/test_hypervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def test_generate_upgrade_plan(
assert plan.description == "Upgrading all applications deployed on machines with hypervisor."
assert len(plan.sub_steps) == 2
assert isinstance(plan.sub_steps[0], HypervisorUpgradePlan)
assert plan.sub_steps[0].description == f"Upgrade plan for '{group1.name}' to '{target}'"
assert plan.sub_steps[0].description == f"Upgrade plan for [] in '{group1.name}' to '{target}'"
assert (
plan.sub_steps[0].sub_steps
== pre_upgrade_steps.return_value
Expand Down Expand Up @@ -392,7 +392,7 @@ def test_hypervisor_upgrade_plan(model):
exp_plan = dedent_plan(
"""\
Upgrading all applications deployed on machines with hypervisor.
Upgrade plan for 'az-0' to 'victoria'
Upgrade plan for [cinder/0, nova-compute/0] in 'az-0' to 'victoria'
Upgrade software packages of 'cinder' from the current APT repositories
Ψ Upgrade software packages on unit 'cinder/0'
Refresh 'cinder' to the latest revision of 'ussuri/stable'
Expand Down Expand Up @@ -422,7 +422,7 @@ def test_hypervisor_upgrade_plan(model):
Enable nova-compute scheduler from unit: 'nova-compute/0'
Wait for up to 2400s for model 'test_model' to reach the idle state
Verify that the workload of 'nova-compute' has been upgraded on units: nova-compute/0
Upgrade plan for 'az-1' to 'victoria'
Upgrade plan for [nova-compute/1] in 'az-1' to 'victoria'
Disable nova-compute scheduler from unit: 'nova-compute/1'
Upgrade software packages of 'nova-compute' from the current APT repositories
Ψ Upgrade software packages on unit 'nova-compute/1'
Expand All @@ -439,7 +439,7 @@ def test_hypervisor_upgrade_plan(model):
Enable nova-compute scheduler from unit: 'nova-compute/1'
Wait for up to 2400s for model 'test_model' to reach the idle state
Verify that the workload of 'nova-compute' has been upgraded on units: nova-compute/1
Upgrade plan for 'az-2' to 'victoria'
Upgrade plan for [nova-compute/2] in 'az-2' to 'victoria'
Disable nova-compute scheduler from unit: 'nova-compute/2'
Upgrade software packages of 'nova-compute' from the current APT repositories
Ψ Upgrade software packages on unit 'nova-compute/2'
Expand Down Expand Up @@ -519,7 +519,7 @@ def test_hypervisor_upgrade_plan_single_machine(model):
exp_plan = dedent_plan(
"""\
Upgrading all applications deployed on machines with hypervisor.
Upgrade plan for 'az-0' to 'victoria'
Upgrade plan for [cinder/0, nova-compute/0] in 'az-0' to 'victoria'
Upgrade software packages of 'cinder' from the current APT repositories
Ψ Upgrade software packages on unit 'cinder/0'
Refresh 'cinder' to the latest revision of 'ussuri/stable'
Expand Down Expand Up @@ -609,7 +609,7 @@ def test_hypervisor_upgrade_plan_some_units_upgraded(model):
exp_plan = dedent_plan(
"""\
Upgrading all applications deployed on machines with hypervisor.
Upgrade plan for 'az-1' to 'victoria'
Upgrade plan for [cinder/1] in 'az-1' to 'victoria'
Upgrade software packages of 'cinder' from the current APT repositories
Ψ Upgrade software packages on unit 'cinder/1'
Upgrade plan for units: cinder/1
Expand All @@ -619,7 +619,7 @@ def test_hypervisor_upgrade_plan_some_units_upgraded(model):
Resume the unit: 'cinder/1'
Wait for up to 300s for app 'cinder' to reach the idle state
Verify that the workload of 'cinder' has been upgraded on units: cinder/1
Upgrade plan for 'az-2' to 'victoria'
Upgrade plan for [cinder/2, nova-compute/2] in 'az-2' to 'victoria'
Upgrade software packages of 'cinder' from the current APT repositories
Ψ Upgrade software packages on unit 'cinder/2'
Disable nova-compute scheduler from unit: 'nova-compute/2'
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/steps/test_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ async def test_generate_plan(mock_filter_hypervisors, model, cli_args):
Refresh 'keystone-ldap' to the latest revision of 'ussuri/stable'
Upgrade 'keystone-ldap' from 'ussuri/stable' to the new channel: 'victoria/stable'
Upgrading all applications deployed on machines with hypervisor.
Upgrade plan for 'az-1' to 'victoria'
Upgrade plan for [nova-compute/0] in 'az-1' to 'victoria'
Disable nova-compute scheduler from unit: 'nova-compute/0'
Upgrade software packages of 'nova-compute' from the current APT repositories
Ψ Upgrade software packages on unit 'nova-compute/0'
Expand Down Expand Up @@ -320,7 +320,7 @@ async def test_generate_plan_with_warning_messages(mock_filter_hypervisors, mode
Refresh 'keystone-ldap' to the latest revision of 'ussuri/stable'
Upgrade 'keystone-ldap' from 'ussuri/stable' to the new channel: 'victoria/stable'
Upgrading all applications deployed on machines with hypervisor.
Upgrade plan for 'az-1' to 'victoria'
Upgrade plan for [nova-compute/0] in 'az-1' to 'victoria'
Disable nova-compute scheduler from unit: 'nova-compute/0'
Upgrade software packages of 'nova-compute' from the current APT repositories
Ψ Upgrade software packages on unit 'nova-compute/0'
Expand Down

0 comments on commit a67e73e

Please sign in to comment.