-
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
Introduce search_content method for repositories [DELIVERY-7839] #71
Conversation
Not sure why it's complaining about coverage. The tests included do cover these lines. |
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 think you're missing support on the fake client - if you have a Repository obtained from a fake client now and you call search_content, what happens? That should work too & would need a test.
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 wonder if we should merge this and #64 together. Most of the work would be done for arranging code to support model criteria anyway. And it seems to be useless to implement something which will be overwritten in next PR
The repository object is still real, right? And, though it makes sense that the real client isn't being called, at least search_content should be covered as it belongs to Repository. |
The point is that if you use a fake client to get a Repository object, then call search_content, it must behave in a way which makes sense, i.e. it returns a consistent view of whatever data is stored on the fake client. Does it behave that way now? I'd expect it's necessary to write new code to achieve that, and then that new code will need to be tested.
It's not the case that only the fake client is used in tests. This library provides two implementations of a Pulp client for use by others, one designed to issue real HTTP requests to a Pulp server and the other designed to return data from local memory. Both implementations should be tested by this library's test suite, so there are some tests here using one and some tests using the other.
Autotest tests/model/test_model_invariants.py automatically finds and performs some basic tests on every model class. On top of that, at least one test where a search returns a ModulemdDefaultUnit would be nice, which I think you already have added. I don't think there's much need for adding more tests when introducing new unit types. |
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.
It doesn't seem to work at all against a real Pulp server.
(python3) [rmcgover@picallow pubtools-pulplib]$ python3
Python 3.7.4 (default, Jul 9 2019, 16:32:37)
[GCC 9.1.1 20190503 (Red Hat 9.1.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pubtools.pulplib import Client
>>> c = Client('https://rhsm-pulp-dev/', auth=('admin', 'admin'), verify=False)
>>> repo = c.get_repository('all-iso-content')
# Library won't accept Pulp server's type IDs
>>> repo.search_content(type_id='iso')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/rmcgover/src/pubtools-pulplib/pubtools/pulplib/_impl/model/repository/base.py", line 223, in search_content
raise InvalidContentTypeException()
pubtools.pulplib._impl.model.common.InvalidContentTypeException
# And Pulp server won't accept library's type IDs
>>> repo.search_content(type_id='FileUnit')
<ProxyFuture at 0x7f9078f69750 state=pending>
...
Retrying due to error: 400 Client Error: Bad Request for url: https://rhsm-pulp-dev/pulp/api/v2/repositories/all-iso-content/search/units/ [1/10]
Traceback (most recent call last):
File "/home/rmcgover/src/more-executors/more_executors/_impl/map.py", line 61, in _delegate_resolved
result = self._map_fn(result)
File "/home/rmcgover/src/pubtools-pulplib/pubtools/pulplib/_impl/client/client.py", line 412, in _unpack_response
pulp_response.raise_for_status()
File "/home/rmcgover/dev/python3/lib/python3.7/site-packages/requests/models.py", line 940, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://rhsm-pulp-dev/pulp/api/v2/repositories/all-iso-content/search/units/
Can you please ensure it works against a real server?
To make this easier for yourself and reviewers, you can consider adding a simple script under examples
, as was done for some other additions to API.
I can reproduce the coveralls results locally.
|
Points 2 and 3 are probably conflicting with each other a bit, as I was reviewing the TestSearchContent body with the understanding that it would be executed, which later turned out to be false. If you fix point 3 first, it might fix or partially fix point 2. |
Yeah, I figured out a lot of this myself last night and think I've solved most of the points you mention. |
Finally. |
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 gave +1 for this patch, but for the repo.search_content API, I still think this is too much. It calls the client.search_repo_content api, means they are completely the same, so why make two of them? Rohan's API design says, 'when in doubt, leave it out', since it's easy to add but difficult to remove.
Anyway, I'm OK if you insist, I gave +1 :)
This commit adds the search_content method for the Repository class which retrieves rpm, srpm, modulemd, and modulemd_default content with optional filtering by name, arch, file name, or modulemd stream.
Client.search_repository_content was found to be unnecessary, so this commit removes it. A Repository object is now required to search content therein. A issue involving type_ids in criteria structures was also corrected.
@jbruzl, I think you're the only code owner for this repo still around. |
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.
Approving as all code owners are not available.
This commit adds the search_content method for the Repository class
which searches for and retrieves content units from Pulp repositories.