docs: remove override = "merge" from test_pebble_layer in configurable charm tutorial
Maintainers usually reply within 3 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Newbie friendliness
- 85/100
- Issue type
- Documentation
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- python
- Domain
- documentation
Research direction
Edit docs/tutorial/from-zero-to-hero-write-your-first-kubernetes-charm/make-your-charm-configurable.md in the "Write unit tests" section and drop the line setting expected_plan.services["fastapi"].override = "merge". Cross-check examples/k8s-2-configurable/tests/unit/test_charm.py for the same line, and run tox -e unit in that example to confirm test_pebble_layer passes with the plan keeping 'override': 'replace'. Done means the tutorial text and the example test agree and the unit test is green.
Written by the indexing model from the issue text.
Description
Page URL
Description
In the Write unit tests section of the "Make your charm configurable" tutorial, the instructions ask to add expected_plan.services["fastapi"].override = "merge" to test_pebble_layer in tests/unit/test_charm.py:
# Expected plan after Pebble ready with default config.
expected_plan = ops.pebble.Plan(ROCK_LAYER.to_dict())
expected_plan.services["fastapi"].override = "merge"
When running tox -e unit in a fresh environment (ops 3.10.0), test_pebble_layer fails because the merged Plan keeps 'override': 'replace' from ROCK_LAYER rather than overwriting it with 'merge':
-------------------------------- Captured log call ---------------------------------
DEBUG root:_main.py:345 ops 3.10.0 up and running.
DEBUG root:storage.py:70 Initializing SQLite local storage: :memory:.
DEBUG root:_main.py:481 Emitting Juju event demo_server_pebble_ready.
INFO charm:charm.py:75 Added updated layer 'fastapi_demo' to Pebble plan
INFO charm:charm.py:80 Replanned with 'fastapi' service
============================= short test summary info ==============================
FAILED tests/unit/test_charm.py::test_pebble_layer - AssertionError: assert Plan({'services': {'fastapi': {'summary': 'FastAPI demo server', 'startup': 'enabled', 'override': 'replace', 'command': '/bin/uvicorn api_demo_server.app:app --host 0.0.0.0 --port 8000', 'on-success': 'shutdown', 'on-failure': 'shutdown'}}}) == Plan({'services': {'fastapi': {'summary': 'FastAPI demo server', 'startup': 'enabled', 'override': 'merge', 'command': '/bin/uvicorn api_demo_server.app:app --host 0.0.0.0 --port 8000', 'on-success': 'shutdown', 'on-failure': 'shutdown'}}})
Root Cause
Inspecting ops.pebble.Service._merge inside the tox unit test environment confirms that ops 3.10.0 matches real Pebble's layer-merging behavior by preserving the existing service's override value when merging a layer:
$ .tox/unit/bin/python -c "import inspect, ops.pebble; print(inspect.getsource(ops.pebble.Service._merge))"
def _merge(self, other: Service):
"""Merges this service object with another service definition.
For attributes present in both objects, the passed in service
attributes take precedence.
"""
for name, value in other.__dict__.items():
if name in ('user_id', 'group_id') and value is not None:
setattr(self, name, value)
continue
# Pebble keeps the existing override when it merges a layer in.
if not value or name in ('name', 'override'):
continue
if name in ['after', 'before', 'requires']:
getattr(self, name).extend(value)
elif name in ['environment', 'on_check_failure']:
getattr(self, name).update(value)
else:
setattr(self, name, value)
Because ROCK_LAYER defines "override": "replace", the merged Plan retains 'override': 'replace', making expected_plan.services["fastapi"].override = "merge" fail.
Suggested Fix
- Remove the instruction to add
expected_plan.services["fastapi"].override = "merge"fromdocs/tutorial/from-zero-to-hero-write-your-first-kubernetes-charm/make-your-charm-configurable.md. - Update
examples/k8s-2-configurable/tests/unit/test_charm.py(and subsequent tutorial chapters/examples) accordingly when bumping theiropsdependency.
Reported from: https://canonical.com/juju/docs/ops/latest/tutorial/from-zero-to-hero-write-your-first-kubernetes-charm/make-your-charm-configurable/
- Dominant language
- Python
- Stars
- 267
- Forks
- 156
- Avg merge
- 5d 5h
- Merged PRs (30d)
- 43
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from canonical/operator
-
docs: reorder interface definition before fetch-libs and link PostgreSQL/library docs in tutorialOpen
Difficulty 1/5 Under an hour Newbie friendliness 90/100
Maintainers usually reply within 3 days
-
test_pull_path_non_ascii_or_trailing_whitespace fails with XPASS(strict)Possibly taken @tonyandrewmeyer claimed this today. Opentests
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
canonical/operator#2953 · 1 comment · 1 assignee ·
Maintainers usually reply within 3 days
-
rainy day small item
Difficulty 2/5 1-3 hours Newbie friendliness 71/100
Maintainers usually reply within 3 days
-
Cleaning up inconsistencies in the Manage relations how-to pagePossibly taken @tromai claimed this 2 days ago. Opendocs roadmap
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
canonical/operator#2688 · 3 comments · 1 assignee ·
Maintainers usually reply within 3 days
-
docs rainy day tests
Difficulty 3/5 1-2 days Newbie friendliness 56/100
canonical/operator#2952 · 1 reaction ·
Maintainers usually reply within 3 days
All issues in canonical/operator
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Kludex/python-multipart#375 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 3 days
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 11 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
FuRongJun-1999/dsh-memory#1000 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
gcivil-nyu-org/team5-mon-fall26#154 ·
Maintainers usually reply within 1 day