Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

Mitigate GSSAPIAuthError #487

Merged
merged 2 commits into from
Jul 30, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions doozerlib/cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,9 @@ def images_build_image(runtime, repo_type, repo, push_to_defaults, push_to, scra

if not runtime.local:
threads = None
with runtime.shared_koji_client_session() as koji_api:
if not koji_api.logged_in:
koji_api.gssapi_login()

# load active build profile
profiles = runtime.group_config.build_profiles
Expand Down
8 changes: 8 additions & 0 deletions doozerlib/cli/rpms_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ async def _rpms_rebase_and_build(runtime: Runtime, version: str, release: str, e
for rpm in rpms:
rpm.private_fix = True

with runtime.shared_koji_client_session() as koji_api:
if not koji_api.logged_in:
koji_api.gssapi_login()

builder = RPMBuilder(runtime, dry_run=dry_run, scratch=scratch)

async def _rebase_and_build(rpm: RPMMetadata):
Expand Down Expand Up @@ -188,6 +192,10 @@ async def _rpms_build(runtime: Runtime, scratch: bool, dry_run: bool):
runtime.logger.error("No RPMs found. Check the arguments.")
exit(0)

with runtime.shared_koji_client_session() as koji_api:
if not koji_api.logged_in:
koji_api.gssapi_login()

builder = RPMBuilder(runtime, dry_run=dry_run, scratch=scratch)
tasks = [asyncio.ensure_future(_build_rpm(runtime, builder, rpm)) for rpm in rpms]

Expand Down
25 changes: 13 additions & 12 deletions doozerlib/distgit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1210,17 +1210,18 @@ def _build_container(self, target_image, target, signing_intent, repo_type, repo
self.logger.info("Error building image: {}, {}".format(task_url, error))
return False

koji_api = self.runtime.build_retrying_koji_client()
koji_api.gssapi_login()
# Unlike rpm build, koji_api.listBuilds(taskID=...) doesn't support image build. For now, let's use a different approach.
taskResult = koji_api.getTaskResult(task_id)
build_id = int(taskResult["koji_builds"][0])
build_info = koji_api.getBuild(build_id)
record["nvrs"] = build_info["nvr"]
if self.runtime.hotfix:
# Tag the image so they don't get garbage collected.
self.runtime.logger.info(f'Tagging {self.metadata.get_component_name()} build {build_info["nvr"]} with {self.metadata.hotfix_brew_tag()} to prevent garbage collection')
koji_api.tagBuild(self.metadata.hotfix_brew_tag(), build_info["nvr"])
with self.runtime.shared_koji_client_session() as koji_api:
if not koji_api.logged_in:
koji_api.gssapi_login()
# Unlike rpm build, koji_api.listBuilds(taskID=...) doesn't support image build. For now, let's use a different approach.
taskResult = koji_api.getTaskResult(task_id)
build_id = int(taskResult["koji_builds"][0])
build_info = koji_api.getBuild(build_id)
record["nvrs"] = build_info["nvr"]
if self.runtime.hotfix:
# Tag the image so they don't get garbage collected.
self.runtime.logger.info(f'Tagging {self.metadata.get_component_name()} build {build_info["nvr"]} with {self.metadata.hotfix_brew_tag()} to prevent garbage collection')
koji_api.tagBuild(self.metadata.hotfix_brew_tag(), build_info["nvr"])

self.update_build_db(True, task_id=task_id, scratch=scratch)
self.logger.info("Successfully built image: {} ; {}".format(target_image, task_url))
Expand Down Expand Up @@ -1756,7 +1757,7 @@ def _update_yum_update_commands(self, force_yum_updates: bool, df_fileobj: io.Te
# For rebuild logic, we need to be able to prioritize repos; RHEL7 requires a plugin to be installed.
yum_update_line = "RUN yum install -y yum-plugin-priorities && yum update -y && yum clean all"
else:
yum_update_line = f"RUN yum update -y && yum clean all"
yum_update_line = "RUN yum update -y && yum clean all"
output = io.StringIO()
build_stage = 0
for line in df_lines_iter:
Expand Down
21 changes: 11 additions & 10 deletions doozerlib/rpm_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,17 +241,18 @@ async def build(self, rpm: RPMMetadata, retries: int = 3):
failed_tasks = {task_id for task_id, error in errors.items() if error is not None}
if not failed_tasks:
# All tasks complete.
koji_api = self._runtime.build_retrying_koji_client()
koji_api.gssapi_login()
with koji_api.multicall(strict=True) as m:
multicall_tasks = [m.listBuilds(taskID=task_id, completeBefore=None) for task_id in task_ids] # this call should not be constrained by brew event
nvrs = [task.result[0]["nvr"] for task in multicall_tasks]
if self._runtime.hotfix:
# Tag rpms so they don't get garbage collected.
self._runtime.logger.info(f'Tagging build(s) {nvrs} with {rpm.hotfix_brew_tag()} to prevent garbage collection')
with self._runtime.shared_koji_client_session() as koji_api:
if not koji_api.logged_in:
koji_api.gssapi_login()
with koji_api.multicall(strict=True) as m:
for nvr in nvrs:
m.tagBuild(rpm.hotfix_brew_tag(), nvr)
multicall_tasks = [m.listBuilds(taskID=task_id, completeBefore=None) for task_id in task_ids] # this call should not be constrained by brew event
nvrs = [task.result[0]["nvr"] for task in multicall_tasks]
if self._runtime.hotfix:
# Tag rpms so they don't get garbage collected.
self._runtime.logger.info(f'Tagging build(s) {nvrs} with {rpm.hotfix_brew_tag()} to prevent garbage collection')
with koji_api.multicall(strict=True) as m:
for nvr in nvrs:
m.tagBuild(rpm.hotfix_brew_tag(), nvr)

logger.info("Successfully built rpm: %s", rpm.rpm_name)
rpm.build_status = True
Expand Down
2 changes: 1 addition & 1 deletion tests/test_rpm_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def test_build_success(self, mocked_cmd_gather_async: mock.Mock):
task_id: None for task_id in task_ids})
mocked_cmd_gather_async.return_value = (0, "some stdout", "some stderr")
dg.resolve_specfile_async = mock.AsyncMock(return_value=(dg.dg_path / "foo.spec", ("foo", "1.2.3", "1"), source_sha))
koji_api = runtime.build_retrying_koji_client.return_value
koji_api = runtime.shared_koji_client_session.return_value.__enter__.return_value
koji_api.multicall.return_value.__enter__.return_value.listBuilds.side_effect = lambda taskID, completeBefore: {
10001: mock.MagicMock(result=[{"nvr": "foo-1.2.3-1.el8"}]),
10002: mock.MagicMock(result=[{"nvr": "foo-1.2.3-1.el7"}]),
Expand Down