Skip to content

many: early device context and Ensure refactor (phase 2) - #17682

Open
pedronis wants to merge 7 commits into
canonical:masterfrom
pedronis:refactor-early-ensure-phase2-copilot
Open

pedronis wants to merge 7 commits into
canonical:masterfrom
pedronis:refactor-early-ensure-phase2-copilot

Conversation

@pedronis

Copy link
Copy Markdown
Contributor

This is phase 2 of the Ensure refactor started in #17483 It completes the move from repeated prerequisite checks in leaf methods to resolving seed readiness and device context once in each manager’s Ensure.

Passes resolved DeviceContext values into dependent device and snap ensure helpers.
Makes post-seeding dependencies explicit through EnsureAfterSeed/ensure...AfterSeed naming and removes redundant seeded, model, and context lookups.
Preserves pre-seed, at-seed, and post-seed ordering and error aggregation.
Tightens readiness gates for device-management exchanges, service updates, and kernel command-line fragment application.
Extends tests for readiness gates, early-seed cache lifecycle, and EnsureAfterSeed logging.

@pedronis pedronis added the Run nested The PR also runs tests inluded in nested suite label Sep 21, 2026
@github-actions github-actions Bot added the Run only one system Only runs spread tests on one system label Sep 21, 2026
@codecov

codecov Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.89655% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.39%. Comparing base (34a5f6c) to head (6625226).
⚠️ Report is 6 commits behind head on master.

Files with missing lines Patch % Lines
overlord/swfeats/swfeatstest/ensurelogchecker.go 68.42% 11 Missing and 1 partial ⚠️
overlord/devicestate/devicemgr.go 72.72% 2 Missing and 4 partials ⚠️
overlord/snapstate/snapmgr.go 93.33% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #17682      +/-   ##
==========================================
- Coverage   78.52%   78.39%   -0.14%     
==========================================
  Files        1418     1417       -1     
  Lines      200500   200463      -37     
  Branches     2502     2503       +1     
