Skip to content

Commit 35dcc3c

Browse files
mcm001crschardt
andauthored
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 <[email protected]>
1 parent 9277960 commit 35dcc3c

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

photon-core/src/main/java/org/photonvision/common/networking/NetworkManager.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ public void initialize(boolean shouldManage) {
7373
return;
7474
}
7575

76+
if (!NetworkUtils.nmcliIsInstalled()) {
77+
logger.error("Cannot manage network without nmcli!");
78+
this.networkingIsDisabled = true;
79+
return;
80+
}
81+
7682
// Start tasks to monitor the network interface(s)
7783
var ethernetDevices = NetworkUtils.getAllWiredInterfaces();
7884
for (NMDeviceInfo deviceInfo : ethernetDevices) {

photon-core/src/main/java/org/photonvision/common/networking/NetworkUtils.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,18 @@ public NMDeviceInfo(String c, String d, String type) {
6666
}
6767
}
6868

69+
public static boolean nmcliIsInstalled() {
70+
var shell = new ShellExec(true, false);
71+
try {
72+
shell.executeBashCommand("nmcli --version");
73+
74+
return shell.getExitCode() == 0;
75+
} catch (IOException e) {
76+
logger.error("Could not query nmcli version", e);
77+
return false;
78+
}
79+
}
80+
6981
private static List<NMDeviceInfo> allInterfaces = new ArrayList<>();
7082
private static long lastReadTimestamp = 0;
7183

0 commit comments

Comments
 (0)