forked from rpms/leapp-repository
91 lines
3.9 KiB
Diff
91 lines
3.9 KiB
Diff
|
From bad2fb2e446246dc80807b078c80e0c98fd72fe5 Mon Sep 17 00:00:00 2001
|
||
|
From: Evgeni Golov <evgeni@golov.de>
|
||
|
Date: Fri, 26 Apr 2024 09:08:58 +0200
|
||
|
Subject: [PATCH 30/34] Refactor satellite_upgrade_services to use
|
||
|
SystemdServicesTasks
|
||
|
|
||
|
We used to just delete the symlinks in /etc/systemd, but with the new
|
||
|
systemd actors this doesn't work anymore as they will restore the
|
||
|
pre-delete state because they by default aim at having source and
|
||
|
target systems match in terms of services. By using SystemdServicesTasks
|
||
|
we can explicitly turn those services off and inform all interested
|
||
|
parties about this.
|
||
|
---
|
||
|
.../satellite_upgrade_services/actor.py | 15 ++++++------
|
||
|
.../unit_test_satellite_upgrade_services.py | 24 +++++++++++++++++++
|
||
|
2 files changed, 31 insertions(+), 8 deletions(-)
|
||
|
create mode 100644 repos/system_upgrade/common/actors/satellite_upgrade_services/tests/unit_test_satellite_upgrade_services.py
|
||
|
|
||
|
diff --git a/repos/system_upgrade/common/actors/satellite_upgrade_services/actor.py b/repos/system_upgrade/common/actors/satellite_upgrade_services/actor.py
|
||
|
index 3cda49a9..d14edfb7 100644
|
||
|
--- a/repos/system_upgrade/common/actors/satellite_upgrade_services/actor.py
|
||
|
+++ b/repos/system_upgrade/common/actors/satellite_upgrade_services/actor.py
|
||
|
@@ -2,8 +2,8 @@ import glob
|
||
|
import os
|
||
|
|
||
|
from leapp.actors import Actor
|
||
|
-from leapp.models import SatelliteFacts
|
||
|
-from leapp.tags import ApplicationsPhaseTag, IPUWorkflowTag
|
||
|
+from leapp.models import SatelliteFacts, SystemdServicesTasks
|
||
|
+from leapp.tags import FactsPhaseTag, IPUWorkflowTag
|
||
|
|
||
|
SYSTEMD_WANTS_BASE = '/etc/systemd/system/multi-user.target.wants/'
|
||
|
SERVICES_TO_DISABLE = ['dynflow-sidekiq@*', 'foreman', 'foreman-proxy',
|
||
|
@@ -18,8 +18,8 @@ class SatelliteUpgradeServices(Actor):
|
||
|
|
||
|
name = 'satellite_upgrade_services'
|
||
|
consumes = (SatelliteFacts,)
|
||
|
- produces = ()
|
||
|
- tags = (IPUWorkflowTag, ApplicationsPhaseTag)
|
||
|
+ produces = (SystemdServicesTasks,)
|
||
|
+ tags = (IPUWorkflowTag, FactsPhaseTag)
|
||
|
|
||
|
def process(self):
|
||
|
facts = next(self.consume(SatelliteFacts), None)
|
||
|
@@ -27,9 +27,8 @@ class SatelliteUpgradeServices(Actor):
|
||
|
return
|
||
|
|
||
|
# disable services, will be re-enabled by the installer
|
||
|
+ services_to_disable = []
|
||
|
for service_name in SERVICES_TO_DISABLE:
|
||
|
for service in glob.glob(os.path.join(SYSTEMD_WANTS_BASE, '{}.service'.format(service_name))):
|
||
|
- try:
|
||
|
- os.unlink(service)
|
||
|
- except OSError as e:
|
||
|
- self.log.warning('Failed disabling service {}: {}'.format(service, e))
|
||
|
+ services_to_disable.append(os.path.basename(service))
|
||
|
+ self.produce(SystemdServicesTasks(to_disable=services_to_disable))
|
||
|
diff --git a/repos/system_upgrade/common/actors/satellite_upgrade_services/tests/unit_test_satellite_upgrade_services.py b/repos/system_upgrade/common/actors/satellite_upgrade_services/tests/unit_test_satellite_upgrade_services.py
|
||
|
new file mode 100644
|
||
|
index 00000000..f41621ab
|
||
|
--- /dev/null
|
||
|
+++ b/repos/system_upgrade/common/actors/satellite_upgrade_services/tests/unit_test_satellite_upgrade_services.py
|
||
|
@@ -0,0 +1,24 @@
|
||
|
+import glob
|
||
|
+
|
||
|
+from leapp.models import SatelliteFacts, SatellitePostgresqlFacts, SystemdServicesTasks
|
||
|
+
|
||
|
+
|
||
|
+def test_disable_httpd(monkeypatch, current_actor_context):
|
||
|
+ def mock_glob():
|
||
|
+ orig_glob = glob.glob
|
||
|
+
|
||
|
+ def mocked_glob(pathname):
|
||
|
+ if pathname == '/etc/systemd/system/multi-user.target.wants/httpd.service':
|
||
|
+ return [pathname]
|
||
|
+ return orig_glob(pathname)
|
||
|
+
|
||
|
+ return mocked_glob
|
||
|
+
|
||
|
+ monkeypatch.setattr('glob.glob', mock_glob())
|
||
|
+
|
||
|
+ current_actor_context.feed(SatelliteFacts(has_foreman=True,
|
||
|
+ postgresql=SatellitePostgresqlFacts(local_postgresql=False)))
|
||
|
+ current_actor_context.run()
|
||
|
+
|
||
|
+ message = current_actor_context.consume(SystemdServicesTasks)[0]
|
||
|
+ assert 'httpd.service' in message.to_disable
|
||
|
--
|
||
|
2.42.0
|
||
|
|