Skip to content

Commit

Permalink
refactor satellite_upgrade_services to use SystemdServicesTasks
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeni committed Apr 26, 2024
1 parent 7ee9f52 commit d074f3c
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 d074f3c

Please sign in to comment.