-
Notifications
You must be signed in to change notification settings - Fork 24
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
Add Client.create_repository() [RHELDST-22483] #218
Conversation
7a977c3
to
7171e16
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #218 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 47 47
Lines 3162 3225 +63
=========================================
+ Hits 3162 3225 +63 ☔ View full report in Codecov by Sentry. |
1a27b69
to
4125b70
Compare
""" | ||
Type id of the importer. | ||
""" | ||
config = pulp_attrib(default=None, type=dict, pulp_field="config") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this please use frozendict (converter=frozendict_or_none_converter
) so the object is immutable?
@@ -13,6 +13,16 @@ | |||
LOG = logging.getLogger("pubtools.pulplib") | |||
|
|||
|
|||
@attr.s(kw_only=True, frozen=True) | |||
class IsoImporter(Importer): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we please name this FileImporter
instead, to match FileRepository
?
It's the same reasoning as for FileRepository
itself. Yes, technically in Pulp's code and type IDs it refers to it as "iso", but that's a mistake and it's actually a generic file handler. We don't need to repeat the mistake in our own APIs, and by avoiding that we'll be better off if we ever want to port this code to Pulp3.
|
||
def test_create_repository(client, requests_mocker): | ||
repo = YumRepository(id="yum_repo") | ||
repo.__dict__["_client"] = client |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this line should be here. It's a hack done from within some tests to forcibly connect a repo object with a client, but the real users of the library aren't supposed to do that, and in this case it's important to test that client.create_repository(repo)
actually works without doing this hack first.
I believe if you delete this line the test should still pass and it'd be more accurately covering what the user code should look like.
|
||
def test_create_repository_already_exists(client, requests_mocker, caplog): | ||
repo = YumRepository(id="yum_repo") | ||
repo.__dict__["_client"] = client |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, we shouldn't need this hack.
|
||
def test_create_repository_raises_exception(client, requests_mocker): | ||
repo = YumRepository(id="yum_repo") | ||
repo.__dict__["_client"] = client |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here, we shouldn't need this hack.
I have addressed suggestions but for some reason the coverage checks started to time out. |
@rohanpm
|
I believe there is a bug in the change actually. I was able to reproduce it too, but I couldn't reproduce it after a change like below: diff --git a/pubtools/pulplib/_impl/client/client.py b/pubtools/pulplib/_impl/client/client.py
index 8a0bc27..5e24a85 100644
--- a/pubtools/pulplib/_impl/client/client.py
+++ b/pubtools/pulplib/_impl/client/client.py
@@ -1093,11 +1093,10 @@ class Client(object):
raise exception
- def get_and_check_repo(_):
- repo_on_server = self.get_repository(repo_id)
+ def check_repo(repo_on_server):
try:
assert (
- repo_on_server.result() == repo
+ repo_on_server == repo
), "Repo exists on server with unexpected values"
except AssertionError:
if importer:
@@ -1120,7 +1119,7 @@ class Client(object):
)
raise
- return repo_on_server
+ return f_return(repo_on_server)
LOG.debug("Creating repository %s", repo_id)
out = self._request_executor.submit(
@@ -1128,6 +1127,9 @@ class Client(object):
)
out = f_map(out, error_fn=log_existing_repo)
- out = f_flat_map(out, get_and_check_repo)
+ # After supposedly creating the repo, get it...
+ out = f_flat_map(out, lambda _: self.get_repository(repo_id))
+ # ...and check it matches what's needed
+ out = f_flat_map(out, check_repo)
return f_proxy(out) ...i.e. changing it into a fully non-blocking style rather than a mixture of blocking and non-blocking. Do you want to give that a try? I think the problem with the other approach is:
It can happen randomly, or not, depending on how fast each future manages to complete. Because when you do |
`Client` is now capable of creating a repository on pulp server. The repository is initialized with proper `Importer` in order to enable sync/upload of content to new repositories. Another notable changes: * 409 status is not retried in requests as it is used as indicator of existing repository. * Added create_repository() method to FakeClient as well. * Small changes in the repository.yaml schema as some of the fields don't have to be necessarily initialized when creating repo but can be updated later. * Added `Importer` pulp object mapping class and related subclasses that encapsulate minimal required fields for this object with valid defaults. * added `"importers": True` to search options for repos * fixed converter of `notes.signatures` on `Repository` - empty string is now converted to empty list, not to list with empty string
Client
is now capable of creating a repository on pulpserver. The repository is initialized with proper
Importer
in orderto enable sync/upload of content to new repositories.
Another notable changes:
existing repository.
don't have to be necessarily initialized when creating repo but can be
updated later.
Importer
pulp object mapping class and related subclassesthat encapsulate minimal required fields for this object with valid
defaults.
"importers": True
to search options for reposnotes.signatures
onRepository
- empty string is nowconverted to empty list, not to list with empty string