From 88126ef33db2094b89fc17ad9e9a3962a9bb7d65 Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Mon, 19 Feb 2024 12:09:05 +0100 Subject: [PATCH 27/34] Move common Satellite Upgrade code to "common" This allows the re-use of the code in the el8toel9 upgrade. --- .../satellite_upgrade_services/actor.py | 35 +++++++++++++++++++ .../actors/satellite_upgrader/actor.py | 0 .../tests/unit_test_satellite_upgrader.py | 0 .../{el7toel8 => common}/models/satellite.py | 0 .../satellite_upgrade_data_migration/actor.py | 15 +------- 5 files changed, 36 insertions(+), 14 deletions(-) create mode 100644 repos/system_upgrade/common/actors/satellite_upgrade_services/actor.py rename repos/system_upgrade/{el7toel8 => common}/actors/satellite_upgrader/actor.py (100%) rename repos/system_upgrade/{el7toel8 => common}/actors/satellite_upgrader/tests/unit_test_satellite_upgrader.py (100%) rename repos/system_upgrade/{el7toel8 => common}/models/satellite.py (100%) diff --git a/repos/system_upgrade/common/actors/satellite_upgrade_services/actor.py b/repos/system_upgrade/common/actors/satellite_upgrade_services/actor.py new file mode 100644 index 00000000..3cda49a9 --- /dev/null +++ b/repos/system_upgrade/common/actors/satellite_upgrade_services/actor.py @@ -0,0 +1,35 @@ +import glob +import os + +from leapp.actors import Actor +from leapp.models import SatelliteFacts +from leapp.tags import ApplicationsPhaseTag, IPUWorkflowTag + +SYSTEMD_WANTS_BASE = '/etc/systemd/system/multi-user.target.wants/' +SERVICES_TO_DISABLE = ['dynflow-sidekiq@*', 'foreman', 'foreman-proxy', + 'httpd', 'postgresql', 'pulpcore-api', 'pulpcore-content', + 'pulpcore-worker@*', 'tomcat', 'redis'] + + +class SatelliteUpgradeServices(Actor): + """ + Reconfigure Satellite services + """ + + name = 'satellite_upgrade_services' + consumes = (SatelliteFacts,) + produces = () + tags = (IPUWorkflowTag, ApplicationsPhaseTag) + + 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 + 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)) diff --git a/repos/system_upgrade/el7toel8/actors/satellite_upgrader/actor.py b/repos/system_upgrade/common/actors/satellite_upgrader/actor.py similarity index 100% rename from repos/system_upgrade/el7toel8/actors/satellite_upgrader/actor.py rename to repos/system_upgrade/common/actors/satellite_upgrader/actor.py diff --git a/repos/system_upgrade/el7toel8/actors/satellite_upgrader/tests/unit_test_satellite_upgrader.py b/repos/system_upgrade/common/actors/satellite_upgrader/tests/unit_test_satellite_upgrader.py similarity index 100% rename from repos/system_upgrade/el7toel8/actors/satellite_upgrader/tests/unit_test_satellite_upgrader.py rename to repos/system_upgrade/common/actors/satellite_upgrader/tests/unit_test_satellite_upgrader.py diff --git a/repos/system_upgrade/el7toel8/models/satellite.py b/repos/system_upgrade/common/models/satellite.py similarity index 100% rename from repos/system_upgrade/el7toel8/models/satellite.py rename to repos/system_upgrade/common/models/satellite.py diff --git a/repos/system_upgrade/el7toel8/actors/satellite_upgrade_data_migration/actor.py b/repos/system_upgrade/el7toel8/actors/satellite_upgrade_data_migration/actor.py index 0cf66970..1dd52691 100644 --- a/repos/system_upgrade/el7toel8/actors/satellite_upgrade_data_migration/actor.py +++ b/repos/system_upgrade/el7toel8/actors/satellite_upgrade_data_migration/actor.py @@ -11,15 +11,10 @@ POSTGRESQL_SCL_DATA_PATH = '/var/opt/rh/rh-postgresql12/lib/pgsql/data/' POSTGRESQL_USER = 'postgres' POSTGRESQL_GROUP = 'postgres' -SYSTEMD_WANTS_BASE = '/etc/systemd/system/multi-user.target.wants/' -SERVICES_TO_DISABLE = ['dynflow-sidekiq@*', 'foreman', 'foreman-proxy', - 'httpd', 'postgresql', 'pulpcore-api', 'pulpcore-content', - 'pulpcore-worker@*', 'tomcat'] - class SatelliteUpgradeDataMigration(Actor): """ - Reconfigure Satellite services and migrate PostgreSQL data + Migrate Satellite PostgreSQL data """ name = 'satellite_upgrade_data_migration' @@ -32,14 +27,6 @@ class SatelliteUpgradeDataMigration(Actor): if not facts or not facts.has_foreman: return - # disable services, will be re-enabled by the installer - 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 Exception as e: # pylint: disable=broad-except - self.log.warning('Failed disabling service {}: {}'.format(service, e)) - if facts.postgresql.local_postgresql and os.path.exists(POSTGRESQL_SCL_DATA_PATH): # we can assume POSTGRESQL_DATA_PATH exists and is empty # move PostgreSQL data to the new home -- 2.42.0