Skip to content

Commit

Permalink
Override the raise_for_status method for silencing logs
Browse files Browse the repository at this point in the history
closes #518
  • Loading branch information
lubosmj authored and ipanova committed Jul 20, 2022
1 parent fa2073a commit 6ad7184
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGES/518.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Silenced redundant logs when downloading signatures.
16 changes: 16 additions & 0 deletions pulp_container/app/downloaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,22 @@ def auth_header(token, basic_auth):
return {}


class NoAuthSignatureDownloader(HttpDownloader):
"""A downloader class suited for signature downloads."""

def raise_for_status(self, response):
"""Log an error only if the status code of the response is not equal to 404.
Status codes equal to 404 signify that a signature could not be found on the server. This
case is still valid because it is not possible to determine the number of signatures
beforehand.
"""
if response.status == 404:
raise FileNotFoundError()
else:
response.raise_for_status()


class NoAuthDownloaderFactory(DownloaderFactory):
"""
A downloader factory without any preset auth configuration, TLS or basic auth.
Expand Down
8 changes: 7 additions & 1 deletion pulp_container/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,13 @@ def noauth_download_factory(self):
try:
return self._noauth_download_factory
except AttributeError:
self._noauth_download_factory = downloaders.NoAuthDownloaderFactory(self)
self._noauth_download_factory = downloaders.NoAuthDownloaderFactory(
self,
downloader_overrides={
"http": downloaders.NoAuthSignatureDownloader,
"https": downloaders.NoAuthSignatureDownloader,
},
)
return self._noauth_download_factory

def get_downloader(self, remote_artifact=None, url=None, **kwargs):
Expand Down
12 changes: 6 additions & 6 deletions pulp_container/app/tasks/sync_stages.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,14 +525,14 @@ async def create_signatures(self, man_dc, signature_source):
signature_downloader = self.remote.get_noauth_downloader(url=signature_url)
try:
signature_download_result = await signature_downloader.run()
except aiohttp.client_exceptions.ClientResponseError as exc:
if exc.status != 404:
log.info(
"{} is not accessible, can't sync an image signature. "
"Error: {} {}".format(signature_url, exc.status, exc.message)
)
except FileNotFoundError:
# 404 is fine, it means there are no or no more signatures available
break
except aiohttp.client_exceptions.ClientResponseError as exc:
log.info(
"{} is not accessible, can't sync an image signature. "
"Error: {} {}".format(signature_url, exc.status, exc.message)
)

with open(signature_download_result.path, "rb") as f:
signature_raw = f.read()
Expand Down

0 comments on commit 6ad7184

Please sign in to comment.