Skip to content

Comments

fix: Consider "degraded" systemd state as booted#217

Merged
richm merged 3 commits intolinux-system-roles:mainfrom
martinpitt:systemd-check
May 14, 2025
Merged

fix: Consider "degraded" systemd state as booted#217
richm merged 3 commits intolinux-system-roles:mainfrom
martinpitt:systemd-check

Conversation

@martinpitt
Copy link
Collaborator

@martinpitt martinpitt commented May 14, 2025

This was a thinko in commit 7a7a323.


Plus some cleanups.

Summary by Sourcery

Fix systemd boot detection to treat 'degraded' state as booted, add a guard for missing systemd installation, and standardize Ansible 'when' checks.

Bug Fixes:

  • Treat 'degraded' systemd state as booted
  • Error out if systemd is not installed

Enhancements:

  • Use consistent 'is defined' syntax in Ansible 'when' conditions

This gives an early explicit error message rather than more cryptic ones
later on.

We already use this in other roles (tlog, logging), copied from there.
@sourcery-ai
Copy link

sourcery-ai bot commented May 14, 2025

Reviewer's Guide

Refactors Ansible systemd boot detection to treat 'degraded' state as booted, introduces a pre-check for systemd installation, and cleans up conditional syntax for readability.

File-Level Changes

Change Details Files
Refactored conditional syntax for systemd boot detection
  • Replaced 'not __cockpit_is_booted is defined' with '__cockpit_is_booted is not defined'
tasks/set_vars.yml
Added systemd installation requirement check
  • Introduced a failure task when systemctl is missing to ensure systemd is installed
tasks/set_vars.yml
Adjusted boot detection logic to treat 'degraded' state as booted
  • Modified __cockpit_is_booted fact to only exclude 'offline' state
tasks/set_vars.yml
Refactored conditional syntax for ostree detection
  • Replaced 'not __cockpit_is_ostree is defined' with '__cockpit_is_ostree is not defined'
tasks/set_vars.yml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @martinpitt - I've reviewed your changes - here's some feedback:

  • Rather than matching on an error string in __is_system_running.msg, use the command’s return code (e.g. when: __is_system_running.rc != 0) to detect missing systemd and avoid locale/version issues.
  • Normalize the systemctl is-system-running output (e.g. stdout|trim|lower) before comparison to guard against trailing whitespace or case differences.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Review instructions: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +18 to +21
- name: Require installed systemd
fail:
msg: "Error: This role requires systemd to be installed."
when: '"No such file or directory" in __is_system_running.msg | d("")'
Copy link

Choose a reason for hiding this comment

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

suggestion: Use explicit binary existence check or Ansible fact instead of parsing error message

Use the stat module to check for /usr/bin/systemctl or use the ansible_service_mgr fact instead of parsing error output. This avoids fragility from output changes or localization.

Suggested change
- name: Require installed systemd
fail:
msg: "Error: This role requires systemd to be installed."
when: '"No such file or directory" in __is_system_running.msg | d("")'
- name: Check for systemctl binary
stat:
path: /usr/bin/systemctl
register: systemctl_stat
- name: Require installed systemd
fail:
msg: "Error: This role requires systemd to be installed."
when: not systemctl_stat.stat.exists

@richm richm merged commit 46437e3 into linux-system-roles:main May 14, 2025
21 checks passed
@martinpitt martinpitt deleted the systemd-check branch May 14, 2025 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants