Skip to content

Commit

Permalink
Merge branch 'main' into feature/tempo_tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
shayancanonical committed Jun 13, 2024
2 parents 9e58375 + f135759 commit 589f1ce
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 26 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ on:
jobs:
lint:
name: Lint
uses: canonical/data-platform-workflows/.github/workflows/lint.yaml@v13.3.5
uses: canonical/data-platform-workflows/.github/workflows/lint.yaml@v14.0.0

unit-test:
name: Unit test charm
Expand All @@ -42,7 +42,7 @@ jobs:

build:
name: Build charm
uses: canonical/data-platform-workflows/.github/workflows/build_charm.yaml@v13.3.5
uses: canonical/data-platform-workflows/.github/workflows/build_charm.yaml@v14.0.0
with:
cache: true

Expand All @@ -58,12 +58,17 @@ jobs:
allure_on_amd64: true
architecture:
- amd64
include:
- juju:
agent: 3.1.8 # renovate: latest juju 3
allure_on_amd64: true
architecture: arm64
name: Integration test charm | ${{ matrix.juju.agent }} | ${{ matrix.architecture }}
needs:
- lint
- unit-test
- build
uses: canonical/data-platform-workflows/.github/workflows/integration_test_charm.yaml@v13.3.5
uses: canonical/data-platform-workflows/.github/workflows/integration_test_charm.yaml@v14.0.0
with:
artifact-prefix: ${{ needs.build.outputs.artifact-prefix }}
architecture: ${{ matrix.architecture }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ jobs:

build:
name: Build charm
uses: canonical/data-platform-workflows/.github/workflows/build_charm.yaml@v13.3.5
uses: canonical/data-platform-workflows/.github/workflows/build_charm.yaml@v14.0.0

release:
name: Release charm
needs:
- ci-tests
- build
uses: canonical/data-platform-workflows/.github/workflows/release_charm.yaml@v13.3.5
uses: canonical/data-platform-workflows/.github/workflows/release_charm.yaml@v14.0.0
with:
channel: 14/edge
artifact-prefix: ${{ needs.build.outputs.artifact-prefix }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sync_issue_to_jira.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
jobs:
sync:
name: Sync GitHub issue to Jira
uses: canonical/data-platform-workflows/.github/workflows/sync_issue_to_jira.yaml@v13.3.5
uses: canonical/data-platform-workflows/.github/workflows/sync_issue_to_jira.yaml@v14.0.0
with:
jira-base-url: https://warthogs.atlassian.net
jira-project-key: DPE
Expand Down
13 changes: 12 additions & 1 deletion lib/charms/data_platform_libs/v0/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def restart(self, event) -> None:

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 16
LIBPATCH = 17

PYDEPS = ["pydantic>=1.10,<2", "poetry-core"]

Expand Down Expand Up @@ -907,6 +907,17 @@ def _on_upgrade_charm(self, event: UpgradeCharmEvent) -> None:
logger.error(e)
self.set_unit_failed()
return
top_unit_id = self.upgrade_stack[-1]
top_unit = self.charm.model.get_unit(f"{self.charm.app.name}/{top_unit_id}")
if (
top_unit == self.charm.unit
and self.peer_relation.data[self.charm.unit].get("state") == "recovery"
):
# While in a rollback and the Juju leader unit is the top unit in the upgrade stack, emit the event
# for this unit to start the rollback.
self.peer_relation.data[self.charm.unit].update({"state": "ready"})
self.on_upgrade_changed(event)
return
self.charm.unit.status = WaitingStatus("other units upgrading first...")
self.peer_relation.data[self.charm.unit].update({"state": "ready"})

Expand Down
18 changes: 14 additions & 4 deletions lib/charms/rolling_ops/v0/rollingops.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def _restart(self, event):
To kick off the rolling restart, emit this library's AcquireLock event. The simplest way
to do so would be with an action, though it might make sense to acquire the lock in
response to another event.
response to another event.
```python
def _on_trigger_restart(self, event):
Expand Down Expand Up @@ -88,7 +88,7 @@ def _on_trigger_restart(self, event):

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 5
LIBPATCH = 7


class LockNoRelationError(Exception):
Expand Down Expand Up @@ -182,6 +182,7 @@ def _state(self) -> LockState:
# Active acquire request.
return LockState.ACQUIRE

logger.debug("Lock state: %s %s", unit_state, app_state)
return app_state # Granted or unset/released

@_state.setter
Expand All @@ -202,21 +203,27 @@ def _state(self, state: LockState):
if state is LockState.IDLE:
self.relation.data[self.app].update({str(self.unit): state.value})

logger.debug("state: %s", state.value)

def acquire(self):
"""Request that a lock be acquired."""
self._state = LockState.ACQUIRE
logger.debug("Lock acquired.")

def release(self):
"""Request that a lock be released."""
self._state = LockState.RELEASE
logger.debug("Lock released.")

def clear(self):
"""Unset a lock."""
self._state = LockState.IDLE
logger.debug("Lock cleared.")

def grant(self):
"""Grant a lock to a unit."""
self._state = LockState.GRANTED
logger.debug("Lock granted.")

def is_held(self):
"""This unit holds the lock."""
Expand Down Expand Up @@ -266,9 +273,11 @@ def __init__(self, handle, callback_override: Optional[str] = None):
self.callback_override = callback_override or ""

def snapshot(self):
"""Snapshot of lock event."""
return {"callback_override": self.callback_override}

def restore(self, snapshot):
"""Restores lock event."""
self.callback_override = snapshot["callback_override"]


Expand All @@ -288,7 +297,7 @@ def __init__(self, charm: CharmBase, relation: AnyStr, callback: Callable):
charm: the charm we are attaching this to.
relation: an identifier, by convention based on the name of the relation in the
metadata.yaml, which identifies this instance of RollingOperatorsFactory,
distinct from other instances that may be hanlding other events.
distinct from other instances that may be handling other events.
callback: a closure to run when we have a lock. (It must take a CharmBase object and
EventBase object as args.)
"""
Expand All @@ -309,6 +318,7 @@ def __init__(self, charm: CharmBase, relation: AnyStr, callback: Callable):
self.framework.observe(charm.on[self.name].acquire_lock, self._on_acquire_lock)
self.framework.observe(charm.on[self.name].run_with_lock, self._on_run_with_lock)
self.framework.observe(charm.on[self.name].process_locks, self._on_process_locks)
self.framework.observe(charm.on.leader_elected, self._on_process_locks)

def _callback(self: CharmBase, event: EventBase) -> None:
"""Placeholder for the function that actually runs our event.
Expand Down Expand Up @@ -381,7 +391,7 @@ def _on_acquire_lock(self: CharmBase, event: ActionEvent):
"""Request a lock."""
try:
Lock(self).acquire() # Updates relation data
# emit relation changed event in the edge case where aquire does not
# emit relation changed event in the edge case where acquire does not
relation = self.model.get_relation(self.name)

# persist callback override for eventual run
Expand Down
20 changes: 10 additions & 10 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ optional = true

[tool.poetry.group.integration.dependencies]
pytest = "^8.2.0"
pytest-github-secrets = {git = "https://github.com/canonical/data-platform-workflows", tag = "v13.3.5", subdirectory = "python/pytest_plugins/github_secrets"}
pytest-github-secrets = {git = "https://github.com/canonical/data-platform-workflows", tag = "v14.0.0", subdirectory = "python/pytest_plugins/github_secrets"}
pytest-operator = "^0.35.0"
pytest-operator-cache = {git = "https://github.com/canonical/data-platform-workflows", tag = "v13.3.5", subdirectory = "python/pytest_plugins/pytest_operator_cache"}
pytest-operator-groups = {git = "https://github.com/canonical/data-platform-workflows", tag = "v13.3.5", subdirectory = "python/pytest_plugins/pytest_operator_groups"}
pytest-operator-cache = {git = "https://github.com/canonical/data-platform-workflows", tag = "v14.0.0", subdirectory = "python/pytest_plugins/pytest_operator_cache"}
pytest-operator-groups = {git = "https://github.com/canonical/data-platform-workflows", tag = "v14.0.0", subdirectory = "python/pytest_plugins/pytest_operator_groups"}
# renovate caret doesn't work: https://github.com/renovatebot/renovate/issues/26940
juju = "<=3.4.0.0"
boto3 = "*"
Expand All @@ -80,7 +80,7 @@ landscape-api-py3 = "^0.9.0"
mailmanclient = "^3.3.5"
psycopg2-binary = "^2.9.9"
allure-pytest = "^2.13.5"
allure-pytest-collection-report = {git = "https://github.com/canonical/data-platform-workflows", tag = "v13.3.5", subdirectory = "python/pytest_plugins/allure_pytest_collection_report"}
allure-pytest-collection-report = {git = "https://github.com/canonical/data-platform-workflows", tag = "v14.0.0", subdirectory = "python/pytest_plugins/allure_pytest_collection_report"}

# Testing tools configuration
[tool.coverage.run]
Expand Down
2 changes: 1 addition & 1 deletion src/relations/async_replication.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ def _on_async_relation_changed(self, event: RelationChangedEvent) -> None:
def _on_async_relation_departed(self, event: RelationDepartedEvent) -> None:
"""Set a flag to avoid setting a wrong status message on relation broken event handler."""
# This is needed because of https://bugs.launchpad.net/juju/+bug/1979811.
if event.departing_unit == self.charm.unit:
if event.departing_unit == self.charm.unit and self.charm._peers is not None:
self.charm._peers.data[self.charm.unit].update({"departing": "True"})

def _on_async_relation_joined(self, _) -> None:
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def harness():
harness.begin()
harness.add_relation("upgrade", harness.charm.app.name)
harness.add_relation(PEER, harness.charm.app.name)
harness.add_relation("restart", harness.charm.app.name)
yield harness
harness.cleanup()

Expand Down

0 comments on commit 589f1ce

Please sign in to comment.