Blame SOURCES/0030-Expose-plugin-unload-method-to-API-RhBug-2047251.patch

eb8139
From aa724a639a641943ecf39038fd694abc2037e66d Mon Sep 17 00:00:00 2001
eb8139
From: Jan Kolarik <jkolarik@redhat.com>
eb8139
Date: Mon, 22 Aug 2022 10:38:30 +0200
eb8139
Subject: [PATCH] Expose plugin unload method to API (RhBug:2047251)
eb8139
eb8139
= changelog =
eb8139
type: bugfix
eb8139
resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2047251
eb8139
---
eb8139
 dnf/base.py                | 5 +++++
eb8139
 dnf/plugin.py              | 1 +
eb8139
 doc/api_base.rst           | 4 ++++
eb8139
 tests/api/test_dnf_base.py | 7 +++++++
eb8139
 4 files changed, 17 insertions(+)
eb8139
eb8139
diff --git a/dnf/base.py b/dnf/base.py
eb8139
index e623d98e..4ddfae15 100644
eb8139
--- a/dnf/base.py
eb8139
+++ b/dnf/base.py
eb8139
@@ -316,6 +316,11 @@ class Base(object):
eb8139
         """Run plugins configure() method."""
eb8139
         self._plugins._run_config()
eb8139
 
eb8139
+    def unload_plugins(self):
eb8139
+        # :api
eb8139
+        """Run plugins unload() method."""
eb8139
+        self._plugins._unload()
eb8139
+
eb8139
     def update_cache(self, timer=False):
eb8139
         # :api
eb8139
 
eb8139
diff --git a/dnf/plugin.py b/dnf/plugin.py
eb8139
index 06066e79..87c1f08f 100644
eb8139
--- a/dnf/plugin.py
eb8139
+++ b/dnf/plugin.py
eb8139
@@ -164,6 +164,7 @@ class Plugins(object):
eb8139
         self._caller('transaction')
eb8139
 
eb8139
     def _unload(self):
eb8139
+        logger.debug(_('Plugins were unloaded'))
eb8139
         del sys.modules[DYNAMIC_PACKAGE]
eb8139
 
eb8139
     def unload_removed_plugins(self, transaction):
eb8139
diff --git a/doc/api_base.rst b/doc/api_base.rst
eb8139
index 03396b69..35cbeef5 100644
eb8139
--- a/doc/api_base.rst
eb8139
+++ b/doc/api_base.rst
eb8139
@@ -97,6 +97,10 @@
eb8139
 
eb8139
      Configure plugins by running their configure() method.
eb8139
 
eb8139
+  .. method:: unload_plugins()
eb8139
+
eb8139
+     Unload all plugins.
eb8139
+
eb8139
   .. method:: fill_sack([load_system_repo=True, load_available_repos=True])
eb8139
 
eb8139
     Setup the package sack. If `load_system_repo` is ``True``, load information about packages in the local RPMDB into the sack. Else no package is considered installed during dependency solving. If `load_available_repos` is ``True``, load information about packages from the available repositories into the sack.
eb8139
diff --git a/tests/api/test_dnf_base.py b/tests/api/test_dnf_base.py
eb8139
index 33598189..e84e272b 100644
eb8139
--- a/tests/api/test_dnf_base.py
eb8139
+++ b/tests/api/test_dnf_base.py
eb8139
@@ -95,6 +95,13 @@ class DnfBaseApiTest(TestCase):
eb8139
 
eb8139
         self.base.configure_plugins()
eb8139
 
eb8139
+    def test_unload_plugins(self):
eb8139
+        # Base.unload_plugins()
eb8139
+        self.assertHasAttr(self.base, "unload_plugins")
eb8139
+
eb8139
+        self.base.init_plugins()
eb8139
+        self.base.unload_plugins()
eb8139
+
eb8139
     def test_update_cache(self):
eb8139
         # Base.update_cache(self, timer=False)
eb8139
         self.assertHasAttr(self.base, "update_cache")
eb8139
-- 
eb8139
2.37.1
eb8139