Skip to content

Commit

Permalink
add first draft of pseudo code for data plane upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
rgildein committed Jan 11, 2024
1 parent a269f71 commit 3845b9f
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 2 deletions.
37 changes: 37 additions & 0 deletions cou/apps/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ class ApplicationUnit:
machine: str = ""


@dataclass
class ApplicationMachine:
"""Representation of single machine of application."""

id: str
hostname: str
az: str
apps: list[OpenStackApplication]


@dataclass
class OpenStackApplication:
"""Representation of a charmed OpenStack application in the deployment.
Expand All @@ -83,6 +93,12 @@ class OpenStackApplication:
:type channel: str, defaults to ""
:param units: Units representation of an application.
:type units: list[ApplicationUnit]
:param machines: Machines representation of an application.
:type machines: list[ApplicationMachine]
:param wait_timeout: Waiting time for application/model status
:type wait_timeout: int
:param wait_for_model: Wait for app itself or for all OpenStack related applications
:type wait_for_model: bool
:raises ApplicationError: When there are no compatible OpenStack release for the
workload version.
:raises MismatchedOpenStackVersions: When units part of this application are running mismatched
Expand Down Expand Up @@ -173,6 +189,11 @@ def _populate_units(self) -> None:
)
)

@property
def is_data_plane(self) -> bool:
"""Check if applications belong to data plane."""
raise NotImplementedError

@property
def is_subordinate(self) -> bool:
"""Check if application is subordinate.
Expand Down Expand Up @@ -225,6 +246,11 @@ def is_from_charm_store(self) -> bool:
"""
return self.charm_origin == "cs"

@property
def machines(self) -> list[ApplicationMachine]:
"""Return list of machines."""
raise NotImplementedError

def is_valid_track(self, charm_channel: str) -> bool:
"""Check if the channel track is valid.
Expand Down Expand Up @@ -390,6 +416,17 @@ def can_upgrade_current_channel(self) -> bool:
"""
return bool(self.status.can_upgrade_to)

async def populate_units(self) -> None:
"""Populate units and filtered them.
This function is responsible for configuring the units for the application and at the same
time filtering them. e.g. Use only the machines that are required by user.
In specific applications such as nova-compute, it can be used to filter out non-empty
hypervisors.
"""
raise NotImplementedError

def new_origin(self, target: OpenStackRelease) -> str:
"""Return the new openstack-origin or source configuration.
Expand Down
72 changes: 72 additions & 0 deletions cou/apps/data_plane.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Copyright 2024 Canonical Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Data plane application class."""
import logging
from typing import Optional

from cou.apps.base import OpenStackApplication
from cou.apps.factory import AppFactory

logger = logging.getLogger(__name__)


class BaseDataPlaneApplication(OpenStackApplication):
"""Base data plane application."""

async def _check_control_plane_was_upgraded(self) -> bool:
"""Check that all control plane apps was upgraded.
This function is part of required pre-checks for all data plane apps.
"""
raise NotImplementedError

async def populate_units(
self,
hostname: Optional[str] = None,
machine_id: Optional[str] = None,
az: Optional[str] = None,
) -> None:
"""Populate units and filtered specific machine, hostname or az.
:param hostname: machine hostname
:type hostname: str
:param machine_id: machine id
:type machine_id: str
:param az: az of machine
:type az: str
"""
raise NotImplementedError


@AppFactory.register_application(["nova-compute"])
class NovaCompute(BaseDataPlaneApplication):
"""Nova-compute application."""

wait_timeout = 30 * 60 # 30 min
wait_for_model = True

async def instance_count(self) -> int:
"""Get number of instances running on hypervisor."""
raise NotImplementedError

async def populate_units(self, *args: Optional[str], **kwargs: Optional[str]) -> None:
"""Populate units and filtered specific machine, hostname or az.
:param args: arguments parser
:type args: Any
:param kwargs: named argument parser
:type kwargs: Any
"""
raise NotImplementedError
11 changes: 10 additions & 1 deletion cou/steps/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,23 @@ def __post_init__(self) -> None:
self.current_cloud_os_release = self._get_minimum_cloud_os_release()
self.current_cloud_series = self._get_minimum_cloud_series()

@staticmethod
def _sort_apps(apps: list[OpenStackApplication]) -> list[OpenStackApplication]:
"""Sort apps in order relevant to upgrade.
:param apps: List of applications to split.
:type apps: list[OpenStackApplication]
"""
raise NotImplementedError

@staticmethod
def _split_apps(
apps: list[OpenStackApplication],
) -> tuple[list[OpenStackApplication], list[OpenStackApplication]]:
"""Split applications to control plane and data plane apps.
:param apps: List of applications to split.
:type apps: Iterable[OpenStackApplication]
:type apps: list[OpenStackApplication]
:return: Control plane and data plane application lists.
:rtype: tuple[list[OpenStackApplication], list[OpenStackApplication]]
"""
Expand Down
8 changes: 7 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ ignore-paths = [
"tests",
"docs"
]
disable = [
"W0223",
]
no-docstring-rgx = "__.*__"
default-docstring-type = "sphinx"
accept-no-param-doc = false
Expand Down Expand Up @@ -80,11 +83,14 @@ exclude = [
relative_files = true
concurrency = ["gevent"]
source = ["."]
omit = ["tests/**", "docs/**", "lib/**", "snap/**", "build/**", "setup.py"]
omit = ["tests/**", "docs/**", "lib/**", "snap/**", "build/**", "setup.py", "cou/apps/data_plane.py"]

[tool.coverage.report]
fail_under = 100
show_missing = true
exclude_also = [
"raise NotImplementedError"
]

[tool.coverage.html]
directory = "tests/unit/report/html"
Expand Down

0 comments on commit 3845b9f

Please sign in to comment.