Skip to content

Commit

Permalink
- removed unecessary SubordinateBase class
Browse files Browse the repository at this point in the history
- added based_on_channel class argument
  • Loading branch information
gabrielcocenza committed Apr 16, 2024
1 parent 3564947 commit 776cd71
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 40 deletions.
18 changes: 3 additions & 15 deletions cou/apps/auxiliary_subordinate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 3 additions & 0 deletions cou/apps/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions cou/apps/channel_based.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
35 changes: 17 additions & 18 deletions cou/apps/subordinate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
7 changes: 1 addition & 6 deletions cou/steps/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion cou/steps/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 776cd71

Please sign in to comment.