Conversation
There was a problem hiding this comment.
Code Review
This pull request is a significant refactoring of the memcache tests, aiming to reduce code duplication by introducing helper functions and parametrizing tests. While this is a great improvement for maintainability, the new implementation introduces several critical and high-severity issues, including a syntax error, flawed test logic that would cause failures, and several inconsistencies between test names, docstrings, and their implementations. I've detailed these issues in the review comments.
88f67f3 to
4164a67
Compare
4164a67 to
92e2433
Compare
800149e to
79780ef
Compare
36e1b79 to
757722f
Compare
bc7b7a2 to
b484bad
Compare
|
@danlavu, can you please check, |
b484bad to
29ad9e3
Compare
|
@madhuriupadhye @andreboscatto I suggest reviewing this PR using the split diff view and not the unified diff. |
Indeed, I started reviewing the old document, understanding each case and looking at yours. Doing that side by side is helpful. |
fixed. |
| Check the existence of objects, either users, groups, or initgroups. | ||
|
|
||
| This is a helper function to parameterize the memcache test. The assertions for each | ||
| cache time are different. Looking up 'users, will use 'id', groups will use 'getent group', |
There was a problem hiding this comment.
Please update to Looking up 'users', will use
cache time or cache type?
There was a problem hiding this comment.
replace Looking up 'users, will use to Looking up **'users'**, will use
|
please check, 289: 2: Group membership is correct -> 2. Group membership is correct |
f45a3e2 to
3ab0a1e
Compare
3ab0a1e to
c3b49a7
Compare
| def test_memcache__invalidate_user_cache_after_stop(client: Client, provider: GenericProvider): | ||
| @pytest.mark.parametrize( | ||
| "cache", | ||
| ["users", "groups", "initgroups", "all"], |
There was a problem hiding this comment.
assert_objects and assert_objects_not_found only handle "users", "groups", and "initgroups". There is no branch for cache == "all", so for "all" both functions return without asserting anything.
When cache is "all", those two lines invoke the helpers with "all", which matches none of the if cache == ... branches, so no assertions run there.
There was a problem hiding this comment.
That is an awesome catch, thank you. Created a new test to cover all cache types disabled.
* parametrized test cases * added colliding hash test case * remove poor test scenarios
c3b49a7 to
926a6b0
Compare
| def test_memcache__invalidate_groups_cache_after_stop(client: Client, provider: GenericProvider): | ||
| @pytest.mark.parametrize( | ||
| "cache", | ||
| ["users", "groups", "initgroups", "all"], |
There was a problem hiding this comment.
@pytest.mark.parametrize(
"cache",
["users", "groups", "initgroups", "all"],
)
...
assert_objects(client, objects, cache)
invalidate_cache_stop_sssd(client, order, cache)
assert_objects_not_found(client, objects, cache)
assert_objects / assert_objects_not_found only handle "users", "groups", and "initgroups". For "all" they do nothing, so those subtests do not assert warm-up or post-conditions. invalidate_cache_stop_sssd does hit cache_expire(everything=True) in the else branch, but the test body is still incomplete.
Drop "all" and add a dedicated test that loops the three cache kinds, or teach the helpers to treat "all" as “run all three branches.”, WDYT?
| gresult = client.tools.getent.group("group1") | ||
| assert gresult is not None, "Group group1 is not found using getent" | ||
| assert gresult.gid == 10001, f"Group gid {gresult.gid} is incorrect, 10001 expected" | ||
| colliding_user = client.host.conn.run(f"python {script}").stdout |
There was a problem hiding this comment.
Use something like colliding_user = client.host.conn.run(...).stdout.strip() and assert non-empty. A trailing newline can become part of the username and break lookups.
| assert result_user is not None, f"User '{user.name}' was not found!" | ||
| assert ( | ||
| result_user.groups[-1].name == expected_groups[-1] | ||
| ), f"User '{user.name}' is member of incorrect groups!" |
There was a problem hiding this comment.
assert (
result_user.groups[-1].name == expected_groups[-1]
), f"User '{user.name}' is member of incorrect groups!"
This only compares the last group name. NSS/id group order may not match user_map list order. Safer: compare sets of names (or sorted lists) for user2 / user3.
Something like this,
assert result_user is not None, f"User '{user.name}' was not found!"
expected_names = set(expected_groups)
actual_names = {g.name for g in result_user.groups if g.name is not None}
assert actual_names == expected_names, (
f"User '{user.name}' group names from id {sorted(actual_names)!r} "
f"!= expected {sorted(expected_names)!r}"
)
| assert result.user.name == user, f"Username {result.user.name} is incorrect, {user} expected" | ||
| assert result.user.id == id, f"User id {result.user.id} is incorrect, {id} expected" | ||
| The word objects is used because it may add 'users' or 'groups'. It returns a dict of lists of objects, | ||
| so they can be used to retrieve uidNUmber and gidNumbers. |
There was a problem hiding this comment.
Typo in docstrings: uidNUmber → uidNumber
| client.sssd.domain["ldap_id_mapping"] = "false" | ||
| script = client.fs.mktmp(""" | ||
| #!/usr/bin/env python3 | ||
| import argparse |
There was a problem hiding this comment.
argparse is imported but unused.
| assert client.tools.getent.group(202020) is None, "Group with gid 202020 was found which is not expected" | ||
|
|
||
| assert_objects_not_found(client, objects, cache) | ||
|
|
There was a problem hiding this comment.
PEP 8: Missing a blank line between functions at ~401–402.
| assert_objects_not_found(client, objects, cache) | ||
|
|
||
| @pytest.mark.importance("critical") | ||
| @pytest.mark.cache |
There was a problem hiding this comment.
None of these tests use @pytest.mark.cache, are we dropping this marker?
|
Please make sure it will be green in IDM-CI also. |
No description provided.