diff --git a/pyproject.toml b/pyproject.toml index f8c89a48..7151bf22 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 = "pietro.pasotti@canonical.com" } diff --git a/scenario/mocking.py b/scenario/mocking.py index f5207a37..5b91c15b 100644 --- a/scenario/mocking.py +++ b/scenario/mocking.py @@ -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] diff --git a/scenario/ops_main_mock.py b/scenario/ops_main_mock.py index 27f00a8b..786b113f 100644 --- a/scenario/ops_main_mock.py +++ b/scenario/ops_main_mock.py @@ -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