Skip to content

Commit

Permalink
- removed changes on machines
Browse files Browse the repository at this point in the history
- introduced the upgrade strategy on the plan
  • Loading branch information
gabrielcocenza committed Feb 7, 2024
1 parent 57739eb commit e518a04
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
10 changes: 1 addition & 9 deletions cou/apps/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class OpenStackApplication:
packages_to_hold: Optional[list] = field(default=None, init=False)
wait_timeout: int = field(default=DEFAULT_WAITING_TIMEOUT, init=False)
wait_for_model: bool = field(default=False, init=False) # waiting only for application itself
upgrade_by_unit: bool = field(default=False, init=False)

def __post_init__(self) -> None:
"""Initialize the Application dataclass."""
Expand Down Expand Up @@ -420,15 +421,6 @@ def can_upgrade_current_channel(self) -> bool:
"""
return bool(self.status.can_upgrade_to)

@property
def upgrade_by_unit(self) -> bool:
"""Check if application should upgrade by unit, also known as "paused-single-unit" strategy.
:return: whether if application should upgrade by unit or not.
:rtype: bool
"""
return any(machine.is_hypervisor for machine in self.machines)

def new_origin(self, target: OpenStackRelease) -> str:
"""Return the new openstack-origin or source configuration.
Expand Down
7 changes: 1 addition & 6 deletions cou/apps/machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

"""Machine class."""

from dataclasses import dataclass, field
from dataclasses import dataclass
from typing import Optional


Expand All @@ -25,11 +25,6 @@ class Machine:
machine_id: str
hostname: str
az: Optional[str] # simple deployments may not have azs
charms_deployed: set[str] = field(default_factory=set)

@property
def is_hypervisor(self) -> bool:
return "nova-compute" in self.charms_deployed

def __repr__(self) -> str:
"""Representation of the juju Machine.
Expand Down
10 changes: 10 additions & 0 deletions cou/steps/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ async def generate_plan(analysis_result: Analysis, args: CLIargs) -> UpgradePlan
:rtype: UpgradePlan
"""
pre_plan_sanity_checks(args, analysis_result)
set_upgrade_strategy(args, analysis_result)
hypervisors = await filter_hypervisors_machines(args, analysis_result)
logger.info("Hypervisors selected: %s", hypervisors)
target = determine_upgrade_target(analysis_result)
Expand Down Expand Up @@ -428,6 +429,15 @@ async def _get_upgradable_hypervisors_machines(
return await get_empty_hypervisors(nova_compute_units, analysis_result.model)


def set_upgrade_strategy(args: CLIargs, analysis_result: Analysis):
nova_compute_machines = _get_upgradable_hypervisors_machines(True, analysis_result)
for app in analysis_result.data_plane_apps:
if any(unit.machine in nova_compute_machines for unit in app.units):
app.upgrade_by_unit = True
if app.charm == "nova-compute" and args.force:
app.force_upgrade = args.force


async def create_upgrade_group(
apps: list[OpenStackApplication],
target: OpenStackRelease,
Expand Down

0 comments on commit e518a04

Please sign in to comment.