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

feat: Restart ceilometer-agent-compute after nova-compute upgrade #435

7 changes: 7 additions & 0 deletions cou/apps/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ def __str__(self) -> str:
"machine": unit.machine.machine_id,
"workload_version": unit.workload_version,
"o7k_version": str(self.get_latest_o7k_version(unit)),
"subordinates": {
subordinate.name: {
"name": subordinate.name,
"charm": subordinate.charm,
}
for subordinate in unit.subordinates
},
}
for unit in self.units.values()
},
Expand Down
39 changes: 38 additions & 1 deletion cou/apps/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,44 @@ def post_upgrade_steps(
:return: List of post upgrade steps.
:rtype: list[PostUpgradeStep]
"""
return self._get_enable_scheduler_step(units) + super().post_upgrade_steps(target, units)
return (
self._get_enable_scheduler_step(units)
+ self._get_restart_subordinate_services_steps(units)
+ super().post_upgrade_steps(target, units)
)

def _get_restart_subordinate_services_steps(
jneo8 marked this conversation as resolved.
Show resolved Hide resolved
self, units: Optional[list[Unit]]
) -> list[PostUpgradeStep]:
"""Get step to restart all subordinate services if they aren't running.

:param units: Units to restart subordinate services.
:type units: Optional[list[Unit]]
:return: Steps to restart to subordinate services
:rtype: list[PostUpgradeStep]
"""
if not units:
units = list(self.units.values())
steps = []
for unit in units:
for subordinate in unit.subordinates:
if "ceilometer-agent" == subordinate.charm:
service = "ceilometer-agent-compute"
steps.append(
PostUpgradeStep(
description=(
f"Restart subordinate service for unit: '{subordinate.name}'"
),
coro=self.model.run_on_unit(
unit_name=subordinate.name,
command=(
f"systemctl is-active --quiet {service}"
f" || systemctl restart {service}"
),
),
rgildein marked this conversation as resolved.
Show resolved Hide resolved
)
)
return steps

def _get_unit_upgrade_steps(self, unit: Unit, force: bool) -> UnitUpgradeStep:
"""Get the upgrade steps for a single unit.
Expand Down
33 changes: 30 additions & 3 deletions cou/utils/juju_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import asyncio
import logging
import os
from dataclasses import dataclass
from dataclasses import dataclass, field
from datetime import datetime
from typing import Any, Callable, Optional
from typing import Any, Callable, List, Optional

from juju.action import Action
from juju.application import Application as JujuApplication
Expand Down Expand Up @@ -142,13 +142,30 @@ class Machine:
az: Optional[str] = None # simple deployments may not have azs


@dataclass(frozen=True)
class SubordinateUnit:
"""Representation of a single unit of subordinate unit."""

name: str
charm: str

def __repr__(self) -> str:
"""App representation.

:return: Name of the application
:rtype: str
"""
return self.name


@dataclass(frozen=True)
class Unit:
"""Representation of a single unit of application."""

name: str
machine: Machine
workload_version: str
subordinates: List[SubordinateUnit] = field(default_factory=lambda: [], compare=False)

def __repr__(self) -> str:
"""App representation.
Expand Down Expand Up @@ -383,7 +400,17 @@ async def get_applications(self) -> dict[str, Application]:
series=status.series,
subordinate_to=status.subordinate_to,
units={
name: Unit(name, machines[unit.machine], unit.workload_version)
name: Unit(
name,
machines[unit.machine],
unit.workload_version,
[
SubordinateUnit(
subordinate, model.applications[subordinate.split("/")[0]]
)
for subordinate, subordinate_unit in unit.subordinates.items()
],
)
for name, unit in status.units.items()
},
workload_version=status.workload_version,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,10 @@ plan: |
Enable nova-compute scheduler from unit: 'nova-compute-kvm/2'
Enable nova-compute scheduler from unit: 'nova-compute-kvm/3'
Enable nova-compute scheduler from unit: 'nova-compute-kvm/9'
Restart subordinate service for unit: 'ceilometer-agent/0'
Restart subordinate service for unit: 'ceilometer-agent/2'
Restart subordinate service for unit: 'ceilometer-agent/3'
Restart subordinate service for unit: 'ceilometer-agent/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 [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'
Expand Down Expand Up @@ -386,6 +390,10 @@ plan: |
Enable nova-compute scheduler from unit: 'nova-compute-kvm/10'
Enable nova-compute scheduler from unit: 'nova-compute-kvm/11'
Enable nova-compute scheduler from unit: 'nova-compute-kvm/5'
Restart subordinate service for unit: 'ceilometer-agent/1'
Restart subordinate service for unit: 'ceilometer-agent/10'
Restart subordinate service for unit: 'ceilometer-agent/11'
Restart subordinate service for unit: 'ceilometer-agent/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 [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'
Expand Down Expand Up @@ -453,6 +461,10 @@ plan: |
Enable nova-compute scheduler from unit: 'nova-compute-kvm/6'
Enable nova-compute scheduler from unit: 'nova-compute-kvm/7'
Enable nova-compute scheduler from unit: 'nova-compute-kvm/8'
Restart subordinate service for unit: 'ceilometer-agent/4'
Restart subordinate service for unit: 'ceilometer-agent/6'
Restart subordinate service for unit: 'ceilometer-agent/7'
Restart subordinate service for unit: 'ceilometer-agent/8'
chanchiwai-ray marked this conversation as resolved.
Show resolved Hide resolved
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/4, nova-compute-kvm/6, nova-compute-kvm/7, nova-compute-kvm/8
Remaining Data Plane principal(s) upgrade plan
Expand Down Expand Up @@ -6738,61 +6750,108 @@ applications:
machine: '21'
workload_version: 21.2.4
o7k_version: ussuri
subordinates:
ceilometer-agent/0:
name: ceilometer-agent/0
charm: ceilometer-agent
nova-compute-kvm/1:
name: nova-compute-kvm/1
machine: '22'
workload_version: 21.2.4
o7k_version: ussuri
jneo8 marked this conversation as resolved.
Show resolved Hide resolved
subordinates:
ceilometer-agent/1:
name: ceilometer-agent/1
charm: ceilometer-agent
nova-compute-kvm/10:
name: nova-compute-kvm/10
machine: '31'
workload_version: 21.2.4
o7k_version: ussuri
subordinates:
ceilometer-agent/10:
name: ceilometer-agent/10
charm: ceilometer-agent
nova-compute-kvm/11:
name: nova-compute-kvm/11
machine: '32'
workload_version: 21.2.4
o7k_version: ussuri
subordinates:
ceilometer-agent/11:
name: ceilometer-agent/11
charm: ceilometer-agent
nova-compute-kvm/2:
name: nova-compute-kvm/2
machine: '23'
workload_version: 21.2.4
o7k_version: ussuri
subordinates:
ceilometer-agent/2:
name: ceilometer-agent/2
charm: ceilometer-agent
nova-compute-kvm/3:
name: nova-compute-kvm/3
machine: '24'
workload_version: 21.2.4
o7k_version: ussuri
subordinates:
ceilometer-agent/3:
name: ceilometer-agent/3
charm: ceilometer-agent
nova-compute-kvm/4:
name: nova-compute-kvm/4
machine: '25'
workload_version: 21.2.4
o7k_version: ussuri
subordinates:
ceilometer-agent/4:
name: ceilometer-agent/4
charm: ceilometer-agent
nova-compute-kvm/5:
name: nova-compute-kvm/5
machine: '26'
workload_version: 21.2.4
o7k_version: ussuri
subordinates:
ceilometer-agent/5:
name: ceilometer-agent/5
charm: ceilometer-agent
nova-compute-kvm/6:
name: nova-compute-kvm/6
machine: '27'
workload_version: 21.2.4
o7k_version: ussuri
subordinates:
ceilometer-agent/6:
name: ceilometer-agent/6
charm: ceilometer-agent
nova-compute-kvm/7:
name: nova-compute-kvm/7
machine: '28'
workload_version: 21.2.4
o7k_version: ussuri
subordinates:
ceilometer-agent/7:
name: ceilometer-agent/7
charm: ceilometer-agent
nova-compute-kvm/8:
name: nova-compute-kvm/8
machine: '29'
workload_version: 21.2.4
o7k_version: ussuri
subordinates:
ceilometer-agent/8:
name: ceilometer-agent/8
charm: ceilometer-agent
nova-compute-kvm/9:
name: nova-compute-kvm/9
machine: '30'
workload_version: 21.2.4
o7k_version: ussuri
subordinates:
ceilometer-agent/9:
name: ceilometer-agent/9
charm: ceilometer-agent
machines:
'21':
id: '21'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,9 @@ plan: |
Enable nova-compute scheduler from unit: 'nova-compute/0'
Enable nova-compute scheduler from unit: 'nova-compute/2'
Enable nova-compute scheduler from unit: 'nova-compute/3'
Restart subordinate service for unit: 'ceilometer-agent/0'
Restart subordinate service for unit: 'ceilometer-agent/2'
Restart subordinate service for unit: 'ceilometer-agent/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 [nova-compute/1, nova-compute/6, nova-compute/8] in 'az3' to 'victoria'
Expand Down Expand Up @@ -373,6 +376,9 @@ plan: |
Enable nova-compute scheduler from unit: 'nova-compute/1'
Enable nova-compute scheduler from unit: 'nova-compute/6'
Enable nova-compute scheduler from unit: 'nova-compute/8'
Restart subordinate service for unit: 'ceilometer-agent/1'
Restart subordinate service for unit: 'ceilometer-agent/6'
Restart subordinate service for unit: 'ceilometer-agent/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 [nova-compute/4, nova-compute/5, nova-compute/7] in 'az2' to 'victoria'
Expand Down Expand Up @@ -405,6 +411,9 @@ plan: |
Enable nova-compute scheduler from unit: 'nova-compute/4'
Enable nova-compute scheduler from unit: 'nova-compute/5'
Enable nova-compute scheduler from unit: 'nova-compute/7'
Restart subordinate service for unit: 'ceilometer-agent/4'
Restart subordinate service for unit: 'ceilometer-agent/5'
Restart subordinate service for unit: 'ceilometer-agent/7'
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/4, nova-compute/5, nova-compute/7
Remaining Data Plane principal(s) upgrade plan
Expand Down Expand Up @@ -5304,46 +5313,82 @@ applications:
machine: '0'
workload_version: 21.2.4
o7k_version: ussuri
subordinates:
ceilometer-agent/0:
name: ceilometer-agent/0
charm: ceilometer-agent
nova-compute/1:
name: nova-compute/1
machine: '1'
workload_version: 21.2.4
o7k_version: ussuri
subordinates:
ceilometer-agent/1:
name: ceilometer-agent/1
charm: ceilometer-agent
nova-compute/2:
name: nova-compute/2
machine: '2'
workload_version: 21.2.4
o7k_version: ussuri
subordinates:
ceilometer-agent/2:
name: ceilometer-agent/2
charm: ceilometer-agent
nova-compute/3:
name: nova-compute/3
machine: '3'
workload_version: 21.2.4
o7k_version: ussuri
subordinates:
ceilometer-agent/3:
name: ceilometer-agent/3
charm: ceilometer-agent
nova-compute/4:
name: nova-compute/4
machine: '4'
workload_version: 21.2.4
o7k_version: ussuri
subordinates:
ceilometer-agent/4:
name: ceilometer-agent/4
charm: ceilometer-agent
nova-compute/5:
name: nova-compute/5
machine: '5'
workload_version: 21.2.4
o7k_version: ussuri
subordinates:
ceilometer-agent/5:
name: ceilometer-agent/5
charm: ceilometer-agent
nova-compute/6:
name: nova-compute/6
machine: '6'
workload_version: 21.2.4
o7k_version: ussuri
subordinates:
ceilometer-agent/6:
name: ceilometer-agent/6
charm: ceilometer-agent
nova-compute/7:
name: nova-compute/7
machine: '7'
workload_version: 21.2.4
o7k_version: ussuri
subordinates:
ceilometer-agent/7:
name: ceilometer-agent/7
charm: ceilometer-agent
nova-compute/8:
name: nova-compute/8
machine: '8'
workload_version: 21.2.4
o7k_version: ussuri
subordinates:
ceilometer-agent/8:
name: ceilometer-agent/8
charm: ceilometer-agent
machines:
'5':
id: '5'
Expand Down
5 changes: 5 additions & 0 deletions tests/mocked_plans/sample_plans/base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ plan: |
├── Upgrade the unit: 'nova-compute/0'
├── Resume the unit: 'nova-compute/0'
Enable nova-compute scheduler from unit: 'nova-compute/0'
Restart subordinate service for unit: 'ceilometer-agent/0'
Wait for up to 2400s for model 'base' to reach the idle state
Verify that the workload of 'nova-compute' has been upgraded on units: nova-compute/0
Remaining Data Plane principal(s) upgrade plan
Expand Down Expand Up @@ -132,6 +133,10 @@ applications:
machine: '1'
workload_version: 21.0.0
o7k_version: ussuri
subordinates:
ceilometer-agent/0:
name: ceilometer-agent/0
charm: ceilometer-agent
machines:
'1':
id: '1'
Expand Down
Loading