From 544555abcdfc40267651f619e2aef5a5aa8cb9f0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pablo=20Su=C3=A1rez=20Hern=C3=A1ndez?=
 <psuarezhernandez@suse.com>
Date: Wed, 11 Aug 2021 11:44:54 +0100
Subject: [PATCH] Fix failing unit tests for systemd

---
 tests/unit/modules/test_systemd_service.py | 52 +++++++++++++---------
 1 file changed, 32 insertions(+), 20 deletions(-)

diff --git a/tests/unit/modules/test_systemd_service.py b/tests/unit/modules/test_systemd_service.py
index 752fb1d659..3e02b4ee23 100644
--- a/tests/unit/modules/test_systemd_service.py
+++ b/tests/unit/modules/test_systemd_service.py
@@ -189,24 +189,30 @@ class SystemdTestCase(TestCase, LoaderModuleMockMixin):
         mock = MagicMock(side_effect=lambda x: _SYSTEMCTL_STATUS[x])
 
         # systemd < 231
-        with patch.dict(systemd.__context__, {'salt.utils.systemd.version': 230}):
-            with patch.object(systemd, '_systemctl_status', mock):
-                self.assertTrue(systemd.available('sshd.service'))
-                self.assertFalse(systemd.available('foo.service'))
+        with patch.dict(systemd.__context__, {"salt.utils.systemd.version": 230}):
+            with patch.object(systemd, "_systemctl_status", mock), patch.object(
+                systemd, "offline", MagicMock(return_value=False)
+            ):
+                self.assertTrue(systemd.available("sshd.service"))
+                self.assertFalse(systemd.available("foo.service"))
 
         # systemd >= 231
         with patch.dict(systemd.__context__, {'salt.utils.systemd.version': 231}):
             with patch.dict(_SYSTEMCTL_STATUS, _SYSTEMCTL_STATUS_GTE_231):
-                with patch.object(systemd, '_systemctl_status', mock):
-                    self.assertTrue(systemd.available('sshd.service'))
-                    self.assertFalse(systemd.available('bar.service'))
+                with patch.object(systemd, "_systemctl_status", mock), patch.object(
+                    systemd, "offline", MagicMock(return_value=False)
+                ):
+                    self.assertTrue(systemd.available("sshd.service"))
+                    self.assertFalse(systemd.available("bar.service"))
 
         # systemd < 231 with retcode/output changes backported (e.g. RHEL 7.3)
         with patch.dict(systemd.__context__, {'salt.utils.systemd.version': 219}):
             with patch.dict(_SYSTEMCTL_STATUS, _SYSTEMCTL_STATUS_GTE_231):
-                with patch.object(systemd, '_systemctl_status', mock):
-                    self.assertTrue(systemd.available('sshd.service'))
-                    self.assertFalse(systemd.available('bar.service'))
+                with patch.object(systemd, "_systemctl_status", mock), patch.object(
+                    systemd, "offline", MagicMock(return_value=False)
+                ):
+                    self.assertTrue(systemd.available("sshd.service"))
+                    self.assertFalse(systemd.available("bar.service"))
 
     def test_missing(self):
         '''
@@ -215,24 +221,30 @@ class SystemdTestCase(TestCase, LoaderModuleMockMixin):
         mock = MagicMock(side_effect=lambda x: _SYSTEMCTL_STATUS[x])
 
         # systemd < 231
-        with patch.dict(systemd.__context__, {'salt.utils.systemd.version': 230}):
-            with patch.object(systemd, '_systemctl_status', mock):
-                self.assertFalse(systemd.missing('sshd.service'))
-                self.assertTrue(systemd.missing('foo.service'))
+        with patch.dict(systemd.__context__, {"salt.utils.systemd.version": 230}):
+            with patch.object(systemd, "_systemctl_status", mock), patch.object(
+                systemd, "offline", MagicMock(return_value=False)
+            ):
+                self.assertFalse(systemd.missing("sshd.service"))
+                self.assertTrue(systemd.missing("foo.service"))
 
         # systemd >= 231
         with patch.dict(systemd.__context__, {'salt.utils.systemd.version': 231}):
             with patch.dict(_SYSTEMCTL_STATUS, _SYSTEMCTL_STATUS_GTE_231):
-                with patch.object(systemd, '_systemctl_status', mock):
-                    self.assertFalse(systemd.missing('sshd.service'))
-                    self.assertTrue(systemd.missing('bar.service'))
+                with patch.object(systemd, "_systemctl_status", mock), patch.object(
+                    systemd, "offline", MagicMock(return_value=False)
+                ):
+                    self.assertFalse(systemd.missing("sshd.service"))
+                    self.assertTrue(systemd.missing("bar.service"))
 
         # systemd < 231 with retcode/output changes backported (e.g. RHEL 7.3)
         with patch.dict(systemd.__context__, {'salt.utils.systemd.version': 219}):
             with patch.dict(_SYSTEMCTL_STATUS, _SYSTEMCTL_STATUS_GTE_231):
-                with patch.object(systemd, '_systemctl_status', mock):
-                    self.assertFalse(systemd.missing('sshd.service'))
-                    self.assertTrue(systemd.missing('bar.service'))
+                with patch.object(systemd, "_systemctl_status", mock), patch.object(
+                    systemd, "offline", MagicMock(return_value=False)
+                ):
+                    self.assertFalse(systemd.missing("sshd.service"))
+                    self.assertTrue(systemd.missing("bar.service"))
 
     def test_show(self):
         '''
-- 
2.32.0


