Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request canonical#191 from tonyandrewmeyer/support-ops-2-17
Browse files Browse the repository at this point in the history
chore: handle the changes coming in ops 2.17
  • Loading branch information
tonyandrewmeyer authored Sep 12, 2024
2 parents 29a50b7 + ab086fc commit 69b1be2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "ops-scenario"

version = "7.0.1"
version = "7.0.2"

authors = [
{ name = "Pietro Pasotti", email = "[email protected]" }
Expand Down
19 changes: 14 additions & 5 deletions scenario/mocking.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,20 @@ def _get_secret(self, id=None, label=None):
# in scenario, you can create Secret(id="foo"),
# but ops.Secret will prepend a "secret:" prefix to that ID.
# we allow getting secret by either version.
secrets = [
s
for s in self._state.secrets
if canonicalize_id(s.id) == canonicalize_id(id)
]
try:
secrets = [
s
for s in self._state.secrets
if canonicalize_id(s.id, model_uuid=self._state.model.uuid) # type: ignore
== canonicalize_id(id, model_uuid=self._state.model.uuid) # type: ignore
]
except TypeError:
# ops 2.16
secrets = [
s
for s in self._state.secrets
if canonicalize_id(s.id) == canonicalize_id(id) # type: ignore
]
if not secrets:
raise SecretNotFoundError(id)
return secrets[0]
Expand Down
13 changes: 9 additions & 4 deletions scenario/ops_main_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@
import ops.model
import ops.storage
from ops import CharmBase

# use logger from ops._main so that juju_log will be triggered
try:
from ops._main import CHARM_STATE_FILE, _Dispatcher, _get_event_args # type: ignore
from ops._main import logger as ops_logger # type: ignore
except ImportError:
# Ops 2.16
from ops.main import CHARM_STATE_FILE, _Dispatcher, _get_event_args # type: ignore
from ops.main import logger as ops_logger # type: ignore
from ops.charm import CharmMeta
from ops.log import setup_root_logging

# use logger from ops.main so that juju_log will be triggered
from ops.main import CHARM_STATE_FILE, _Dispatcher, _get_event_args
from ops.main import logger as ops_logger

from scenario.errors import BadOwnerPath, NoObserverError

if TYPE_CHECKING: # pragma: no cover
Expand Down

0 comments on commit 69b1be2

Please sign in to comment.