Skip to content

Commit

Permalink
Add patched python-psutil
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleGospo committed Jan 4, 2024
1 parent 60f227d commit 8bc7b53
Show file tree
Hide file tree
Showing 4 changed files with 621 additions and 0 deletions.
34 changes: 34 additions & 0 deletions staging/python-psutil/2305.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
From 3c9a0c52f3eee3bdb1c058ad19c515cf9f0ff442 Mon Sep 17 00:00:00 2001
From: Marco Rodolfi <[email protected]>
Date: Wed, 13 Sep 2023 11:15:25 +0200
Subject: [PATCH] Exclude external batteries from sensors_battery

The single check for battery in power_supply was causing sometimes to grab external device battery statuses since they have the form of hid_<mac>_battery, which match the bat filter.

However they do not have an ACPI path to the system itself.

This takes into account that detail and properly exclude them from being included as an internal battery.
---
psutil/_pslinux.py | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py
index 0f102cbfa..e0221ede4 100644
--- a/psutil/_pslinux.py
+++ b/psutil/_pslinux.py
@@ -1471,9 +1471,13 @@ def multi_bcat(*paths):
except ValueError:
return ret.strip()
return None
+ # The final check verifies if the reported battery is internal
+ # since the existence of the device/path file represent an available
+ # ACPI path to the battery itself.
+ bats = [x for x in os.listdir(POWER_SUPPLY_PATH) if x.startswith('BAT')
+ or 'battery' in x.lower() and
+ os.path.exists(os.path.join(POWER_SUPPLY_PATH, x, "device/path"))]

- bats = [x for x in os.listdir(POWER_SUPPLY_PATH) if x.startswith('BAT') or
- 'battery' in x.lower()]
if not bats:
return None
# Get the first available battery. Usually this is "BAT0", except
169 changes: 169 additions & 0 deletions staging/python-psutil/python-psutil-skip-tests-in-mock.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
diff -uNr psutil-release-5.9.5.orig/psutil/tests/test_contracts.py psutil-release-5.9.5/psutil/tests/test_contracts.py
--- psutil-release-5.9.5.orig/psutil/tests/test_contracts.py 2023-08-04 06:14:41.080097504 -0500
+++ psutil-release-5.9.5/psutil/tests/test_contracts.py 2023-08-04 06:36:02.844609234 -0500
@@ -425,6 +425,7 @@
ls.append(proc_info(pid))
return ls

+ @unittest.skip("Unreliable in mock")
def test_all(self):
failures = []
for info in self.iter_proc_info():
diff -uNr psutil-release-5.9.5.orig/psutil/tests/test_linux.py psutil-release-5.9.5/psutil/tests/test_linux.py
--- psutil-release-5.9.5.orig/psutil/tests/test_linux.py 2023-08-04 06:14:41.080097504 -0500
+++ psutil-release-5.9.5/psutil/tests/test_linux.py 2023-08-04 08:32:44.666822057 -0500
@@ -257,7 +257,7 @@
psutil_value = psutil.virtual_memory().total
self.assertEqual(cli_value, psutil_value)

- @retry_on_failure()
+ @unittest.skip("Unreliable on mock")
def test_used(self):
# Older versions of procps used slab memory to calculate used memory.
# This got changed in:
@@ -314,6 +314,7 @@
vmstat_value, psutil_value, delta=TOLERANCE_SYS_MEM)

@retry_on_failure()
+ @unittest.skip("Unreliable in mock")
def test_used(self):
# Older versions of procps used slab memory to calculate used memory.
# This got changed in:
@@ -691,8 +692,7 @@
@unittest.skipIf(not LINUX, "LINUX only")
class TestSystemCPUCountLogical(PsutilTestCase):

- @unittest.skipIf(not os.path.exists("/sys/devices/system/cpu/online"),
- "/sys/devices/system/cpu/online does not exist")
+ @unittest.skip("Unreliable on mock")
def test_against_sysdev_cpu_online(self):
with open("/sys/devices/system/cpu/online") as f:
value = f.read().strip()
@@ -700,14 +700,13 @@
value = int(value.split('-')[1]) + 1
self.assertEqual(psutil.cpu_count(), value)

- @unittest.skipIf(not os.path.exists("/sys/devices/system/cpu"),
- "/sys/devices/system/cpu does not exist")
+ @unittest.skip("Unreliable in mock on ppc64le")
def test_against_sysdev_cpu_num(self):
ls = os.listdir("/sys/devices/system/cpu")
count = len([x for x in ls if re.search(r"cpu\d+$", x) is not None])
self.assertEqual(psutil.cpu_count(), count)

- @unittest.skipIf(not which("nproc"), "nproc utility not available")
+ @unittest.skip("Unreliable on mock")
def test_against_nproc(self):
num = int(sh("nproc --all"))
self.assertEqual(psutil.cpu_count(logical=True), num)
@@ -752,7 +751,7 @@
assert m.called


-@unittest.skipIf(not LINUX, "LINUX only")
+@unittest.skip("Unreliable on mock")
class TestSystemCPUCountCores(PsutilTestCase):

@unittest.skipIf(not which("lscpu"), "lscpu utility not available")
@@ -784,7 +783,7 @@
@unittest.skipIf(not LINUX, "LINUX only")
class TestSystemCPUFrequency(PsutilTestCase):

- @unittest.skipIf(not HAS_CPU_FREQ, "not supported")
+ @unittest.skip("Unreliable on mock")
def test_emulate_use_second_file(self):
# https://github.com/giampaolo/psutil/issues/981
def path_exists_mock(path):
@@ -798,7 +797,7 @@
create=True):
assert psutil.cpu_freq()

