baseosmgr: add Phase-1 unit tests + pathConfig seam#5922
Draft
eriknordmark wants to merge 3 commits into
Draft
Conversation
Adds pkg/pillar/docs/baseosmgr.md describing the responsibilities, pubsub inputs and outputs, internal logical components, control flow through the five main paths (boot, BaseOsConfig install, content-tree progress, test-complete commit, reboot-after-failed-update) plus the force-fallback and retry-update side channels, and a debugging section. Structured to mirror the existing nim.md and nodeagent.md so the pillar docs remain consistent across microservices. Signed-off-by: eriknordmark <erik@zededa.com> Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Lifts the three on-disk paths baseosmgr persists across reboots (current_retry_update_counter, config_retry_update_counter, forceFallbackCounter) out of package-level constants and into a pathConfig struct hung off baseOsMgrContext. defaultPathConfig() returns the production paths under /persist/, so behaviour is unchanged. Run() initialises ctx.paths early. The five callers — saveCurrentRetryUpdateCounter, saveConfigRetryUpdateCounter, readSavedCurrentRetryUpdateCounter, readSavedConfigRetryUpdateCounter, readForceFallbackCounter and writeForceFallbackCounter — now take *baseOsMgrContext and consult ctxPtr.paths instead of the constants. The corresponding callers in Run() and handleForceFallback are updated. This is the minimal seam needed for upcoming unit tests so the counter persistence helpers can be driven against t.TempDir() without touching /persist/. Signed-off-by: eriknordmark <erik@zededa.com> Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds unit-test coverage for baseosmgr's pure helpers, lookup
functions, publication helpers and the persistent counter files.
No production behaviour change. The previous commit added the
pathConfig seam that lets the counter tests run against t.TempDir()
instead of /persist/.
Coverage of the package goes from 0% to 16.1% of statements
(go test -count=1 -cover). The remaining uncovered code is the
zboot-driven state machine (validatePartition,
validateAndAssignPartition, doBaseOsActivate, handleZbootTestComplete,
handleForceFallback, updateBaseOsStatusOnReboot, the install worker,
shouldDeferForNodeDrain) plus Run() and the agentlog-backed global
config branch — to be unlocked by a Zboot/kubeapi seam in Phase 2.
Files added (one per logical concern):
- helpers_test.go log init helper
- mocks_test.go mockPubSub (Publication+Subscription) and the
newTestCtx fixture (per-test temp paths +
all pubs/subs wired up)
- baseosmgr_test.go validateBaseOsConfig, appendError,
publishBaseOSMgrStatus
- lookups_test.go lookupBaseOsConfig / Status / StatusByPartLabel /
StatusesByContentID / ConfigByVersion,
lookupContentTreeStatus
- publish_test.go publishBaseOsStatus, unpublishBaseOsStatus,
publishZbootStatus
- counters_test.go save / readSaved current and config retry update
counters; absent / present / overwrite / garbage
- forcefallback_test.go read / write force-fallback counter; absent /
present / overwrite / garbage
- contenttree_test.go checkContentTreeStatus missing / loaded-no-change /
loaded-from-initial / error;
handleContentTreeStatusImpl no-fanout
- globalconfig_test.go handleGlobalConfigImpl / Delete non-global key
fast paths
- wrappers_test.go trivial Delete dispatch wrappers,
maybeRetryInstall non-TooEarly / no-config branches,
shouldDeferForNodeDrain NOTSUPPORTED short-circuit,
handleNodeDrainStatusImpl non-UPDATE ignore
Signed-off-by: eriknordmark <erik@zededa.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This was referenced May 8, 2026
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #5922 +/- ##
==========================================
+ Coverage 21.62% 22.28% +0.66%
==========================================
Files 464 475 +11
Lines 83994 85700 +1706
==========================================
+ Hits 18166 19101 +935
- Misses 64300 64885 +585
- Partials 1528 1714 +186 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Phase 1 of bringing
pkg/pillar/cmd/baseosmgr/from 0% to non-trivialunit-test coverage. Companion to #5921 (the architecture doc).
The PR is split into two commits so the refactor can be reviewed
independently from the tests:
baseosmgr: introduce pathConfig seam for persistent files—refactor only; no behaviour change. Lifts the three on-disk paths
baseosmgr persists across reboots
(`current_retry_update_counter`, `config_retry_update_counter`,
`forceFallbackCounter`) out of package-level constants and into
a `pathConfig` struct hung off `baseOsMgrContext`.
`defaultPathConfig()` returns the production paths under
`/persist/`. The five callers (`saveCurrentRetryUpdateCounter`,
`saveConfigRetryUpdateCounter`, `readSavedCurrentRetryUpdateCounter`,
`readSavedConfigRetryUpdateCounter`, `readForceFallbackCounter`,
`writeForceFallbackCounter`) now take `*baseOsMgrContext` and
consult `ctxPtr.paths` instead of the constants.
baseosmgr: add Phase-1 unit tests— 10 new test files. Noproduction change.
Coverage delta
go test -count=1 -cover ./cmd/baseosmgr/...Phase-1 covers the pure helpers, lookups, publishes, content-tree
status, the persistent counter files, and the trivial dispatcher /
delete wrappers. The remaining ~70% of statements is the
zboot-driven state machine (`doBaseOsStatusUpdate`,
`doBaseOsActivate`, `validatePartition`, `validateAndAssignPartition`,
`handleZbootTestComplete`, `handleForceFallback`,
`updateBaseOsStatusOnReboot`, `handleUpdateRetryCounter`, the
install worker, `shouldDeferForNodeDrain`) plus `Run()` — all
unblocked by Phase-2's Zboot / kubeapi / HVType seams.
Test files added (one per logical concern):
the `newTestCtx` fixture (per-test temp paths + all pubs/subs
wired up).
`publishBaseOSMgrStatus`.
StatusByPartLabel / StatusesByContentID / ConfigByVersion`,
`lookupContentTreeStatus`.
`unpublishBaseOsStatus`, `publishZbootStatus`.
update counters; absent / present / overwrite / garbage.
absent / present / overwrite / garbage.
loaded-no-change / loaded-from-initial / error;
`handleContentTreeStatusImpl` no-fanout.
non-global key fast paths.
`maybeRetryInstall` non-TooEarly / no-config branches,
`shouldDeferForNodeDrain` NOTSUPPORTED short-circuit,
`handleNodeDrainStatusImpl` non-UPDATE ignore.
Why draft
Drafted because the Phase-2 refactor + tests (Zboot/kubeapi/HVType
seams) is the larger, more reviewable chunk and may inform feedback
on the layering used here. Happy to mark ready for review once
Phase 2 has been seen, or sooner if reviewers want to look now.
PR dependencies
None hard. Reads better after #5921.
How to test and validate this PR
```sh
cd pkg/pillar
go test -count=1 -race -cover ./cmd/baseosmgr/...
go test -count=1 -coverprofile=/tmp/b.cov ./cmd/baseosmgr/...
go tool cover -func=/tmp/b.cov
```
Expected: all tests pass, coverage ≈ 16.1%.
Changelog notes
No user-facing changes.
PR Backports
Checklist