Skip to content

Commit

Permalink
backend: implement a check for every storage whether a repository is …
Browse files Browse the repository at this point in the history
…available

Otherwise, builds in Pulp projects will fail with this:

    Waiting for copr_base repository
    Waiting for copr_base repository
    Backend process error: Giving up waiting for copr_base repository

So far it worked only because we didn't create Pulp projects directly
but rather migrated existing projects into Pulp and therefore this
path existed on the backend.
  • Loading branch information
FrostyX authored and praiskup committed Jan 9, 2025
1 parent ddec4d9 commit 88293f0
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
5 changes: 3 additions & 2 deletions backend/copr_backend/background_worker_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,11 @@ def _wait_for_repo(self):
# we don't need copr_base repodata for srpm builds
return

repodata = os.path.join(self.job.chroot_dir, "repodata/repomd.xml")
waiting_since = time.time()
while time.time() - waiting_since < 60:
if os.path.exists(repodata):
exists = self.storage.repository_exists(
self.job.project_dirname, self.job.chroot)
if exists:
return

# Either (a) the very first copr-repo run in this chroot dir
Expand Down
40 changes: 38 additions & 2 deletions backend/copr_backend/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import os
import json
import shutil
from urllib.parse import urlparse
import requests
from copr_common.enums import StorageEnum
from copr_backend.helpers import call_copr_repo, build_chroot_log_name
from copr_backend.pulp import PulpClient
Expand Down Expand Up @@ -85,6 +87,12 @@ def delete_builds(self, dirname, chroot_builddirs, build_ids):
"""
raise NotImplementedError

def repository_exists(self, dirname, chroot):
"""
Does a repository exist?
"""
raise NotImplementedError


class BackendStorage(Storage):
"""
Expand Down Expand Up @@ -172,6 +180,11 @@ def delete_builds(self, dirname, chroot_builddirs, build_ids):
self.log.debug("can't remove %s", log_path)
return result

def repository_exists(self, dirname, chroot):
repodata = os.path.join(self.opts.destdir, self.owner, dirname,
chroot, "repodata", "repomd.xml")
return os.path.exists(repodata)


class PulpStorage(Storage):
"""
Expand Down Expand Up @@ -342,15 +355,38 @@ def delete_builds(self, dirname, chroot_builddirs, build_ids):

return result

def repository_exists(self, dirname, chroot):
name = self._distribution_name(chroot, dirname)
response = self.client.get_distribution(name)
if not response.ok:
return False

data = response.json()
if data["count"] == 0:
return False

distribution = response.json()["results"][0]

# For some instances (local container) the distribution base_url
# contains only path, for some instances (hosted STG) it returns fully
# qualified URL. The problem is that there is a lot of magic in the
# hosted deployment in order to provide the data publicly without
# a Red Hat login. And we cannot use the returned URL, only its path.
path = urlparse(distribution["base_url"]).path.lstrip("/")
host = self.client.config["base_url"].rstrip("/")
repodata = "{0}/{1}/repodata/repomd.xml".format(host, path)
response = requests.head(repodata)
return response.ok

def _repository_name(self, chroot, dirname=None):
return "/".join([
self.owner,
dirname or self.project,
chroot,
])

def _distribution_name(self, chroot):
repository = self._repository_name(chroot)
def _distribution_name(self, chroot, dirname=None):
repository = self._repository_name(chroot, dirname)
if self.devel:
return "{0}-devel".format(repository)
return repository
Expand Down

0 comments on commit 88293f0

Please sign in to comment.