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

refactor: reduce the YAML loading and dumping in ops.testing #7

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

tonyandrewmeyer
Copy link
Owner

@tonyandrewmeyer tonyandrewmeyer commented Dec 17, 2024

Work-in-progress PR. Submit to upstream once it's more complete.

Changes:

  • Create the ops.CharmMeta object using the dictionaries that we already have in the _CharmSpec object rather than loading and deserialising from disk.
  • Cache the metadata, config, and actions dictionaries that are loaded from charmcraft.yaml (or the separate YAML files) in the original charm directory.

It would be nice if we could avoid deserialising and writing the YAML files to the temporary charm directory. However, charms might be using those directly (I think we can say that they shouldn't for metadata.yaml, and probably actions.yaml - however CharmMeta does not currently load config.yaml, so it's legitimate to do that to get the defaults, for example). We could certainly cache the serialised form - we could perhaps symlink rather than write, but since the original form is possibly charmcraft.yaml, we'd need to write to one place, so that might not be a win. Biggest question is whether the charm tests actually need these files.

At the moment, timing is not necessarily a win:

Suite main branch
operator/testing unit tests 6.63s 6.65s
traefik scenario tests (upstream/scenario-7-migraine) 63.14s 57.21s
kafka-k8s-operator (-e unit -- -s tests/unit/test_charm.py) 4.71s 4.73s

Once done, should resolve canonical#1498

There are some drive-by trailing whitespace fixes that come from running the pre-commit linting in the testing folder. Could move these out to a separate PR.

Similarly, shebangs are removed from files that aren't meant to be directly executed. Could move those out too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reduce the amount of YAML load/dump calls present in Scenario tests
1 participant