2.9.0: Pebble log forwarding, unit testing actions, and more
This release makes it easy to write tests for your Charm actions, aligns testing secrets with upcoming Juju changes, and exposes the ability to use the new Pebble log forwarding functionality. There's also the usual collection of documentation improvements, bug fixes, and other minor improvements.
Unit Testing Actions
Writing unit tests for actions with Harness is now as simple as:
def test_action(harness):
out = harness.run_action("my-action-name", {"param1": value, "param2": value2})
assert out.results == {"result1": "expected"}
Added in #1053
Secrets
In the original implementation of Juju secrets, the owner of a secret would automatically peek (get the latest revision) at secret contents - this also meant that using 'refresh' was not allowed (since there was no revision tracking). This behaviour causes difficulties in some situations, so is being changed in the next versions of Juju (back to 3.1.7), removing the automatic peek and allowing refresh.
In ops
, we are switching to the new behaviour, and this applies regardless of the detected/set JujuVersion. This primarily applies to Harness, which was updated in #1067, but also to the ops
documentation. The constraints outside of Harness are applied by Juju, so your charms will reflect the new behaviour when Juju updates.
Note that you can get the old behaviour by always using refresh=True
if that's what you prefer (to support both old and new Juju, you'll need to wrap this so that in older Juju you retry when it complains that you can't refresh).
We've also fixed the simulated access to app secrets for non-leaders in #1076.
Pebble Log Targets
Pebble 1.4 added the ability to configure log forwarding for services to a Loki server, and Pebble 1.6 extends this with the ability to add custom labels to the forwarded logs. This functionality is now exposed in ops
via a new (optional) log-targets
section in Pebble layers and plans. Added in #1074
Documentation Improvements
- A fresh README that's simpler and better aligns with the docs and other projects in the Juju universe in #1052 - many thanks to @tmihoc for this contribution!
- Clarified how custom events are emitted in
emit()
in #1072 - Fixed the
Harness.get_filesystem_root
example in the docs in #1065
Minor Improvements
- Removed the executable bit from all the .py files by in #1059 - thanks @jameinel!
- The test suite now passes under Python 3.12 in #1081
Fixes
- The SQLite storage file is no longer group/other readable. We strongly recommend against storing any secret data in stored state (use secrets), but we are aware of cases of this in the wild. This change prevents other users in the containers from being able to access the saved state file. Existing storage files will be
chmod
'd to 0o600 whenops
first opens them after upgrading to 2.9.0+. #1057 - When parsing a timestamp returned from Pebble, there was a 1 in 2 million chance that
ops
would fail with aValueError
. Fixed in #1084 Container.push_path
andHarness.list_files
would fail if the files/folders involved belonged to a user or group ID that did not have a name (for example, had been removed). Fixed in #1082. Thanks to @nedbat for the report!
Full Changelog: 2.8.0...2.9.0