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

feat: add support for cloud spec #119

Merged
merged 26 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b02cf85
feat: add support for cloud spec
IronCore864 Apr 8, 2024
108b1ce
test: add e2e test for cloud spec
IronCore864 Apr 8, 2024
9d58637
chore: fix linting
IronCore864 Apr 8, 2024
65be11b
chore: fix linting
IronCore864 Apr 8, 2024
8a058d1
chore: refactor according to code review
IronCore864 Apr 9, 2024
56e56db
chore: refactor according to code review
IronCore864 Apr 9, 2024
0c25e09
Update scenario/mocking.py
IronCore864 Apr 9, 2024
da8dea3
Update scenario/state.py
IronCore864 Apr 9, 2024
6e81250
refactor: some updates according to code review and standup discussions
IronCore864 Apr 10, 2024
d738b94
chore: refactor according to code review and standup discussion
IronCore864 Apr 11, 2024
db1f54f
chore: refactor according to code review
IronCore864 Apr 12, 2024
abaaf64
chore: fix static check
IronCore864 Apr 12, 2024
3a9a78d
chore: remove testing code
IronCore864 Apr 12, 2024
115b5bc
chore: make CloudCredential.to_ops_cloud_credential a private function'
IronCore864 Apr 15, 2024
d618391
docs: update readme with cloudspec
IronCore864 Apr 15, 2024
b274440
chore: make to ops methods private
IronCore864 Apr 15, 2024
1bc5e5c
chore: change import ops to import specific things
IronCore864 Apr 15, 2024
8e7dd97
chore: fix linting and ut
IronCore864 Apr 15, 2024
82b109c
chore: rename to ops method after discussion
IronCore864 Apr 15, 2024
77913d1
chore: fixing scenario imports
IronCore864 Apr 15, 2024
389dd65
chore: fix readability issue
IronCore864 Apr 15, 2024
e1bb629
docs: update readme cloudspec code example
IronCore864 Apr 15, 2024
82e8e4c
chore: add a missing type
IronCore864 Apr 15, 2024
3e1acc9
Update scenario/consistency_checker.py
IronCore864 Apr 17, 2024
0739003
chore: updating comment for redacted according to review suggestions
IronCore864 May 29, 2024
c56e267
Merge branch 'cloud-spec' of github.com:IronCore864/ops-scenario into…
IronCore864 May 29, 2024
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
9 changes: 8 additions & 1 deletion scenario/mocking.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
)

from ops import JujuVersion, pebble
from ops.model import ModelError, RelationNotFoundError
from ops.model import CloudSpec, ModelError, RelationNotFoundError
IronCore864 marked this conversation as resolved.
Show resolved Hide resolved
from ops.model import Secret as Secret_Ops # lol
from ops.model import (
SecretInfo,
Expand Down Expand Up @@ -631,6 +631,13 @@ def resource_get(self, resource_name: str) -> str:
f"resource {resource_name} not found in State. please pass it.",
)

def credential_get(self) -> CloudSpec:
if not self._state.cloud_spec:
raise ModelError(
IronCore864 marked this conversation as resolved.
Show resolved Hide resolved
"ERROR cloud spec is empty, initialise it with `scenario.State(cloud_spec=...)`",
IronCore864 marked this conversation as resolved.
Show resolved Hide resolved
)
return self._state.cloud_spec


class _MockPebbleClient(_TestingPebbleClient):
def __init__(
Expand Down
3 changes: 2 additions & 1 deletion scenario/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import yaml
from ops import pebble
from ops.charm import CharmBase, CharmEvents
from ops.model import SecretRotate, StatusBase
from ops.model import CloudSpec, SecretRotate, StatusBase

from scenario.logger import logger as scenario_logger

Expand Down Expand Up @@ -919,6 +919,7 @@ class State(_DCBase):
"""Status of the unit."""
workload_version: str = ""
"""Workload version."""
cloud_spec: Optional[CloudSpec] = None
IronCore864 marked this conversation as resolved.
Show resolved Hide resolved

def __post_init__(self):
for name in ["app_status", "unit_status"]:
Expand Down
40 changes: 40 additions & 0 deletions tests/test_e2e/test_cloud_spec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import ops
import pytest

import scenario


@pytest.fixture(scope="function")
IronCore864 marked this conversation as resolved.
Show resolved Hide resolved
def mycharm():
class MyCharm(ops.CharmBase):
def __init__(self, framework: ops.Framework):
super().__init__(framework)
for evt in self.on.events().values():
self.framework.observe(evt, self._on_event)

def _on_event(self, event):
pass

return MyCharm


def test_get_cloud_spec(mycharm):
IronCore864 marked this conversation as resolved.
Show resolved Hide resolved
cloud_spec = ops.model.CloudSpec.from_dict(
{
"name": "localhost",
"type": "lxd",
"endpoint": "https://127.0.0.1:8443",
"credential": {
"auth-type": "certificate",
"attrs": {
"client-cert": "foo",
"client-key": "bar",
"server-cert": "baz",
},
},
}
)

ctx = scenario.Context(mycharm, meta={"name": "foo"})
with ctx.manager("start", scenario.State(cloud_spec=cloud_spec)) as mgr:
assert mgr.charm.model.get_cloud_spec() == cloud_spec
IronCore864 marked this conversation as resolved.
Show resolved Hide resolved
Loading