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 committed Nov 22, 2024
1 parent 4313913 commit 682d6f5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
3 changes: 1 addition & 2 deletions backend/copr_backend/background_worker_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,9 @@ 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):
if self.storage.repository_exists(self.job.chroot):
return

# Either (a) the very first copr-repo run in this chroot dir
Expand Down
31 changes: 31 additions & 0 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
import requests
from urllib.parse import urlparse

Check warning

Code scanning / vcs-diff-lint

standard import "urllib.parse.urlparse" should be placed before third party import "requests" Warning

standard import "urllib.parse.urlparse" should be placed before third party 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, 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, chroot):
repodata = os.path.join(self.opts.destdir, self.owner, self.project,
chroot, "repodata", "repomd.xml")
return os.path.exists(repodata)


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

return result

def repository_exists(self, chroot):
name = self._distribution_name(chroot)
response = self.client.get_distribution(name)
if not response.ok:
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,
Expand Down

0 comments on commit 682d6f5

Please sign in to comment.