Skip to content

Commit

Permalink
compute needed repos based on enabled repos
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeni committed Mar 1, 2024
1 parent ff8aaf7 commit 055467b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
RepositoriesSetupTasks,
RpmTransactionTasks,
SatelliteFacts,
SatellitePostgresqlFacts
SatellitePostgresqlFacts,
UsedRepositories
)
from leapp.tags import FactsPhaseTag, IPUWorkflowTag

SATELLITE_VERSION = '6.99'

RELATED_PACKAGES = ('foreman', 'foreman-proxy', 'katello', 'candlepin')
RELATED_PACKAGES = ('foreman', 'foreman-proxy', 'katello', 'candlepin', 'satellite', 'satellite-capsule')
RELATED_PACKAGE_PREFIXES = ('rubygem-hammer', 'rubygem-foreman', 'rubygem-katello',
'rubygem-smart_proxy', 'python3.11-pulp', 'foreman-installer',
'satellite-installer')
Expand All @@ -24,7 +23,7 @@ class SatelliteUpgradeFacts(Actor):
"""

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

Expand Down Expand Up @@ -60,16 +59,12 @@ def process(self):
),
))

satellite = has_package(InstalledRPM, 'satellite')
capsule = has_package(InstalledRPM, 'satellite-capsule')
if satellite or capsule:
repositories_to_enable = [f'satellite-maintenance-{SATELLITE_VERSION}-for-rhel-9-x86_64-rpms']
if satellite:
repositories_to_enable.append(f'satellite-{SATELLITE_VERSION}-for-rhel-9-x86_64-rpms')
to_install.append('satellite')
elif capsule:
repositories_to_enable.append(f'satellite-capsule-{SATELLITE_VERSION}-for-rhel-9-x86_64-rpms')
to_install.append('satellite-capsule')
repositories_to_enable = []
for used_repos in self.consume(UsedRepositories):
for used_repo in used_repos.repositories:
if used_repo.repository.startswith(('satellite-6', 'satellite-capsule-6', 'satellite-maintenance-6')):
repositories_to_enable.append(used_repo.repository.replace('for-rhel-8', 'for-rhel-9'))
if repositories_to_enable:
self.produce(RepositoriesSetupTasks(to_enable=repositories_to_enable))

self.produce(RpmTransactionTasks(to_install=to_install))
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from leapp.libraries.common.config import mock_configs
from leapp.models import InstalledRPM, RepositoriesSetupTasks, RPM, RpmTransactionTasks, SatelliteFacts
from leapp.models import InstalledRPM, RepositoriesSetupTasks, RPM, RpmTransactionTasks, SatelliteFacts, UsedRepositories, UsedRepository

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

Expand All @@ -19,7 +19,9 @@ def fake_package(pkg_name):
SATELLITE_RPM = fake_package('satellite')
SATELLITE_CAPSULE_RPM = fake_package('satellite-capsule')

SATELLITE_VERSION = '6.99'
SATELLITE_REPOSITORY = UsedRepository(repository='satellite-6.99-for-rhel-8-x86_64-rpms')
CAPSULE_REPOSITORY = UsedRepository(repository='satellite-capsule-6.99-for-rhel-8-x86_64-rpms')
MAINTENANCE_REPOSITORY = UsedRepository(repository='satellite-maintenance-6.99-for-rhel-8-x86_64-rpms')


def test_no_satellite_present(current_actor_context):
Expand Down Expand Up @@ -110,24 +112,26 @@ def test_detects_remote_postgresql(current_actor_context):

def test_enables_right_repositories_on_satellite(current_actor_context):
current_actor_context.feed(InstalledRPM(items=[FOREMAN_RPM, SATELLITE_RPM]))
current_actor_context.feed(UsedRepositories(repositories=[SATELLITE_REPOSITORY, MAINTENANCE_REPOSITORY]))
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
assert 'satellite-maintenance-6.99-for-rhel-9-x86_64-rpms' in rpmmessage.to_enable
assert 'satellite-6.99-for-rhel-9-x86_64-rpms' in rpmmessage.to_enable
assert 'satellite-capsule-6.99-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.feed(UsedRepositories(repositories=[CAPSULE_REPOSITORY, MAINTENANCE_REPOSITORY]))
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
assert 'satellite-maintenance-6.99-for-rhel-9-x86_64-rpms' in rpmmessage.to_enable
assert 'satellite-6.99-for-rhel-9-x86_64-rpms' not in rpmmessage.to_enable
assert 'satellite-capsule-6.99-for-rhel-9-x86_64-rpms' in rpmmessage.to_enable


def test_enables_right_repositories_on_upstream(current_actor_context):
Expand Down

0 comments on commit 055467b

Please sign in to comment.