Verify that nmcli installed (#1929)

## Description

Previously, NetworkManager would happily go asking for networkmanager to
do things even if it wasn't installed. This should never be the case,
but we should bail out early if it is regardless IMO. This prevents logs
and the UI from looking suspiciously "working", if you ignore the exit
code. Up for debate if we actually need this feature.

## Meta

Merge checklist:
- [x] Pull Request title is [short, imperative
summary](https://cbea.ms/git-commit/) of proposed changes
- [x] The description documents the _what_ and _why_
- [ ] If this PR changes behavior or adds a feature, user documentation
is updated
- [ ] If this PR touches photon-serde, all messages have been
regenerated and hashes have not changed unexpectedly
- [ ] If this PR touches configuration, this is backwards compatible
with settings back to v2024.3.1
- [ ] If this PR touches pipeline settings or anything related to data
exchange, the frontend typing is updated
- [ ] If this PR addresses a bug, a regression test for it is added

---------

Co-authored-by: Craig Schardt <crschardt@fastem.com>
This commit is contained in:
Matt Morley
2025-08-09 19:40:55 -07:00
committed by GitHub
parent 9277960018
commit 35dcc3ce5a
2 changed files with 18 additions and 0 deletions

View File

@@ -73,6 +73,12 @@ public class NetworkManager {
return;
}
if (!NetworkUtils.nmcliIsInstalled()) {
logger.error("Cannot manage network without nmcli!");
this.networkingIsDisabled = true;
return;
}
// Start tasks to monitor the network interface(s)
var ethernetDevices = NetworkUtils.getAllWiredInterfaces();
for (NMDeviceInfo deviceInfo : ethernetDevices) {

View File

@@ -66,6 +66,18 @@ public class NetworkUtils {
}
}
public static boolean nmcliIsInstalled() {
var shell = new ShellExec(true, false);
try {
shell.executeBashCommand("nmcli --version");
return shell.getExitCode() == 0;
} catch (IOException e) {
logger.error("Could not query nmcli version", e);
return false;
}
}
private static List<NMDeviceInfo> allInterfaces = new ArrayList<>();
private static long lastReadTimestamp = 0;