Skip to content

Commit

Permalink
The trust is really more context than state, per review.
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyandrewmeyer committed Jun 7, 2024
1 parent c7ed120 commit b895d36
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
4 changes: 4 additions & 0 deletions scenario/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ def __init__(
capture_framework_events: bool = False,
app_name: Optional[str] = None,
unit_id: Optional[int] = 0,
app_trusted: bool = False,
):
"""Represents a simulated charm's execution context.
Expand Down Expand Up @@ -225,6 +226,8 @@ def __init__(
:arg app_name: App name that this charm is deployed as. Defaults to the charm name as
defined in metadata.yaml.
:arg unit_id: Unit ID that this charm is deployed as. Defaults to 0.
:arg app_trusted: whether the charm has Juju trust (deployed with ``--trust`` or added with
``juju trust``). Defaults to False
:arg charm_root: virtual charm root the charm will be executed with.
If the charm, say, expects a `./src/foo/bar.yaml` file present relative to the
execution cwd, you need to use this. E.g.:
Expand Down Expand Up @@ -268,6 +271,7 @@ def __init__(

self._app_name = app_name
self._unit_id = unit_id
self.app_trusted = app_trusted
self._tmp = tempfile.TemporaryDirectory()

# config for what events to be captured in emitted_events.
Expand Down
4 changes: 2 additions & 2 deletions scenario/mocking.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,9 +632,9 @@ def resource_get(self, resource_name: str) -> str:
)

def credential_get(self) -> CloudSpec:
if not self._state.trusted:
if not self._context.app_trusted:
raise ModelError(
"ERROR charm is not trusted, initialise State with trusted=True",
"ERROR charm is not trusted, initialise Context with `app_trusted=True`",
)
if not self._state.model.cloud_spec:
raise ModelError(
Expand Down
2 changes: 0 additions & 2 deletions scenario/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -967,8 +967,6 @@ class State(_DCBase):
"""Whether this charm has leadership."""
model: Model = Model()
"""The model this charm lives in."""
trusted: bool = False
"""Whether ``juju-trust`` has been run for this charm."""
secrets: List[Secret] = dataclasses.field(default_factory=list)
"""The secrets this charm has access to (as an owner, or as a grantee).
The presence of a secret in this list entails that the charm can read it.
Expand Down
3 changes: 1 addition & 2 deletions tests/test_e2e/test_cloud_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@ def test_get_cloud_spec():
},
),
)
ctx = scenario.Context(MyCharm, meta={"name": "foo"})
ctx = scenario.Context(MyCharm, meta={"name": "foo"}, app_trusted=True)
state = scenario.State(
model=scenario.Model(
name="lxd-model", type="lxd", cloud_spec=scenario_cloud_spec
),
trusted=True,
)
with ctx.manager("start", state=state) as mgr:
assert mgr.charm.model.get_cloud_spec() == expected_cloud_spec
Expand Down

0 comments on commit b895d36

Please sign in to comment.