forked from rpms/dnf-plugins-core
Backport patch " Add fix and test assertion"
Resolves: rhbz#2203100
This commit is contained in:
parent
1b834e68de
commit
607acc86a0
@ -0,0 +1,88 @@
|
||||
From 169a79922d7cb8968ffd378b1c98959185ee417f Mon Sep 17 00:00:00 2001
|
||||
From: Andy Baugh <andy@troglodyne.net>
|
||||
Date: Fri, 28 Apr 2023 10:52:16 -0500
|
||||
Subject: [PATCH] Add fix and test assertion for "no systemd unit exists for
|
||||
pid"
|
||||
|
||||
= changelog =
|
||||
msg: Catch exception in needs-restarting.py when no systemd unit exists for pid
|
||||
type: bugfix
|
||||
resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2122587
|
||||
related: None
|
||||
---
|
||||
plugins/needs_restarting.py | 18 ++++++++++++++----
|
||||
tests/test_needs_restarting.py | 15 +++++++++++++--
|
||||
2 files changed, 27 insertions(+), 6 deletions(-)
|
||||
|
||||
diff --git a/plugins/needs_restarting.py b/plugins/needs_restarting.py
|
||||
index 03831fa..8dbc965 100644
|
||||
--- a/plugins/needs_restarting.py
|
||||
+++ b/plugins/needs_restarting.py
|
||||
@@ -138,10 +138,20 @@ def get_service_dbus(pid):
|
||||
systemd_manager_object,
|
||||
'org.freedesktop.systemd1.Manager'
|
||||
)
|
||||
- service_proxy = bus.get_object(
|
||||
- 'org.freedesktop.systemd1',
|
||||
- systemd_manager_interface.GetUnitByPID(pid)
|
||||
- )
|
||||
+ service_proxy = None
|
||||
+ try:
|
||||
+ service_proxy = bus.get_object(
|
||||
+ 'org.freedesktop.systemd1',
|
||||
+ systemd_manager_interface.GetUnitByPID(pid)
|
||||
+ )
|
||||
+ except dbus.DBusException as e:
|
||||
+ # There is no unit for the pid. Usually error is 'NoUnitForPid'.
|
||||
+ # Considering what we do at the bottom (just return if not service)
|
||||
+ # Then there's really no reason to exit here on that exception.
|
||||
+ # Log what's happened then move on.
|
||||
+ msg = str(e)
|
||||
+ logger.warning("Failed to get systemd unit for PID {}: {}".format(pid, msg))
|
||||
+ return
|
||||
service_properties = dbus.Interface(
|
||||
service_proxy, dbus_interface="org.freedesktop.DBus.Properties")
|
||||
name = service_properties.Get(
|
||||
diff --git a/tests/test_needs_restarting.py b/tests/test_needs_restarting.py
|
||||
index 0ad70a5..7b629b4 100644
|
||||
--- a/tests/test_needs_restarting.py
|
||||
+++ b/tests/test_needs_restarting.py
|
||||
@@ -20,6 +20,8 @@ from __future__ import absolute_import
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
+from unittest.mock import patch, Mock
|
||||
+import dbus
|
||||
import needs_restarting
|
||||
import tests.support
|
||||
|
||||
@@ -29,8 +31,6 @@ MM_FILE = '7fc4e1168000-7fc4e1169000 rw-s 1096dd000 00:05 7749' \
|
||||
' /dev/dri/card0'
|
||||
SO_FILE = '30efe06000-30efe07000 r--p 00006000 08:02 139936' \
|
||||
' /usr/lib64/libSM.so.6.0.1'
|
||||
-
|
||||
-
|
||||
class NeedsRestartingTest(tests.support.TestCase):
|
||||
def test_smap2opened_file(self):
|
||||
func = needs_restarting.smap2opened_file
|
||||
@@ -46,6 +46,17 @@ class NeedsRestartingTest(tests.support.TestCase):
|
||||
self.assertTrue(ofile.deleted)
|
||||
self.assertEqual(ofile.name, '/usr/lib64/libXfont.so.1.4.1;5408628d')
|
||||
|
||||
+ def test_get_service_dbus_nounitforpid(self):
|
||||
+ func = needs_restarting.get_service_dbus
|
||||
+ # So, This is gonna look kinda screwy unless you are aware of what
|
||||
+ # this proxies interface is actually doing. The GetUnitByPid function
|
||||
+ # is normally "dynamically" defined by the get_dbus_method at runtime.
|
||||
+ # As such there's no actual way to mock it out in any meaningful way
|
||||
+ # without create=True.
|
||||
+ with patch( "dbus.proxies.Interface.GetUnitByPID", create=True, side_effect=dbus.DBusException('org.freedesktop.systemd1.NoUnitForPID: PID 1234 does not belong to any loaded unit.') ), \
|
||||
+ patch( "dbus.SystemBus", return_value=Mock(spec=dbus.Bus) ), \
|
||||
+ patch( "dbus.bus.BusConnection.__new__", side_effect=dbus.DBusException("Never should hit this exception if mock above works")):
|
||||
+ self.assertIsNone(func(1234))
|
||||
|
||||
class OpenedFileTest(tests.support.TestCase):
|
||||
def test_presumed_name(self):
|
||||
--
|
||||
2.40.1
|
||||
|
@ -34,7 +34,7 @@
|
||||
|
||||
Name: dnf-plugins-core
|
||||
Version: 4.3.0
|
||||
Release: 7%{?dist}
|
||||
Release: 8%{?dist}
|
||||
Summary: Core Plugins for DNF
|
||||
License: GPLv2+
|
||||
URL: https://github.com/rpm-software-management/dnf-plugins-core
|
||||
@ -47,6 +47,7 @@ Patch5: 0005-Update-translations.patch
|
||||
Patch6: 0006-Fix-boot-time-derivation-for-systems-with-no-rtc.patch
|
||||
Patch7: 0007-system-upgrade-Add-poweroff-option-to-reboot-subcomm.patch
|
||||
Patch8: 0008-Doc-update-for-reposync-RhBug-2132383-2182004.patch
|
||||
Patch9: 0009-Add-fix-and-test-assertion-for-no-systemd-unit-exist.patch
|
||||
|
||||
BuildArch: noarch
|
||||
BuildRequires: cmake
|
||||
@ -794,6 +795,9 @@ ln -sf %{_mandir}/man1/%{yum_utils_subpackage_name}.1.gz %{buildroot}%{_mandir}/
|
||||
%endif
|
||||
|
||||
%changelog
|
||||
* Wed May 31 2023 Nicola Sella <nsella@redhat.com> - 4.3.0-8
|
||||
- Add fix and test assertion for "no systemd unit exists for pid"
|
||||
|
||||
* Wed May 17 2023 Jaroslav Rohel <jrohel@redhat.com> - 4.3.0-7
|
||||
- Remove patch: "reposync: Implement --safe-write-path option (RhBug:1898089,2203766)" (RhBug:2207946)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user