Skip to content

Fix the MQTT e2e broker on ubuntu-26.04 runners - #3029

Merged
J. Nick Koston (bdraco) merged 3 commits into
mainfrom
mqtt-e2e-broker-log
Nov 6, 2026
Merged

J. Nick Koston (bdraco) merged 3 commits into
mainfrom
mqtt-e2e-broker-log

Conversation

@bdraco

@bdraco J. Nick Koston (bdraco) commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

What does this implement/fix?

The MQTT discovery e2e jobs went red on main when ubuntu-latest moved to ubuntu-26.04: that image ships an AppArmor profile for mosquitto that only lets it read its own config paths, so the broker exits with Unable to open config file /tmp/pytest-of-runner/.../mosquitto.conf. The job now unloads that profile before the tests, and the harness keeps the broker's output so a startup failure says why.

- name: Let mosquitto read the test config
  run: if [ -e /etc/apparmor.d/mosquitto ]; then sudo apparmor_parser -R /etc/apparmor.d/mosquitto; fi
# before: stderr=DEVNULL, then a 10 s wait and "connection refused"
# after
if broker.returncode is not None:
    pytest.fail(f"mosquitto exited with {broker.returncode}:\n{log_path.read_text()}")

Related issue or feature (if applicable):

  • Red E2E MQTT discovery jobs on main after the ubuntu-26.04 runner switch

Types of changes

  • Bugfix (non-breaking change which fixes an issue) — bugfix
  • New feature (non-breaking change which adds functionality) — new-feature
  • Enhancement to an existing feature — enhancement
  • Breaking change (fix or feature that would cause existing functionality to not work as expected) — breaking-change
  • Refactor (no behaviour change) — refactor
  • Documentation only — docs
  • Maintenance / chore — maintenance
  • CI / workflow change — ci
  • Dependencies bump — dependencies

Frontend coordination

  • No frontend change needed
  • Companion frontend PR: esphome/device-builder-frontend#

Checklist

  • The code change is tested and works locally.
  • Pre-commit hooks pass (ruff, codespell, yaml/json/python checks).
  • Tests have been added or updated under tests/ where applicable.
  • components.index.json / definitions/components/*.json have not been hand-edited (regenerate via script/sync_components.py if a sync is needed).
  • Architecture-level changes are reflected in docs/ARCHITECTURE.md and/or docs/API.md.

@github-actions github-actions Bot added the ci Continuous integration / build / release tooling label Nov 6, 2026
@bdraco

Copy link
Copy Markdown
Member Author

ESPHome Bot (@esphbot) review

@codspeed

codspeed Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 28 untouched benchmarks
⏩ 1 skipped benchmark1


Comparing mqtt-e2e-broker-log (ecf8307) with main (2ff818f)

Open in CodSpeed

Footnotes

  1. 1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports. ↩

@bdraco J. Nick Koston (bdraco) changed the title Surface mosquitto's output when the MQTT e2e broker fails to start Fix the MQTT e2e broker on ubuntu-26.04 runners Nov 6, 2026
@bdraco

Copy link
Copy Markdown
Member Author

ESPHome Bot (@esphbot) review

@codecov

codecov Bot commented Nov 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.77%. Comparing base (2ff818f) to head (ecf8307).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #3029   +/-   ##
=======================================
  Coverage   99.77%   99.77%           
=======================================
  Files         300      300           
  Lines       26522    26522           
=======================================
  Hits        26461    26461           
  Misses         61       61           
Flag Coverage Δ
py3.12 99.73% <ø> (ø)
py3.14 99.62% <ø> (ø)

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@bdraco
J. Nick Koston (bdraco) marked this pull request as ready for review November 6, 2026 00:28
Copilot AI balanced review requested due to automatic review settings November 6, 2026 00:28

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.

🟢 Approval recommended

No active review issues remain for the CI and test-harness changes addressing MQTT discovery failures.

No open issues 🎉

What changed in this PR

This PR addresses MQTT discovery end-to-end test failures after ubuntu-latest moved to Ubuntu 26.04. Changes are limited to CI and the test harness; production behavior is unchanged.

Changes:

  • Unload Mosquitto’s AppArmor profile when present so the broker can read temporary test configurations.
  • Capture broker output, report early exits, and improve startup-timeout diagnostics and cleanup.
File Description
tests/​e2e/​slow/​mqtt/​conftest.py Preserve broker logs and improve startup-failure reporting and cleanup.
.github/​workflows/​test.yml Unload the AppArmor profile before running MQTT discovery tests.

Review effort: Balanced

@bdraco
J. Nick Koston (bdraco) merged commit b93a6d5 into main Nov 6, 2026
28 checks passed
@bdraco
J. Nick Koston (bdraco) deleted the mqtt-e2e-broker-log branch November 6, 2026 00:31
@esphbot

Copy link
Copy Markdown
Contributor

PR Review — Fix the MQTT e2e broker on ubuntu-26.04 runners

Small, well-targeted fix to the CI and test harness. Merge-ready, with one note on how robust the workflow step is.

The harness change is a clear improvement. Before, mosquitto's output went to DEVNULL and a broken config only showed up as a 10 s connection-refused timeout. Now stdout and stderr go to tmp_path/mosquitto.log, an early exit is reported right away with the return code and log, and the timeout path uses stop_broker (terminate plus wait) instead of an un-awaited terminate(). Opening the log in append mode keeps the output from both the first start and the restart in test_broker_restart_resubscribes_and_recovers. Closing the parent's handle after spawning is safe because the child holds its own copy. Mosquitto logs to stderr by default and the test configs don't set log_dest, so the log will actually have content. The AppArmor step is scoped to the MQTT job and the guard makes it a no-op on images without the profile.

  • Suggestion: apparmor_parser -R is guarded on the profile file existing, not on the profile being loaded. On a cache-apt-pkgs cache hit, install scripts probably don't run, so the file can exist without a loaded profile. -R would then exit non-zero and fail the job (unverified).


Checklist

  • No hardcoded secrets
  • Resource cleanup on error paths
  • Cross-platform CI commands on a single line
  • PR description matches diff

Automated review by Kōan (Claude) HEAD=ecf8307 45s

@esphbot ESPHome Bot (esphbot) 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.

Tip

No blocking issues found — ready to merge.

@github-actions github-actions Bot locked and limited conversation to collaborators Nov 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

ci Continuous integration / build / release tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants