-
Notifications
You must be signed in to change notification settings - Fork 45
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
Rewrite test_modify.py
using pytest
#333
Conversation
f08d3f7
to
b66dde9
Compare
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.
Keep on! Do you mind addressing the comments?
@pytest.fixture | ||
def synced_repo_version( | ||
ostree_repositories_api_client, | ||
ostree_repositories_versions_api_client, | ||
ostree_repository_factory, | ||
ostree_remote_factory, | ||
monitor_task, | ||
): | ||
""" | ||
Fixture that syncs a Remote ostree Repository, | ||
waits until the sync task completes and returns the | ||
created repository version object. | ||
""" | ||
repo = ostree_repository_factory() | ||
remote = ostree_remote_factory(url=OSTREE_FIXTURE_URL, policy="immediate") | ||
result = ostree_repositories_api_client.sync(repo.pulp_href, {"remote": remote.pulp_href}) | ||
repo_version_href = monitor_task(result.task).created_resources[0] | ||
return ostree_repositories_versions_api_client.read(repo_version_href), remote, repo |
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.
Is this a duplicate of
def synced_repo( |
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.
Yes, kind of the same but instead of returning the repo we are now returning also the repo_version and remote.
At first, I thought that reusing it (by adding some conditionals or modifying the return) would compromise the readability/maintainability, but thinking again maybe not ... I'll check it!
|
||
|
||
@pytest.fixture | ||
def modify_repo(bindings_cfg, monitor_task): |
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 would remove this fixture. Try using repository_api.modify()
instead. It looks much more appealing!
|
||
|
||
@pytest.fixture | ||
def get_content(bindings_cfg): |
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 believe you can delete this.
In the past, we replaced get_content
from pulp_smash
by a plain call to content_api.list(repo.latest_version)
, see pulp/pulp_file@5c65d92#diff-082889e4107e892cad9e326317979e0a6e6b82a021fb85db8228af551797d6a0R99. Considering this, I propose adopting a similar strategy in the current context.
Furthermore, we will need to modify or remove the normalize_content
function to parse results separately for each content type. Alternatively, we can make the function a fixture and fuse the content_api.list(repo.latest_version)
logic into it, so we will have the downloading and normalizing at one place. What do you think?
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.
hum... not sure if I understood it, but both options seem complicated. I'll do some tests and revisit/re-read the functions to have a better understanding of the proposals.
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.
The basic idea is to use bindings to get things done. We should stray away from using requests
to access API endpoints that are suited for administering. In this case, we want to get a list of content units from an API endpoint which is properly mapped by the bindings.
86f50d6
to
f027c34
Compare
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.
Lint errors should be fixed now. Please, rebase your commit on top of the main branch.
commits = ostree_content_commits_api_client.list(repository_version=repo).results | ||
configs = ostree_content_configs_api_client.list(repository_version=repo).results | ||
objects = ostree_content_objects_api_client.list(repository_version=repo).results | ||
refs = ostree_content_refs_api_client.list(repository_version=repo).results | ||
summaries = ostree_content_summaries_api_client.list(repository_version=repo).results |
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.
Is there a guarantee that the results are always returned in the same order?
We used sorted
in the past to enforce the order:
sorted(
[remove_created_key(item) for item in repo_content[OSTREE_OBJECTS_NAME]],
key=lambda item: item["pulp_href"],
)
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.
hum... the only test that uses the normalize_content
is the test_copy_whole_repository and, if I understood it right, the test will not create multiple contents (commits/configs/objects/refs/summaries), therefore the results will always be ordered (a list with 0 or one element is an ordered list), right?
Anyway, I'll order it so that we can use it in the future with other tests if necessary.
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.
The synced repository should contain 3 objects as far as I know.
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.
ohhh ...my bad! (I still need to study and learn ostree to understand what is going on)
response = ostree_repositories_api_client.modify( | ||
ostree_ostree_repository_href=repo1.pulp_href, | ||
repository_add_remove_content={"add_content_units": [obj["pulp_href"]]}, | ||
) | ||
monitor_task(response.task) | ||
version2 = repo1.latest_version_href |
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 is necessary to re-load the version object by doing ostree_repositories_api_client.read(repo1.pulp_href).latest_version_href
. We aim to verify if the repository version was really not changed.
repository_add_remove_content={"remove_content_units": [obj["pulp_href"]]}, | ||
) | ||
monitor_task(response.task) | ||
version2 = repo1.latest_version_href |
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. The latest version is not automatically updated for repo1
since it represent an older state of the repository, before running the modify
task.
result = ostree_repositories_api_client.sync(repo.pulp_href, {"remote": remote.pulp_href}) | ||
repo_version_href = monitor_task(result.task).created_resources[0] | ||
repo = ostree_repositories_api_client.read(repo.pulp_href) | ||
return ostree_repositories_versions_api_client.read(repo_version_href), remote, repo |
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 might be worth returning the updated repository, containing a new latest repository version after syncing.
repo = ostree_repositories_api_client.read(repo.pulp_href)
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.
hum... I didn't get it. I thought that lines 143
https://github.com/pulp/pulp_ostree/pull/333/files/f027c34e99b30bb933276d2c24f29ad50ff97b8c#diff-fb6fcf86eeb05753e592d20f35257cdb41de6529cd8deb07781fb7707b8e378fR143
and return ... , ..., repo
(line144) would do that
https://github.com/pulp/pulp_ostree/pull/333/files/f027c34e99b30bb933276d2c24f29ad50ff97b8c#diff-fb6fcf86eeb05753e592d20f35257cdb41de6529cd8deb07781fb7707b8e378fR144
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.
Oh, my bad. This one is correct. It went unnoticed.
f027c34
to
e09f13c
Compare
e09f13c
to
068d70d
Compare
fixes: #326