Skip to content

Conversation

jonathanspw
Copy link
Contributor

@jonathanspw jonathanspw commented Jul 9, 2025

Description

This patch makes the failure case of netplan status cleaner when systemd-networkd is not present. This is at least relevant to Fedora/EPEL use-cases.

Before:

[root@alma-9-srpm-test 1.el9]# netplan status
Failed to start systemd-networkd.service: Unit systemd-networkd.service not found.
Traceback (most recent call last):
  File "/usr/sbin/netplan", line 23, in <module>
    netplan.main()
  File "/usr/share/netplan/netplan_cli/cli/core.py", line 58, in main
    self.run_command()
  File "/usr/share/netplan/netplan_cli/cli/utils.py", line 332, in run_command
    self.func()
  File "/usr/share/netplan/netplan_cli/cli/commands/status.py", line 77, in run
    self.run_command()
  File "/usr/share/netplan/netplan_cli/cli/utils.py", line 332, in run_command
    self.func()
  File "/usr/share/netplan/netplan_cli/cli/commands/status.py", line 829, in command
    system_state = SystemConfigState(self.ifname, self.all)
  File "/usr/share/netplan/netplan_cli/cli/state.py", line 437, in __init__
    utils.systemctl('start', ['systemd-networkd.service'], True)
  File "/usr/share/netplan/netplan_cli/cli/utils.py", line 118, in systemctl
    subprocess.check_call(command)
  File "/usr/lib64/python3.9/subprocess.py", line 373, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['systemctl', 'start', 'systemd-networkd.service']' returned non-zero exit status 5.

After:

[root@alma-9-srpm-test 1.el9]# netplan status
systemd-networkd is required for 'netplan status' functionality

It also fixes a bug in the systemctl_is_installed def. systemctl is-enabled only returns 1/0 so it needs to use systemctl status instead to be able to use the 4 exit code to determine if a given service is installed.

Checklist

  • Runs make check successfully.
  • Retains code coverage (make check-coverage).
  • New/changed keys in YAML format are documented.
  • (Optional) Adds example YAML for new feature.
  • (Optional) Closes an open bug in Launchpad.

@Conan-Kudo
Copy link
Contributor

@slyon is there a reason netplan status doesn't work with NetworkManager?

@jonathanspw
Copy link
Contributor Author

Signed the CLA now.

@jonathanspw jonathanspw force-pushed the jonathanspw-patch-1 branch from f771011 to d20930a Compare July 10, 2025 16:25
Copy link
Collaborator

@slyon slyon left a comment

Choose a reason for hiding this comment

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

Thanks for this improvement!
I left two smaller inline comments below.

@Conan-Kudo IIRC systemd-networkd is not needed in principle for netplan status to function. But it's an implementation detail that we rely on systemd-networkd data heavily (in netplan_cli/cli/state.py:__init__()), besides iproute2 and NetworkManager data.

In theory, it could be changed to use only iproute2 data as ground truth and amend that with systemd-networkd and/or NetworkManager data - whatever is available. And I would be open about that when somebody wants to drive such change.

@jonathanspw jonathanspw force-pushed the jonathanspw-patch-1 branch from d20930a to e371ccd Compare July 29, 2025 12:55
`systemctl status` uses the 1-4 exit statuses as defined at https://www.freedesktop.org/software/systemd/man/latest/systemctl.html#Exit%20status

`systemctl is-enabled` only exits with 0/1
This has a clean and clear error message instead of a python stack trace if systemd-networkd is not present on the system.
@jonathanspw jonathanspw force-pushed the jonathanspw-patch-1 branch from e371ccd to df94b9e Compare July 29, 2025 13:03
@jonathanspw
Copy link
Contributor Author

Rebased PR against main.

Copy link
Collaborator

@slyon slyon left a comment

Choose a reason for hiding this comment

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

Thanks for addressing my remarks. LGTM!

@slyon slyon merged commit baba35f into canonical:main Jul 30, 2025
19 checks passed
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.

3 participants