Skip to content

Commit

Permalink
Fix sync from local (on-disk) repository
Browse files Browse the repository at this point in the history
[nocoverage]

closes: #7342
https://pulp.plan.io/issues/7342
  • Loading branch information
dralley committed Aug 19, 2020
1 parent f122346 commit 8ef4e58
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES/7342.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix sync from local (on-disk) repository.
26 changes: 24 additions & 2 deletions pulp_rpm/app/downloaders.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
from logging import getLogger
from urllib.parse import urljoin

from pulpcore.plugin.download import HttpDownloader
from pulpcore.plugin.download import FileDownloader, HttpDownloader


log = getLogger(__name__)


class RpmFileDownloader(FileDownloader):
"""
FileDownloader that strips out RPM's custom http downloader arguments.
This is unfortunate, but there isn't currently a good pattern for customizing the downloader
factory machinery such that certain types of arguments only apply to certain downloaders,
so passing a kwarg into get_downloader() will pass it to constructor for any downloader.
TODO: https://pulp.plan.io/issues/7352
"""

def __init__(self, *args, **kwargs):
"""
Initialize the downloader.
"""
kwargs.pop('silence_errors_for_response_status_codes', None)
super().__init__(*args, **kwargs)


class RpmDownloader(HttpDownloader):
"""
Custom Downloader that automatically handles authentication token for SLES repositories.
Expand All @@ -21,12 +40,15 @@ class RpmDownloader(HttpDownloader):
"""

def __init__(self, *args, silence_errors_for_response_status_codes=set(), sles_auth_token=None,
def __init__(self, *args, silence_errors_for_response_status_codes=None, sles_auth_token=None,
**kwargs):
"""
Initialize the downloader.
"""
self.sles_auth_token = sles_auth_token

if silence_errors_for_response_status_codes is None:
silence_errors_for_response_status_codes = set()
self.silence_errors_for_response_status_codes = silence_errors_for_response_status_codes

super().__init__(*args, **kwargs)
Expand Down
3 changes: 2 additions & 1 deletion pulp_rpm/app/models/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
UpdateRecord,
)

from pulp_rpm.app.downloaders import RpmDownloader
from pulp_rpm.app.downloaders import RpmDownloader, RpmFileDownloader
from pulp_rpm.app.exceptions import DistributionTreeConflict

log = getLogger(__name__)
Expand Down Expand Up @@ -74,6 +74,7 @@ def download_factory(self):
downloader_overrides={
'http': RpmDownloader,
'https': RpmDownloader,
'file': RpmFileDownloader,
}
)
return self._download_factory
Expand Down

0 comments on commit 8ef4e58

Please sign in to comment.