Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: handle the changes coming in ops 2.17 #191

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading