Hi Sandro,
It looks like to me that the bug is because, with newer kernels, the
correct path for the power supply plug should be:
/sys/class/power_supply/ADP0
At least, the above is what I have currently have in my laptop.
The current code for psutil is expecting /AC0 or /AC, but not /ADP0. If
I'm correct that this is just a new possible path, then the solution is
to simply add this new path as possible path in sensors_battery().
Though adding /ADP0 as possible path in psutil/_pslinux.py's
sensors_battery() breaks a bunch of tests, so the attached patch also
fixes them.
Please do apply the patch and upload the package ASAP, as we're close to
the freeze, and a few packages I know need psutil >= 6. We really want
python-psutil 7.0.0 to migrate to Testing soon. Knowing this, if nothing
is done, I'll be NMU-ing the attached fix in 2 days, which I would
prefer not to do, as I've seen multiple cases were you prefer to do this
yourself.
Last thing, when having my VPN on, I'm getting this error (with my
10.x.x.x IP annonymized):
________________________ TestSystemNetIfAddrs.test_ips
_________________________
self = <psutil.tests.test_linux.TestSystemNetIfAddrs testMethod=test_ips>
def test_ips(self):
for name, addrs in psutil.net_if_addrs().items():
for addr in addrs:
if addr.family == psutil.AF_LINK:
assert addr.address == get_mac_address(name)
elif addr.family == socket.AF_INET:
assert addr.address == get_ipv4_address(name)
assert addr.netmask == get_ipv4_netmask(name)
if addr.broadcast is not None:
assert addr.broadcast == get_ipv4_broadcast(name)
else:
> assert get_ipv4_broadcast(name) == '0.0.0.0'
E AssertionError: assert '10.x.x.255' == '0.0.0.0'
E
E - 0.0.0.0
E + 10.x.x.255
psutil/tests/test_linux.py:957: AssertionError
=========================== short test summary info
============================
FAILED psutil/tests/test_linux.py::TestSystemNetIfAddrs::test_ips -
Assertion...
So I would suggest disabling this test, as it doesn't feel like a
reliable test.
Hoping this patch is helpful, and that you can fix #1101865 quickly,
Cheers,
Thomas Goirand (zigo)
P.S: IMO, strong package ownership for python-psutil is wrong,
considering it has 136 reverse dependencies, and this package would be
better back in the Python team. Please consider pushing it back there.
Also, the old repository doesn't redirect to the new place: you should
have asked Salsa admins to move the package for you.
From cc7c9edbc9fe8d29e4028e652bbd231e5c5bfc7b Mon Sep 17 00:00:00 2001
From: Thomas Goirand <z...@debian.org>
Date: Sun, 6 Apr 2025 23:14:16 +0200
Subject: [PATCH] Add fix-power-plug-detection.patch (Closes: #1101865).
---
debian/changelog | 7 ++
debian/patches/fix-power-plug-detection.patch | 66 +++++++++++++++++++
debian/patches/series | 1 +
3 files changed, 74 insertions(+)
create mode 100644 debian/patches/fix-power-plug-detection.patch
diff --git a/debian/changelog b/debian/changelog
index d09c64a..f402722 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+python-psutil (7.0.0-1.1) unstable; urgency=medium
+
+ * Non-maintainer upload.
+ * Add fix-power-plug-detection.patch (Closes: #1101865).
+
+ -- Thomas Goirand <z...@debian.org> Sun, 06 Apr 2025 23:14:08 +0200
+
python-psutil (7.0.0-1) unstable; urgency=medium
* New upstream release; Closes: #1086528
diff --git a/debian/patches/fix-power-plug-detection.patch b/debian/patches/fix-power-plug-detection.patch
new file mode 100644
index 0000000..d4dcd93
--- /dev/null
+++ b/debian/patches/fix-power-plug-detection.patch
@@ -0,0 +1,66 @@
+Description: Fix power plug detection
+ It looks like newer kernel
+Author: Thomas Goirand <z...@debian.org>
+Bug-Debian: https://bugs.debian.org/1101865
+Forwarded: no
+Last-Update: 2025-04-06
+
+Index: python-psutil/psutil/_pslinux.py
+===================================================================
+--- python-psutil.orig/psutil/_pslinux.py
++++ python-psutil/psutil/_pslinux.py
+@@ -1505,6 +1505,7 @@ def sensors_battery():
+ # it's called "AC".
+ power_plugged = None
+ online = multi_bcat(
++ os.path.join(POWER_SUPPLY_PATH, "ADP0/online"),
+ os.path.join(POWER_SUPPLY_PATH, "AC0/online"),
+ os.path.join(POWER_SUPPLY_PATH, "AC/online"),
+ )
+Index: python-psutil/psutil/tests/test_linux.py
+===================================================================
+--- python-psutil.orig/psutil/tests/test_linux.py
++++ python-psutil/psutil/tests/test_linux.py
+@@ -1620,7 +1620,7 @@ class TestSensorsBattery(PsutilTestCase)
+ def test_emulate_power_not_plugged(self):
+ # Pretend the AC power cable is not connected.
+ def open_mock(name, *args, **kwargs):
+- if name.endswith(('AC0/online', 'AC/online')):
++ if name.endswith(('AC0/online', 'AC/online', 'ADP0/online')):
+ return io.BytesIO(b"0")
+ else:
+ return orig_open(name, *args, **kwargs)
+@@ -1634,7 +1634,7 @@ class TestSensorsBattery(PsutilTestCase)
+ # Same as above but pretend /AC0/online does not exist in which
+ # case code relies on /status file.
+ def open_mock(name, *args, **kwargs):
+- if name.endswith(('AC0/online', 'AC/online')):
++ if name.endswith(('AC0/online', 'AC/online', 'ADP0/online')):
+ raise FileNotFoundError
+ if name.endswith("/status"):
+ return io.StringIO("discharging")
+@@ -1651,6 +1651,7 @@ class TestSensorsBattery(PsutilTestCase)
+ # connected (assert fallback to False).
+ def open_mock(name, *args, **kwargs):
+ if name.startswith((
++ '/sys/class/power_supply/ADP0/online',
+ '/sys/class/power_supply/AC0/online',
+ '/sys/class/power_supply/AC/online',
+ )):
+@@ -1698,10 +1699,13 @@ class TestSensorsBattery(PsutilTestCase)
+ "/sys/class/power_supply/AC0/online", FileNotFoundError
+ ):
+ with mock_open_exception(
+- "/sys/class/power_supply/BAT0/status",
+- FileNotFoundError,
++ "/sys/class/power_supply/ADP0/online", FileNotFoundError
+ ):
+- assert psutil.sensors_battery().power_plugged is None
++ with mock_open_exception(
++ "/sys/class/power_supply/BAT0/status",
++ FileNotFoundError,
++ ):
++ assert psutil.sensors_battery().power_plugged is None
+
+
+ @pytest.mark.skipif(not LINUX, reason="LINUX only")
diff --git a/debian/patches/series b/debian/patches/series
index 01fc9f8..3f18c11 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1,2 +1,3 @@
0001-dont-depend-on-install-when-running-tests.patch
0002-pass-PYTHONPATH-to-the-test-runner.patch
+fix-power-plug-detection.patch
--
2.39.5