def test_is_service_installed(self): """Test the is_service_installed function.""" with patch('pyanaconda.core.util.execWithCapture') as execute: execute.return_value = "fake.service enabled enabled" self.assertEqual(util.is_service_installed("fake"), True) execute.assert_called_once_with("systemctl", [ "list-unit-files", "fake.service", "--no-legend", "--root", "/mnt/sysroot" ]) with patch('pyanaconda.core.util.execWithCapture') as execute: execute.return_value = "fake.service enabled enabled" self.assertEqual( util.is_service_installed("fake.service", root="/"), True) execute.assert_called_once_with( "systemctl", ["list-unit-files", "fake.service", "--no-legend"]) with patch('pyanaconda.core.util.execWithCapture') as execute: execute.return_value = "" self.assertEqual(util.is_service_installed("fake", root="/"), False) execute.assert_called_once_with( "systemctl", ["list-unit-files", "fake.service", "--no-legend"])
def _enable_service(self): """Enable or disable the chrony service.""" if not util.is_service_installed(NTP_SERVICE, root=self._sysroot): log.debug("The NTP service is not installed.") return if self._ntp_enabled: util.enable_service(NTP_SERVICE, root=self._sysroot) else: util.disable_service(NTP_SERVICE, root=self._sysroot)
def check_initial_conditions(): """Can the Subscription service run?""" # Exclude the dir and image installations. if not conf.target.is_hardware: log.debug("subscription: Unsupported type of the installation target. " "The Subscription module won't be started.") sys.exit(1) # Exclude environments without the rhsm service. if not util.is_service_installed(RHSM_SYSTEMD_UNIT_NAME, root="/"): log.debug( "subscription: The required rhsm systemd service is not available. " "The Subscription module won't be started.") sys.exit(1)