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

Add support for passing charmcraft.yaml as metadata #156

Closed
gruyaume opened this issue Jul 16, 2024 · 4 comments
Closed

Add support for passing charmcraft.yaml as metadata #156

gruyaume opened this issue Jul 16, 2024 · 4 comments
Labels

Comments

@gruyaume
Copy link

gruyaume commented Jul 16, 2024

Description

Charmcraft.yaml (replacing metadata.yaml) now removes the need to have different files for metadata, config, and actions. When providing metadata in the charmcraft.yaml format, we get a InconsistentScenarioError error because the config option is not recognized.

METADATA = yaml.safe_load(Path("tests/unit/charms/tls_certificates_interface/v4/dummy_requirer_charm/charmcraft.yaml").read_text())
state_in = scenario.State(
    config={"common_name": "example.com"},
)
ctx = scenario.Context(
    charm_type=DummyTLSCertificatesRequirerCharm,
    meta=METADATA,
)

Logs

scenario.runtime.InconsistentScenarioError: Inconsistent scenario. The following errors were found: config option 'common_name' in state.config but not specified in config.yaml.

Desired state

self.ctx = scenario.Context(
    charm_type=DummyTLSCertificatesRequirerCharm,
    meta=METADATA,
)

Workaround

self.ctx = scenario.Context(
    charm_type=DummyTLSCertificatesRequirerCharm,
    meta=METADATA,
    config=METADATA["config"],
    actions=METADATA["actions"],
)
@tonyandrewmeyer
Copy link
Collaborator

Support for the unified charmcraft.yaml was added in #91, but only for the autoloading where it finds the file (and under the hood it's basically doing what you describe in the workaround section).

I can see that it would be convenient to just throw an entire YAML file to the metadata argument and have Scenario figure it out.

@tonyandrewmeyer tonyandrewmeyer changed the title Add support for charmcraft.yaml Add support for passing charmcraft.yaml as metadata Jul 16, 2024
@PietroPasotti
Copy link
Collaborator

should we consider in 7.0 to have the unified charmcraft as default?

Context(charm:CharmType, meta:CharmcraftYaml = None)

and offer a helper to_charmcraft_yaml(meta, config, actions) function?

A less hardline approach would be to keep the Context signature as is, but change the semantics of the 'meta' argument to also accept 'unified charmcraft yaml'.
Downside is that with this we'd have to guard against passing a combination of 'charmcraft yaml' + actions and/or config.

@tonyandrewmeyer
Copy link
Collaborator

should we consider in 7.0 to have the unified charmcraft as default?

Context(charm:CharmType, meta:CharmcraftYaml = None)

and offer a helper to_charmcraft_yaml(meta, config, actions) function?

+1

A less hardline approach would be to keep the Context signature as is, but change the semantics of the 'meta' argument to also accept 'unified charmcraft yaml'. Downside is that with this we'd have to guard against passing a combination of 'charmcraft yaml' + actions and/or config.

Yeah, and the names are then confusing I think: even though it's "meta" and not "metadata", having a set of (meta, config, actions) feels very much like you are expected to not have the config/actions in the first arg.

@tonyandrewmeyer
Copy link
Collaborator

Moved to canonical/operator#1424

@tonyandrewmeyer tonyandrewmeyer closed this as not planned Won't fix, can't repro, duplicate, stale Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants