From 9a3f7d44c4803ed35598267656ba6aaaf9c8f144 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Wed, 9 Oct 2024 16:57:23 +0200 Subject: [PATCH] statd: allow ethtool rmon counters readout to fail In e373398 we restored statd suport for checking for faults in yanger at runtime. This in turn broke CLI "show interfaces" support on the little NanoPi R2S because ethtool cannot read counters in JSON format on it. This patch catches the subprocess exception, allowing this particular call to ethtool to fail with empty result. The only difference from before e373398 is that run_json_cmd() will log an error that ethtool failed, for every interface it is called on. Signed-off-by: Joachim Wiberg --- src/statd/python/yanger/yanger.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/statd/python/yanger/yanger.py b/src/statd/python/yanger/yanger.py index 236d0e7e..0a8f325d 100755 --- a/src/statd/python/yanger/yanger.py +++ b/src/statd/python/yanger/yanger.py @@ -726,12 +726,15 @@ def add_ip_addr(ifname, iface_in, iface_out): def add_ethtool_groups(ifname, iface_out): - """Fetch interface counters from kernel""" - - data = run_json_cmd(['ethtool', '--json', '-S', ifname, '--all-groups'], - f"ethtool-groups-{ifname}.json") - if len(data) != 1: - logger.warning(f"{ifname}: no counters available, skipping.") + """Fetch interface counters from kernel (need new JSON format!)""" + cmd = ['ethtool', '--json', '-S', ifname, '--all-groups'] + try: + data = run_json_cmd(cmd, f"ethtool-groups-{ifname}.json") + if len(data) != 1: + logger.warning("%s: no counters available, skipping.", ifname) + return + except subprocess.CalledProcessError: + # Allow comand to fail, not all NICs support --json yet return iface_in = data[0]