Replace dependency on python-ethtool with built-in functionality

Resolves: rhbz#2123751
Signed-off-by: John Kacur <jkacur@redhat.com>
This commit is contained in:
John Kacur 2022-09-30 12:40:06 -04:00
parent 63c3e5c44f
commit b21e4dca3f
2 changed files with 111 additions and 1 deletions

View File

@ -0,0 +1,104 @@
From f2a28b05264fa9557192b73a1b888756748930ac Mon Sep 17 00:00:00 2001
From: John Kacur <jkacur@redhat.com>
Date: Tue, 27 Sep 2022 12:59:54 -0400
Subject: [PATCH] tuna: Replace python_ethtool with builtin funtionality
This patch replaces the dependency on python_ethtool with some
simplified functions to achieve the same result.
Reviewed-by: Federico Pellegrin <fede@evolware.org>
- return 'tun' only if tun_flags exists
Signed-off-by: John Kacur <jkacur@redhat.com>
---
tuna-cmd.py | 2 +-
tuna/gui/irqview.py | 2 +-
tuna/new_eth.py | 37 +++++++++++++++++++++++++++++++++++++
tuna/tuna.py | 2 +-
4 files changed, 40 insertions(+), 3 deletions(-)
create mode 100755 tuna/new_eth.py
diff --git a/tuna-cmd.py b/tuna-cmd.py
index 9a3d3f32398b..b13b25b8a801 100755
--- a/tuna-cmd.py
+++ b/tuna-cmd.py
@@ -26,7 +26,7 @@ import fnmatch
import gettext
import locale
from functools import reduce
-import ethtool
+import tuna.new_eth as ethtool
import tuna.tuna_sched as tuna_sched
import procfs
from tuna import tuna, sysfs
diff --git a/tuna/gui/irqview.py b/tuna/gui/irqview.py
index 35fc3fd0b0ca..5143d6dc0df5 100755
--- a/tuna/gui/irqview.py
+++ b/tuna/gui/irqview.py
@@ -7,7 +7,7 @@ from gi.repository import Gtk
from gi.repository import GObject
import os
from functools import reduce
-import ethtool
+import tuna.new_eth as ethtool
import tuna.tuna_sched as tuna_sched
import gi
diff --git a/tuna/new_eth.py b/tuna/new_eth.py
new file mode 100755
index 000000000000..98f9179d5695
--- /dev/null
+++ b/tuna/new_eth.py
@@ -0,0 +1,37 @@
+# Copyright (C) 2022 John Kacur
+""" A few functions similar to ethtool """
+import os
+import socket
+
+def get_active_devices():
+ """ return a list of network devices """
+ ret = []
+
+ for device in socket.if_nameindex():
+ ret.append(device[1])
+
+ return ret
+
+def get_module(intf):
+ """ return the kernel module for the given network interface """
+ if intf == 'lo':
+ return ""
+ myp = f'/sys/class/net/{intf}/device/driver'
+ if os.path.exists(myp):
+ return os.path.basename(os.readlink(myp))
+ if os.path.exists(f'/sys/class/net/{intf}/bridge'):
+ return 'bridge'
+ if os.path.exists(f'/sys/class/net/{intf}/tun_flags'):
+ return 'tun'
+ return ""
+
+if __name__ == "__main__":
+ nics = get_active_devices()
+ print(f'nics = {nics}')
+
+ for intf in nics:
+ driver = get_module(intf)
+ if driver:
+ print(f'{intf}, {driver}')
+ else:
+ print(f'{intf}')
diff --git a/tuna/tuna.py b/tuna/tuna.py
index 30a5a570c9d4..43adb84079e4 100755
--- a/tuna/tuna.py
+++ b/tuna/tuna.py
@@ -9,7 +9,7 @@ import sys
import shlex
import fnmatch
import platform
-import ethtool
+import tuna.new_eth as ethtool
import procfs
from procfs import utilist
from tuna import help
--
2.37.3

View File

@ -1,6 +1,6 @@
Name: tuna
Version: 0.18
Release: 2%{?dist}
Release: 3%{?dist}
License: GPLv2
Summary: Application tuning GUI & command line utility
URL: https://git.kernel.org/pub/scm/utils/tuna/tuna.git
@ -14,6 +14,7 @@ Requires: python3-linux-procfs >= 0.6
# Requires: python-inet_diag
# Patches
Patch1: tuna-Replace-python_ethtool-with-builtin-funtionalit.patch
%description
Provides interface for changing scheduler and IRQ tunables, at whole CPU and at
@ -26,6 +27,7 @@ installed.
%prep
%setup -q
%patch1 -p1
%build
%py3_build
@ -67,6 +69,10 @@ done
%{_datadir}/polkit-1/actions/org.tuna.policy
%changelog
* Fri Sep 30 2022 John Kacur <jkacur@redhat.com> - 0.18-3
- Replace dependency on python-ethtool with built-in functionality
Resolves: rhbz#2123751
* Wed Jun 29 2022 Leah Leshchinsky <lleshchi@redhat.com> - 0.18-2
- Delete patches
Resolves: rhbz#2068629