zedagent: extend docs with internals and startup sequence#5898
Open
eriknordmark wants to merge 2 commits intolf-edge:masterfrom
Open
zedagent: extend docs with internals and startup sequence#5898eriknordmark wants to merge 2 commits intolf-edge:masterfrom
eriknordmark wants to merge 2 commits intolf-edge:masterfrom
Conversation
8971916 to
36d1062
Compare
Extends pkg/pillar/docs/zedagent.md with two new sections: - Startup Sequence: documents the 13-step, gate-based initialization that zedagent performs before entering its main event loop, including the onboarding gate, NodeAgentStatus gate, cipher module setup, Zboot gate, and DNS gate. - Goroutine Architecture: documents the long-running goroutines (objectInfoTask, metricsTask, etc.) and the central mainEventLoop that dispatches pubsub events to their handlers. Adds a new file pkg/pillar/docs/zedagent-internals.md covering: - Pubsub map (all publications and subscriptions with their topics, keys, and consumer/producer agents). - Handler naming conventions and the Create/Modify/Delete/Impl pattern. - Metric and info publish pipeline with data-flow from source microservices through zedagent to the controller. - Eden integration test guidance: how to write testscripts that match the correct proto path for info, metric, and flow-log messages. Signed-off-by: eriknordmark <erik@zededa.com> Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
bc64b65 to
b78c0e0
Compare
Refactor loadBootstrapConfig and loadGlobalConfig to extract testable impl functions that accept file paths as parameters rather than using the hardcoded /config/* constants. The crypto validation path is further separated into validateBootstrapConfig, which returns a parsed *EdgeDevConfig without requiring a getconfigCtx. Add VerifyLeavesCertChainWithRootPEM to controllerconn so callers can supply a root certificate PEM directly instead of reading from /config/root-certificate.pem, enabling unit testing of the full certificate chain verification without touching the filesystem. Add handleconfig_test.go with 10 unit tests covering: - validateBootstrapConfig: missing file, success with real ECDSA key generation and signature, malformed proto, invalid cert chain (wrong root CA), and corrupted signature - TestBootstrapConfigPublishesDPC: verifies that a bootstrap config carrying a SystemAdapter is parsed and published as a DevicePortConfig with ConfigSource.Origin == NetworkConfigOriginBootstrap - loadGlobalConfigImpl: missing file, success, authorized keys, and malformed JSON Signed-off-by: eriknordmark <erik@zededa.com> Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
b78c0e0 to
9a672c2
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #5898 +/- ##
==========================================
- Coverage 19.52% 17.17% -2.36%
==========================================
Files 19 474 +455
Lines 3021 85666 +82645
==========================================
+ Hits 590 14717 +14127
- Misses 2310 69424 +67114
- Partials 121 1525 +1404 ☔ 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
This PR contains two commits extending the zedagent package with documentation
and unit tests.
Commit 1: zedagent: extend docs with internals and startup sequence
pkg/pillar/docs/zedagent.mdgains two new sections:that zedagent performs before entering its main event loop. Each gate
(onboarding, NodeAgentStatus, cipher, Zboot, DNS) is explained with
the reason it must block before the next stage can proceed.
launched at startup (
objectInfoTask,metricsTask, etc.) and thecentral
mainEventLoopthat dispatches pubsub events.pkg/pillar/docs/zedagent-internals.mdis a new file covering:pubsub key, and the producer/consumer agent.
used throughout the codebase.
microservices through zedagent to the controller.
correctly reference proto field paths for info, metric, and flow-log
messages (including the
MetricContentoneof vs. direct fieldsdistinction that is a common source of test errors).
Commit 2: zedagent: unit tests for bootstrap and global config loading
Adds unit tests and supporting refactoring to cover the zedagent startup
sequence paths that are not exercised by Eden e2e tests (bootstrap config
loading, global config loading, and DPC publication from bootstrap).
pkg/pillar/cmd/zedagent/handleconfig.gois refactored to exposetestable entry points:
validateBootstrapConfig(bootstrapFile, rootCertFile string)– performsthe full cert-chain verification and ECDSA signature check without
requiring a live
getconfigContext.loadBootstrapConfigImpl(ctx, bootstrapFile, rootCertFile string)–delegates from the existing
loadBootstrapConfig.loadGlobalConfigImpl(ctx, globalConfigFile, authorizedKeysFile string)–delegates from the existing
loadGlobalConfig.pkg/pillar/controllerconn/authen.gogainsVerifyLeavesCertChainWithRootPEMso tests can supply their own root certPEM instead of reading
/config/root-certificate.pemfrom disk.pkg/pillar/cmd/zedagent/handleconfig_test.go(new) contains 10 tests:TestValidateBootstrapConfigMissingFile– no file → (nil, nil)TestValidateBootstrapConfigSuccess– valid signed proto → parsed configTestValidateBootstrapConfigMalformedProto– corrupt bytes → errorTestValidateBootstrapConfigInvalidCertChain– wrong root CA → errorTestValidateBootstrapConfigInvalidSignature– flipped signature bit → errorTestBootstrapConfigPublishesDPC– bootstrap config with SystemAdapterpublishes a
DevicePortConfigwithNetworkConfigOriginBootstrapTestLoadGlobalConfigMissingFile– no file → falseTestLoadGlobalConfigSuccess– valid JSON → globalConfig updatedTestLoadGlobalConfigWithAuthorizedKeys– authorized_keys file contentpropagated to
SSHAuthorizedKeysconfig itemTestLoadGlobalConfigMalformedJSON– invalid JSON → falsePR dependencies
None.
How to test and validate this PR
All 10 new tests should pass. The rest of the documentation can be reviewed
as rendered Markdown in
pkg/pillar/docs/.Changelog notes
No user-facing changes. Internal documentation and unit test improvements
for the zedagent microservice.
PR Backports
Checklist