Skip to content

Commit

Permalink
[DPE-4416] Rollback rolling-ops lib to LIBPATH=5 due to unhappy unit …
Browse files Browse the repository at this point in the history
…tests
  • Loading branch information
taurus-forever committed May 27, 2024
1 parent 9d8457b commit 8f3f1f1
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 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 = 7
LIBPATCH = 5


class LockNoRelationError(Exception):
Expand Down Expand Up @@ -182,7 +182,6 @@ 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 @@ -203,27 +202,21 @@ 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 @@ -273,11 +266,9 @@ 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 @@ -297,7 +288,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 handling other events.
distinct from other instances that may be hanlding 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 @@ -318,7 +309,6 @@ 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 @@ -391,7 +381,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 acquire does not
# emit relation changed event in the edge case where aquire does not
relation = self.model.get_relation(self.name)

# persist callback override for eventual run
Expand Down

0 comments on commit 8f3f1f1

Please sign in to comment.