==========================================
- Hits       157444   157145     -299     
+ Misses      33945    33915      -30     
- Partials     9111     9403     +292     
Flag Coverage Δ
unittests 78.39% <81.89%> (-0.14%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The logging checker no longer validates child ensures beneath renamed submanager entry points.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Centralizes seed readiness and device-context resolution in manager Ensure paths.

Changes:

  • Renames post-seed helpers and passes resolved device contexts explicitly.
  • Tightens readiness gates for device, service, refresh, and management work.
  • Expands readiness, cache-lifecycle, and Ensure logging tests.
File Description
overlord/​swfeats/​swfeatstest/​ensurelogchecker.go Supports renamed submanager Ensure methods.
overlord/​swfeats/​swfeatstest/​ensurelogchecker_test.go Tests EnsureAfterSeed logging.
overlord/​snapstate/​snapstate_update_test.go Updates auto-refresh references.
overlord/​snapstate/​snapstate_test.go Tests seeded work and transition gating.
overlord/​snapstate/​snapmgr.go Centralizes seed/context checks and post-seed dispatch.
overlord/​snapstate/​refreshhints.go Accepts a resolved device context.
overlord/​snapstate/​export_test.go Adapts test-facing Ensure helpers.
overlord/​snapstate/​catalogrefresh.go Moves seed/context prerequisites to the manager.
overlord/​snapstate/​autorefresh.go Renames the post-seed entry point.
overlord/​snapstate/​autorefresh_test.go Updates auto-refresh tests.
overlord/​servicestate/​servicemgr_test.go Tests missing post-seed context.
overlord/​devicestate/​export_test.go Adapts cloud-init test helper.
overlord/​devicestate/​devicestate_test.go Tests readiness and early-seed cache lifecycle.
overlord/​devicestate/​devicestate_cloudinit_test.go Tests pre-seed cloud-init gating.
overlord/​devicestate/​devicemgr.go Passes context through post-seed device helpers.
overlord/​devicemgmtstate/​devicemgmtmgr_test.go Tests pre-seed exchange gating.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread overlord/swfeats/swfeatstest/ensurelogchecker.go
@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

Tue Sep 22 09:33:05 UTC 2026
The following results are from: https://github.com/canonical/snapd/actions/runs/35626287134

Test Predictor Analysis

Preparing

Test Success %
openstack:ubuntu-core-24-64:tests/regression/lp-1667385:devmode 🟢 99.0%
openstack-ext:ubuntu-18.04-64:tests/nested/classic/activate-state 🔴 3.0%
openstack-ext:ubuntu-18.04-64:tests/nested/classic/hotplug 🔴 3.5%

Executing

Test Success %
openstack:ubuntu-20.04-64:tests/completion/indirect:files 🟢 99.0%
openstack:ubuntu-26.04-64:tests/main/snap-connectivity-check 🟢 99.0%
openstack:ubuntu-core-18-64:tests/core/gadget-update-pc 🟢 99.0%
openstack:ubuntu-core-24-64:tests/main/component-sideload 🟢 99.0%
openstack-ext:ubuntu-22.04-64:tests/nested/manual/seed-refresh-back-to-revision:refresh_kernel 🟢 99.0%
openstack-ext:ubuntu-22.04-64:tests/nested/manual/seed-refresh-back-to-revision:revert_gadget 🟢 99.0%
openstack-ext:ubuntu-24.04-64:tests/nested/manual/remodel-to-installed-kernel 🔴 0.5%
openstack-ext:ubuntu-24.04-64:tests/nested/manual/seed-refresh-back-to-revision:install_path_removed_app 🔴 16.7%
openstack-ext:ubuntu-26.04-64:tests/nested/core/core20-degraded 🔴 9.9%
openstack-ext:ubuntu-26.04-64:tests/nested/core/core20-factory-reset:fde 🔴 4.1%
openstack-ext:ubuntu-26.04-64:tests/nested/core/core20-gadget-reseal 🔴 7.1%
openstack-ext:ubuntu-26.04-64:tests/nested/core/core20-kernel-reseal 🔴 9.6%
openstack-ext:ubuntu-26.04-64:tests/nested/manual/fde-auth-support-on-hybrid:passphrase 🟡 63.8%
openstack-ext:ubuntu-26.04-64:tests/nested/manual/recovery-system:tested_and_default 🟢 99.0%
openstack-ext:ubuntu-26.04-64:tests/nested/manual/seed-refresh-no-space 🟢 99.0%
openstack-ext:ubuntu-26.04-64:tests/nested/manual/seed-refresh-rollback 🟢 99.0%

Restoring

Test Success %
openstack:ubuntu-core-18-64:tests/core/ 🟢 99.0%
openstack:ubuntu-core-18-64:tests/core/gadget-update-pc 🟢 99.0%
openstack-ext:ubuntu-22.04-64:tests/nested/manual/ 3 times 🟢 99.0%
openstack-ext:ubuntu-22.04-64:tests/nested/manual/muinstaller-real:seeded 🟡 68.5%
openstack-ext:ubuntu-22.04-64:tests/nested/manual/seed-refresh-back-to-revision:refresh_kernel 🟢 99.0%
openstack-ext:ubuntu-22.04-64:tests/nested/manual/seed-refresh-back-to-revision:revert_gadget 🟢 99.0%
openstack-ext:ubuntu-24.04-64:tests/nested/manual/ 3 times 🟢 96.5%
openstack-ext:ubuntu-24.04-64:tests/nested/manual/muinstaller-real:preseed 🟢 77.4%
openstack-ext:ubuntu-24.04-64:tests/nested/manual/remodel-to-installed-kernel 🔴 3.2%
openstack-ext:ubuntu-24.04-64:tests/nested/manual/seed-refresh-back-to-revision:install_path_removed_app 🔴 3.0%

Skipped tests from snapd-testing-skip

If you wish to have any of the below tests run in your PR, in your PR description, add 'unskip:' followed by a copy-and-pasted list of the below tests you wish to run (unskip plus test list must be valid yaml)

  • openstack:arch-linux-64:tests/main/interfaces-location-control
  • openstack:debian-12-64:tests/main/interfaces-location-control
  • openstack:ubuntu-20.04-64:tests/main/interfaces-location-control
  • openstack:ubuntu-24.04-64:tests/main/auto-refresh-retry
  • openstack:ubuntu-24.04-64:tests/main/i18n
  • openstack:ubuntu-24.04-64:tests/main/interfaces-location-control
  • openstack:ubuntu-24.04-64:tests/main/network-retry
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-flag-restart
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-integration-tests
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-prompt-restoration
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-smoke
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-snapd-startup
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-support
  • openstack:ubuntu-26.04-64:tests/main/interfaces-location-control
  • openstack:ubuntu-26.04-64:tests/main/interfaces-requests-activates-handlers

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The logging checker can validate the wrong method when a submanager defines multiple Ensure-prefixed methods.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
Resolved since last review (1)

Comment thread overlord/swfeats/swfeatstest/ensurelogchecker.go Outdated
Teach the checker to inspect child ensure calls from renamed submanager entry points such as EnsureAfterSeed, instead of assuming the entry point is always Ensure.

Preserve the exact receiver and method called by the parent when selecting a submanager declaration, so files with multiple Ensure-prefixed methods are checked correctly. Reuse the AST call traversal and replace textual cross-file method lookup with AST matching.
@pedronis
pedronis force-pushed the refactor-early-ensure-phase2-copilot branch from fec4e3f to 6625226 Compare September 21, 2026 16:32
@pedronis
pedronis requested a balanced review from Copilot September 21, 2026 16:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

It changes boot-time sequencing and device-context lifecycle across several core state managers, warranting final human validation.

Review effort: Balanced
Findings: None

Resolved since last review (1)

@pedronis
pedronis marked this pull request as ready for review September 22, 2026 07:03
@github-actions github-actions Bot removed the Run only one system Only runs spread tests on one system label Sep 22, 2026

@bboozzoo bboozzoo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

}
if !seeded {
return nil
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this and the others cleaned up nicely

// of snap files if the units are modified as services
// in the snap have a Requires= on them. Otherwise the
// services would be restarted.
// This is especially relevant for the snapd snap as if

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// This is especially relevant for the snapd snap as if

Comment on lines 1498 to 1499
// TODO refactor so the check for kernel type is not repeated
// in the installation case

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can go away now?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Run nested The PR also runs tests inluded in nested suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants