Skip to content

Commit

Permalink
add el8toel9 upgrade facts for Satellite
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeni committed Feb 19, 2024
1 parent 7de9b0e commit 68ca385
Show file tree
Hide file tree
Showing 2 changed files with 209 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
from leapp.actors import Actor
from leapp.libraries.common.config import architecture
from leapp.libraries.common.rpms import has_package
from leapp.models import (
InstalledRPM,
RepositoriesSetupTasks,
RpmTransactionTasks,
SatelliteFacts,
SatellitePostgresqlFacts
)
from leapp.tags import FactsPhaseTag, IPUWorkflowTag

SATELLITE_VERSION = '6.99'


class SatelliteUpgradeFacts(Actor):
"""
Report which Satellite packages require updates and how to handle PostgreSQL data
"""

name = 'satellite_upgrade_facts'
consumes = (InstalledRPM, )
produces = (RepositoriesSetupTasks, RpmTransactionTasks, SatelliteFacts)
tags = (IPUWorkflowTag, FactsPhaseTag)

def process(self):
if not architecture.matches_architecture(architecture.ARCH_X86_64):
return

has_foreman = has_package(InstalledRPM, 'foreman') or has_package(InstalledRPM, 'foreman-proxy')
if not has_foreman:
return

local_postgresql = has_package(InstalledRPM, 'postgresql-server')
postgresql_contrib = has_package(InstalledRPM, 'postgresql-contrib')
postgresql_evr = has_package(InstalledRPM, 'postgresql-evr')

to_remove = []
to_install = ['rubygem-foreman_maintain']

if has_package(InstalledRPM, 'katello'):
to_install.append('katello')

for rpm_pkgs in self.consume(InstalledRPM):
for pkg in rpm_pkgs.items:
if (pkg.name.startswith('rubygem-hammer') or pkg.name.startswith('rubygem-foreman')
or pkg.name.startswith('rubygem-katello')
or pkg.name.startswith('rubygem-smart_proxy')):
to_install.append(pkg.name)
elif pkg.name.startswith('python3.11-pulp'):
to_install.append(pkg.name)
elif pkg.name.startswith('foreman-installer') or pkg.name.startswith('satellite-installer'):
to_install.append(pkg.name)

on_same_partition = True
bytes_required = None
bytes_available = None
old_pgsql_data = False

if local_postgresql:
to_install.extend(['postgresql', 'postgresql-server'])
if postgresql_contrib:
to_install.append('postgresql-contrib')
if postgresql_evr:
to_install.append('postgresql-evr')

self.produce(SatelliteFacts(
has_foreman=has_foreman,
installer_has_systemchecks=False,
postgresql=SatellitePostgresqlFacts(
local_postgresql=local_postgresql,
old_var_lib_pgsql_data=old_pgsql_data,
same_partition=on_same_partition,
space_required=bytes_required,
space_available=bytes_available,
),
))

repositories_to_enable = [f'satellite-maintenance-{SATELLITE_VERSION}-for-rhel-9-x86_64-rpms']
if has_package(InstalledRPM, 'satellite'):
repositories_to_enable.append(f'satellite-{SATELLITE_VERSION}-for-rhel-9-x86_64-rpms')
to_install.append('satellite')
elif has_package(InstalledRPM, 'satellite-capsule'):
repositories_to_enable.append(f'satellite-capsule-{SATELLITE_VERSION}-for-rhel-9-x86_64-rpms')
to_install.append('satellite-capsule')

self.produce(RpmTransactionTasks(
to_remove=to_remove,
to_install=to_install,
)
)

self.produce(RepositoriesSetupTasks(to_enable=repositories_to_enable))
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
from leapp.libraries.common.config import mock_configs
from leapp.models import InstalledRPM, RepositoriesSetupTasks, RPM, RpmTransactionTasks, SatelliteFacts

RH_PACKAGER = 'Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla>'


def fake_package(pkg_name):
return RPM(name=pkg_name, version='0.1', release='1.sm01', epoch='1', packager=RH_PACKAGER, arch='noarch',
pgpsig='RSA/SHA256, Mon 01 Jan 1970 00:00:00 AM -03, Key ID 199e2f91fd431d51')


FOREMAN_RPM = fake_package('foreman')
FOREMAN_PROXY_RPM = fake_package('foreman-proxy')
KATELLO_INSTALLER_RPM = fake_package('foreman-installer-katello')
KATELLO_RPM = fake_package('katello')
POSTGRESQL_RPM = fake_package('postgresql-server')
SATELLITE_RPM = fake_package('satellite')
SATELLITE_CAPSULE_RPM = fake_package('satellite-capsule')

SATELLITE_VERSION = '6.99'


def test_no_satellite_present(current_actor_context):
current_actor_context.feed(InstalledRPM(items=[]))
current_actor_context.run(config_model=mock_configs.CONFIG)
message = current_actor_context.consume(SatelliteFacts)
assert not message


def test_satellite_present(current_actor_context):
current_actor_context.feed(InstalledRPM(items=[FOREMAN_RPM]))
current_actor_context.run(config_model=mock_configs.CONFIG)
message = current_actor_context.consume(SatelliteFacts)[0]
assert message.has_foreman


def test_wrong_arch(current_actor_context):
current_actor_context.feed(InstalledRPM(items=[FOREMAN_RPM]))
current_actor_context.run(config_model=mock_configs.CONFIG_S390X)
message = current_actor_context.consume(SatelliteFacts)
assert not message


def test_satellite_capsule_present(current_actor_context):
current_actor_context.feed(InstalledRPM(items=[FOREMAN_PROXY_RPM]))
current_actor_context.run(config_model=mock_configs.CONFIG)
message = current_actor_context.consume(SatelliteFacts)[0]
assert message.has_foreman


def test_no_katello_installer_present(current_actor_context):
current_actor_context.feed(InstalledRPM(items=[FOREMAN_RPM]))
current_actor_context.run(config_model=mock_configs.CONFIG)
message = current_actor_context.consume(SatelliteFacts)[0]
assert not message.installer_has_systemchecks


def test_katello_installer_present(current_actor_context):
current_actor_context.feed(InstalledRPM(items=[FOREMAN_RPM, KATELLO_INSTALLER_RPM]))
current_actor_context.run(config_model=mock_configs.CONFIG)
message = current_actor_context.consume(SatelliteFacts)[0]
assert not message.installer_has_systemchecks


def test_installs_satellite_package(current_actor_context):
current_actor_context.feed(InstalledRPM(items=[FOREMAN_RPM, SATELLITE_RPM]))
current_actor_context.run(config_model=mock_configs.CONFIG)
message = current_actor_context.consume(RpmTransactionTasks)[0]
assert 'satellite' in message.to_install
assert 'satellite-capsule' not in message.to_install


def test_installs_satellite_capsule_package(current_actor_context):
current_actor_context.feed(InstalledRPM(items=[FOREMAN_PROXY_RPM, SATELLITE_CAPSULE_RPM]))
current_actor_context.run(config_model=mock_configs.CONFIG)
message = current_actor_context.consume(RpmTransactionTasks)[0]
assert 'satellite-capsule' in message.to_install
assert 'satellite' not in message.to_install


def test_detects_local_postgresql(current_actor_context):
current_actor_context.feed(InstalledRPM(items=[FOREMAN_RPM, POSTGRESQL_RPM]))
current_actor_context.run(config_model=mock_configs.CONFIG)

satellitemsg = current_actor_context.consume(SatelliteFacts)[0]
assert satellitemsg.postgresql.local_postgresql


def test_detects_remote_postgresql(current_actor_context):
current_actor_context.feed(InstalledRPM(items=[FOREMAN_RPM]))
current_actor_context.run(config_model=mock_configs.CONFIG)

satellitemsg = current_actor_context.consume(SatelliteFacts)[0]
assert not satellitemsg.postgresql.local_postgresql


def test_enables_right_repositories_on_satellite(current_actor_context):
current_actor_context.feed(InstalledRPM(items=[FOREMAN_RPM, SATELLITE_RPM]))
current_actor_context.run(config_model=mock_configs.CONFIG)

rpmmessage = current_actor_context.consume(RepositoriesSetupTasks)[0]

assert f'satellite-maintenance-{SATELLITE_VERSION}-for-rhel-9-x86_64-rpms' in rpmmessage.to_enable
assert f'satellite-{SATELLITE_VERSION}-for-rhel-9-x86_64-rpms' in rpmmessage.to_enable
assert f'satellite-capsule-{SATELLITE_VERSION}-for-rhel-9-x86_64-rpms' not in rpmmessage.to_enable


def test_enables_right_repositories_on_capsule(current_actor_context):
current_actor_context.feed(InstalledRPM(items=[FOREMAN_PROXY_RPM, SATELLITE_CAPSULE_RPM]))
current_actor_context.run(config_model=mock_configs.CONFIG)

rpmmessage = current_actor_context.consume(RepositoriesSetupTasks)[0]

assert f'satellite-maintenance-{SATELLITE_VERSION}-for-rhel-9-x86_64-rpms' in rpmmessage.to_enable
assert f'satellite-{SATELLITE_VERSION}-for-rhel-9-x86_64-rpms' not in rpmmessage.to_enable
assert f'satellite-capsule-{SATELLITE_VERSION}-for-rhel-9-x86_64-rpms' in rpmmessage.to_enable

0 comments on commit 68ca385

Please sign in to comment.