Skip to content

Commit

Permalink
Refactor satellite_upgrade_services to use SystemdServicesTasks
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
evgeni authored and fernflower committed May 2, 2024
1 parent 720bb13 commit bad2fb2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
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',
Expand All @@ -18,18 +18,17 @@ 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)
if not facts or not facts.has_foreman:
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))
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit bad2fb2

Please sign in to comment.