- @unittest.skipIf(not HAS_CPU_FREQ, "not supported")
+ @unittest.skip("Unreliable on mock")
def test_emulate_use_cpuinfo(self):
# Emulate a case where /sys/devices/system/cpu/cpufreq* does not
# exist and /proc/cpuinfo is used instead.
@@ -923,7 +922,7 @@
self.assertEqual(freq.current, 200)


-@unittest.skipIf(not LINUX, "LINUX only")
+@unittest.skip("Unreliable on mock")
class TestSystemCPUStats(PsutilTestCase):

def test_ctx_switches(self):
@@ -956,7 +955,7 @@
# =====================================================================


-@unittest.skipIf(not LINUX, "LINUX only")
+@unittest.skip("Unreliable on mock")
class TestSystemNetIfAddrs(PsutilTestCase):

def test_ips(self):
@@ -1350,7 +1349,7 @@
self.assertRaises(FileNotFoundError, finder.ask_sys_dev_block)
finder.ask_sys_class_block()

- @unittest.skipIf(GITHUB_ACTIONS, "unsupported on GITHUB_ACTIONS")
+ @unittest.skip("Unreliable on mock")
def test_comparisons(self):
finder = RootFsDeviceFinder()
self.assertIsNotNone(finder.find())
@@ -1373,11 +1372,13 @@

@unittest.skipIf(not which("findmnt"), "findmnt utility not available")
@unittest.skipIf(GITHUB_ACTIONS, "unsupported on GITHUB_ACTIONS")
+ @unittest.skip("Unreliable on mock")
def test_against_findmnt(self):
psutil_value = RootFsDeviceFinder().find()
findmnt_value = sh("findmnt -o SOURCE -rn /")
self.assertEqual(psutil_value, findmnt_value)

+ @unittest.skip("Unreliable on mock")
def test_disk_partitions_mocked(self):
with mock.patch(
'psutil._pslinux.cext.disk_partitions',
@@ -1513,6 +1514,7 @@
psutil._pslinux.boot_time)
assert m.called

+ @unittest.skip("Unreliable on mock")
def test_users_mocked(self):
# Make sure ':0' and ':0.0' (returned by C ext) are converted
# to 'localhost'.
@@ -2275,6 +2277,7 @@
value = self.read_status_file("nonvoluntary_ctxt_switches:")
self.assertEqual(self.proc.num_ctx_switches().involuntary, value)

+ @unittest.skip("Unreliable on mock")
def test_cpu_affinity(self):
value = self.read_status_file("Cpus_allowed_list:")
if '-' in str(value):
diff -uNr psutil-release-5.9.5.orig/psutil/tests/test_system.py psutil-release-5.9.5/psutil/tests/test_system.py
--- psutil-release-5.9.5.orig/psutil/tests/test_system.py 2023-08-04 06:14:41.080097504 -0500
+++ psutil-release-5.9.5/psutil/tests/test_system.py 2023-08-04 08:18:37.164817563 -0500
@@ -512,10 +512,7 @@
if not AIX and name in ('ctx_switches', 'interrupts'):
self.assertGreater(value, 0)

- # TODO: remove this once 1892 is fixed
- @unittest.skipIf(MACOS and platform.machine() == 'arm64',
- "skipped due to #1892")
- @unittest.skipIf(not HAS_CPU_FREQ, "not supported")
+ @unittest.skip("Unreliable on mock")
def test_cpu_freq(self):
def check_ls(ls):
for nt in ls:
diff -uNr psutil-release-5.9.5.orig/psutil/tests/test_testutils.py psutil-release-5.9.5/psutil/tests/test_testutils.py
--- psutil-release-5.9.5.orig/psutil/tests/test_testutils.py 2023-08-04 06:14:41.080097504 -0500
+++ psutil-release-5.9.5/psutil/tests/test_testutils.py 2023-08-04 06:35:41.421931668 -0500
@@ -370,7 +370,7 @@
self.assertRaises(ValueError, self.execute, lambda: 0, retries=-1)

@retry_on_failure()
- @unittest.skipIf(CI_TESTING, "skipped on CI")
+ @unittest.skip("Unreliable in mock")
@unittest.skipIf(COVERAGE, "skipped during test coverage")
def test_leak_mem(self):
ls = []
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
diff --git a/psutil/tests/test_system.py b/psutil/tests/test_system.py
index 3b787ee..db22245 100755
--- a/psutil/tests/test_system.py
+++ b/psutil/tests/test_system.py
@@ -346,7 +346,7 @@ class TestCpuAPIs(PsutilTestCase):
self.assertIsInstance(cp_time, float)
self.assertGreaterEqual(cp_time, 0.0)
total += cp_time
- self.assertEqual(total, sum(times))
+ self.assertAlmostEqual(total, sum(times))
str(times)
# CPU times are always supposed to increase over time
# or at least remain the same and that's because time
@@ -385,7 +385,7 @@ class TestCpuAPIs(PsutilTestCase):
self.assertIsInstance(cp_time, float)
self.assertGreaterEqual(cp_time, 0.0)
total += cp_time
- self.assertEqual(total, sum(times))
+ self.assertAlmostEqual(total, sum(times))
str(times)
self.assertEqual(len(psutil.cpu_times(percpu=True)[0]),
len(psutil.cpu_times(percpu=False)))
Loading

0 comments on commit 8bc7b53

Please sign in to comment.