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

Implement a check for every storage whether a repository is available #3527

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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: 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
from urllib.parse import urlparse
Fixed Show fixed Hide fixed
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,
Copy link
Member

Choose a reason for hiding this comment

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

Is self.project actually a self.coprdir?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's actually this:

project = self.ext_data.get("projectname")

which comes from frontend

project = self.ext_data.get("projectname")

so it should only be a project name, not CoprDir name. Which should IMHO be what we want because CoprDirs don't have their own repositories available (see #3369) and they use the main repo.

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