From 776cd7117db73d6b02af2aacd86cfd11e701a1b6 Mon Sep 17 00:00:00 2001 From: Gabriel Cocenza Date: Tue, 16 Apr 2024 09:42:18 -0300 Subject: [PATCH] - removed unecessary SubordinateBase class - added based_on_channel class argument --- cou/apps/auxiliary_subordinate.py | 18 +++------------- cou/apps/base.py | 3 +++ cou/apps/channel_based.py | 3 +++ cou/apps/subordinate.py | 35 +++++++++++++++---------------- cou/steps/analyze.py | 7 +------ cou/steps/plan.py | 2 +- 6 files changed, 28 insertions(+), 40 deletions(-) diff --git a/cou/apps/auxiliary_subordinate.py b/cou/apps/auxiliary_subordinate.py index d5821500..4d7bf21a 100644 --- a/cou/apps/auxiliary_subordinate.py +++ b/cou/apps/auxiliary_subordinate.py @@ -14,26 +14,14 @@ """Auxiliary subordinate application class.""" from cou.apps.auxiliary import OVN, AuxiliaryApplication from cou.apps.factory import AppFactory -from cou.apps.subordinate import SubordinateBase -from cou.utils.openstack import AUXILIARY_SUBORDINATES, OpenStackRelease +from cou.apps.subordinate import SubordinateApplication +from cou.utils.openstack import AUXILIARY_SUBORDINATES @AppFactory.register_application(AUXILIARY_SUBORDINATES) -class AuxiliarySubordinateApplication(SubordinateBase, AuxiliaryApplication): +class AuxiliarySubordinateApplication(SubordinateApplication, AuxiliaryApplication): """Auxiliary subordinate application class.""" - @property - def current_os_release(self) -> OpenStackRelease: - """Infer the OpenStack release from subordinate charm's channel. - - We cannot determine the OpenStack release base on workload packages because the principal - charm has already upgraded the packages. - - :return: OpenStackRelease object. - :rtype: OpenStackRelease - """ - return self.channel_codename - @AppFactory.register_application(["ovn-chassis"]) class OVNSubordinate(OVN, AuxiliarySubordinateApplication): diff --git a/cou/apps/base.py b/cou/apps/base.py index 803a6681..59b4296e 100644 --- a/cou/apps/base.py +++ b/cou/apps/base.py @@ -67,6 +67,9 @@ class OpenStackApplication(Application): packages_to_hold: Optional[list] = field(default=None, init=False) wait_timeout: int = field(default=STANDARD_IDLE_TIMEOUT, init=False) wait_for_model: bool = field(default=False, init=False) # waiting only for application itself + # OpenStack apps rely on the workload version of the packages to evaluate current OpenStack + # release + based_on_channel = False def __hash__(self) -> int: """Hash magic method for Application. diff --git a/cou/apps/channel_based.py b/cou/apps/channel_based.py index 16589d8a..7a4482df 100644 --- a/cou/apps/channel_based.py +++ b/cou/apps/channel_based.py @@ -28,6 +28,9 @@ class ChannelBasedApplication(OpenStackApplication): """Application for charms that are channel based.""" + # rely on the channel to evaluate current OpenStack release + based_on_channel = True + def get_latest_os_version(self, unit: Unit) -> OpenStackRelease: """Get the latest compatible OpenStack release based on the channel. diff --git a/cou/apps/subordinate.py b/cou/apps/subordinate.py index e9c1d92f..da6420a1 100644 --- a/cou/apps/subordinate.py +++ b/cou/apps/subordinate.py @@ -25,9 +25,25 @@ logger = logging.getLogger(__name__) -class SubordinateBase(OpenStackApplication): +@AppFactory.register_application(SUBORDINATES) +class SubordinateApplication(OpenStackApplication): """Subordinate base class.""" + # subordinate apps rely on the channel to evaluate current OpenStack release + based_on_channel = True + + @property + def current_os_release(self) -> OpenStackRelease: + """Infer the OpenStack release from subordinate charm's channel. + + We cannot determine the OpenStack release base on workload packages because the principal + charm has already upgraded the packages. + + :return: OpenStackRelease object. + :rtype: OpenStackRelease + """ + return self.channel_codename + def _check_application_target(self, target: OpenStackRelease) -> None: """Check if the application is already upgraded. @@ -87,20 +103,3 @@ def post_upgrade_steps( :rtype: list[PostUpgradeStep] """ return [] - - -@AppFactory.register_application(SUBORDINATES) -class SubordinateApplication(SubordinateBase): - """Subordinate application class.""" - - @property - def current_os_release(self) -> OpenStackRelease: - """Infer the OpenStack release from subordinate charm's channel. - - We cannot determine the OpenStack release base on workload packages because the principal - charm has already upgraded the packages. - - :return: OpenStackRelease object. - :rtype: OpenStackRelease - """ - return self.channel_codename diff --git a/cou/steps/analyze.py b/cou/steps/analyze.py index d31efc7b..b19d721f 100644 --- a/cou/steps/analyze.py +++ b/cou/steps/analyze.py @@ -20,9 +20,7 @@ from typing import Optional from cou.apps.base import OpenStackApplication -from cou.apps.channel_based import ChannelBasedApplication from cou.apps.factory import AppFactory -from cou.apps.subordinate import SubordinateBase from cou.utils import juju_utils from cou.utils.app_utils import stringify_objects from cou.utils.openstack import DATA_PLANE_CHARMS, UPGRADE_ORDER, OpenStackRelease @@ -171,10 +169,7 @@ def min_os_release_apps(apps: list[OpenStackApplication]) -> Optional[OpenStackR # be considered when on 'latest/stable' or from Charmstore because it's not reliable and # will be considered as Ussuri. apps_skipped = { - app - for app in apps - if isinstance(app, (ChannelBasedApplication, SubordinateBase)) - and app.using_non_release_channel + app for app in apps if app.based_on_channel and app.using_non_release_channel } if apps_skipped: logger.debug( diff --git a/cou/steps/plan.py b/cou/steps/plan.py index d4bdf153..df22350a 100644 --- a/cou/steps/plan.py +++ b/cou/steps/plan.py @@ -35,7 +35,7 @@ from cou.apps.base import OpenStackApplication from cou.apps.channel_based import ChannelBasedApplication # noqa: F401 from cou.apps.core import Keystone, Octavia, Swift # noqa: F401 -from cou.apps.subordinate import SubordinateApplication, SubordinateBase # noqa: F401 +from cou.apps.subordinate import SubordinateApplication # noqa: F401 from cou.commands import CONTROL_PLANE, DATA_PLANE, HYPERVISORS, CLIargs from cou.exceptions import ( COUException,