generated from canonical/template-operator
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
cc985cf
commit 3304eb0
Showing
16 changed files
with
1,198 additions
and
758 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[report] | ||
exclude_lines = | ||
# Skip any pass lines such as may be used for @abstractmethod | ||
pass | ||
|
||
# Ignore abstract methods | ||
@abstractmethod | ||
@abc.abstractmethod | ||
|
||
# Have to re-enable the standard pragma | ||
pragma: no cover | ||
|
||
# Don't complain about missing debug-only code: | ||
def __repr__ | ||
if self\.debug | ||
|
||
# Don't complain if tests don't hit defensive assertion code: | ||
raise AssertionError | ||
raise NotImplementedError | ||
|
||
# Don't complain if non-runnable code isn't run: | ||
if 0: | ||
if __name__ == .__main__.: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Copyright 2022 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
|
||
"""Utility functions for charms related operations.""" | ||
import re | ||
|
||
from charms.opensearch.v0.helper_enums import BaseStrEnum | ||
from ops.model import ActiveStatus | ||
|
||
# The unique Charmhub library identifier, never change it | ||
LIBID = "293db55a2d8949f8aa5906d04cd541ba" | ||
|
||
# Increment this major API version when introducing breaking changes | ||
LIBAPI = 0 | ||
|
||
# Increment this PATCH version before using `charmcraft publish-lib` or reset | ||
# to 0 if you are raising the major API version | ||
LIBPATCH = 1 | ||
|
||
|
||
class Status: | ||
"""Class for managing the various status changes in a charm.""" | ||
|
||
class CheckPattern(BaseStrEnum): | ||
"""Enum for types of status comparison.""" | ||
|
||
Equal = "equal" | ||
Start = "start" | ||
End = "end" | ||
Contain = "contain" | ||
Interpolated = "interpolated" | ||
|
||
def __init__(self, charm): | ||
self.charm = charm | ||
|
||
def clear(self, status_message: str, pattern: CheckPattern = CheckPattern.Equal): | ||
"""Resets the unit status if it was previously blocked/maintenance with message.""" | ||
unit = self.charm.unit | ||
|
||
condition: bool | ||
match pattern: | ||
case Status.CheckPattern.Equal: | ||
condition = unit.status.message == status_message | ||
case Status.CheckPattern.Start: | ||
condition = unit.status.message.startswith(status_message) | ||
case Status.CheckPattern.End: | ||
condition = unit.status.message.endswith(status_message) | ||
case Status.CheckPattern.Interpolated: | ||
condition = ( | ||
re.fullmatch(status_message.replace("{}", "(?s:.*?)"), status_message) | ||
is not None | ||
) | ||
case _: | ||
condition = status_message in unit.status.message | ||
|
||
if condition: | ||
unit.status = ActiveStatus() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.