diff --git a/CHANGES/518.bugfix b/CHANGES/518.bugfix new file mode 100644 index 000000000..accec378c --- /dev/null +++ b/CHANGES/518.bugfix @@ -0,0 +1 @@ +Silenced redundant logs when downloading signatures. diff --git a/pulp_container/app/downloaders.py b/pulp_container/app/downloaders.py index a2e6ed16c..14bdc4522 100644 --- a/pulp_container/app/downloaders.py +++ b/pulp_container/app/downloaders.py @@ -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. diff --git a/pulp_container/app/models.py b/pulp_container/app/models.py index 1bcbb0474..26fca20ab 100644 --- a/pulp_container/app/models.py +++ b/pulp_container/app/models.py @@ -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): diff --git a/pulp_container/app/tasks/sync_stages.py b/pulp_container/app/tasks/sync_stages.py index 55ebde225..1922ffcf4 100644 --- a/pulp_container/app/tasks/sync_stages.py +++ b/pulp_container/app/tasks/sync_stages.py @@ -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()