Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable cross-releasing between platforms #1058

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 33 additions & 14 deletions alws/release_planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@

class BaseReleasePlanner(metaclass=ABCMeta):
def __init__(self, db: AsyncSession):
self.base_platform = None # type: typing.Optional[models.Platform]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, do not mix type annotations in the code with type comments, just use annotation instead

self._db = db
self.pulp_client = PulpClient(
settings.pulp_host,
Expand Down Expand Up @@ -238,11 +239,22 @@ async def get_pulp_packages_info(
for _, package in pulp_packages.items()
]

@staticmethod
def __get_platforms(platform: models.Platform) -> list[models.Platform]:
return [platform] + platform.reference_platforms

def _can_be_released_to_target_platform(
self,
artifact_platform: models.Platform,
) -> bool:
target_platforms = self.__get_platforms(self.base_platform)
source_platforms = self.__get_platforms(artifact_platform)
return any(sp in target_platforms for sp in source_platforms)

@class_measure_work_time_async("get_packages_info_pulp_and_db")
async def get_pulp_packages(
self,
build_ids: typing.List[int],
platform_id: int,
build_tasks: typing.Optional[typing.List[int]] = None,
) -> typing.Tuple[typing.List[dict], typing.List[str], typing.List[dict]]:
src_rpm_names = []
Expand All @@ -255,17 +267,21 @@ async def get_pulp_packages(
selectinload(models.Build.platform_flavors),
selectinload(models.Build.source_rpms)
.selectinload(models.SourceRpm.artifact)
.selectinload(models.BuildTaskArtifact.build_task),
.selectinload(models.BuildTaskArtifact.build_task)
.selectinload(models.BuildTask.platform)
.selectinload(models.Platform.reference_platforms),
selectinload(models.Build.binary_rpms)
.selectinload(models.BinaryRpm.artifact)
.selectinload(models.BuildTaskArtifact.build_task),
.selectinload(models.BuildTaskArtifact.build_task)
.selectinload(models.BuildTask.platform)
.selectinload(models.Platform.reference_platforms),
selectinload(models.Build.binary_rpms)
.selectinload(models.BinaryRpm.source_rpm)
.selectinload(models.SourceRpm.artifact),
selectinload(models.Build.tasks).selectinload(
models.BuildTask.rpm_modules
),
selectinload(models.Build.repos),
selectinload(models.Build.tasks)
.selectinload(models.BuildTask.rpm_modules),
selectinload(models.Build.repos)
.selectinload(models.Repository.platform),
)
)
build_result = await self.db.execute(builds_q)
Expand All @@ -278,7 +294,9 @@ async def get_pulp_packages(
build.binary_rpms,
]
for build_rpm in rpms_list
if build_rpm.artifact.build_task.platform_id == platform_id
if self._can_be_released_to_target_platform(
artifact_platform=build_rpm.artifact.build_task.platform,
)
]
logging.info('Build RPMs "%s"', build_rpms)
pulp_artifacts = await self.get_pulp_packages_info(
Expand Down Expand Up @@ -337,7 +355,9 @@ async def get_pulp_packages(
if build_repo.arch == task.arch
and not build_repo.debug
and build_repo.type == "rpm"
and build_repo.platform_id == platform_id
and self._can_be_released_to_target_platform(
artifact_platform=build_repo.platform,
)
)
template = await self.pulp_client.get_repo_modules_yaml(
module_repo.url
Expand All @@ -361,7 +381,7 @@ async def get_pulp_packages(
# Module version needs to be converted into
# string because it's going to be involved later
# in release plan. When interacting with API
# via Swagger or albs-frontend, we'll loose
# via Swagger or albs-frontend, we'll lose
# precision as described here:
# https://github.com/tiangolo/fastapi/issues/2483#issuecomment-744576007
"version": str(module.version),
Expand Down Expand Up @@ -703,6 +723,7 @@ async def get_release_plan(
build_tasks: typing.Optional[typing.List[int]] = None,
product: typing.Optional[models.Product] = None,
) -> dict:
self.base_platform = base_platform
release_plan = {"modules": {}}
added_packages = set()

Expand All @@ -719,7 +740,6 @@ async def get_release_plan(
pulp_rpm_modules,
) = await self.get_pulp_packages(
build_ids,
platform_id=base_platform.id,
build_tasks=build_tasks,
)

Expand Down Expand Up @@ -1312,7 +1332,6 @@ async def get_release_plan(
pulp_rpm_modules,
) = await self.get_pulp_packages(
build_ids,
platform_id=base_platform.id,
build_tasks=build_tasks,
)

Expand Down Expand Up @@ -1437,7 +1456,7 @@ async def get_release_plan(
continue
module_info["repositories"].append(module_repo_dict)

platforms_list = base_platform.reference_platforms + [base_platform]
platforms_list = self.__get_platforms(base_platform)
beholder_responses = await self._beholder_client.retrieve_responses(
platforms_list,
data={
Expand Down Expand Up @@ -1500,7 +1519,7 @@ async def get_release_plan(
is_devel=is_devel,
beholder_cache=beholder_cache,
)
# if we doesn't found repos for debug package, we can try to
# if we didn't find the repos for debug package, we can try to
# find repos by same package name but without debug suffix
if not repositories and is_debug:
repositories = self.find_release_repos(
Expand Down
4 changes: 4 additions & 0 deletions tests/fixtures/platforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import yaml
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm import selectinload

from alws import models
from alws.schemas import platform_schema, repository_schema
Expand All @@ -25,6 +26,9 @@ async def base_platform(
select(models.Platform).where(
models.Platform.name == schema["name"],
)
.options(
selectinload(models.Platform.reference_platforms),
)
)
)
.scalars()
Expand Down
Loading