Skip to content

tests: add pysss_nss_idmap system test#8133

Merged
thalman merged 2 commits intoSSSD:masterfrom
sumit-bose:test_pysss_nss_idmap
Nov 13, 2025
Merged

tests: add pysss_nss_idmap system test#8133
thalman merged 2 commits intoSSSD:masterfrom
sumit-bose:test_pysss_nss_idmap

Conversation

@sumit-bose
Copy link
Contributor

The new system test is mostly a 1:1 replacement of the exisintg integration test.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds a new system test for pysss_nss_idmap, which is a good addition to ensure the functionality is covered. The tests are comprehensive. My main feedback is to refactor the assertions to be more robust and readable by parsing the command output into Python objects instead of comparing raw strings. This will make the tests easier to maintain in the long run.


from __future__ import annotations

import pytest

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The ast module is needed to safely evaluate the string representation of Python literals from the command output. This is a more robust way to check test results than string concatenation.

Suggested change
import pytest
import pytest
import ast

Comment on lines +153 to +189
output = client.host.conn.run(
f"""python -c 'import pysss_nss_idmap; print(pysss_nss_idmap.getsidbyname("{group.name}"))'"""
)
assert output.stdout == "{'" + group.name + "': {'sid': '" + group_sid + "', 'type': 2}}"

output = client.host.conn.run(
f"""python -c 'import pysss_nss_idmap; print(pysss_nss_idmap.getsidbygroupname("{group.name}"))'"""
)
assert output.stdout == "{'" + group.name + "': {'sid': '" + group_sid + "', 'type': 2}}"

output = client.host.conn.run(
f"""python -c 'import pysss_nss_idmap; print(pysss_nss_idmap.getsidbyusername("{group.name}"))'"""
)
assert output.stdout == "{}"

output = client.host.conn.run(f"python -c 'import pysss_nss_idmap; print(pysss_nss_idmap.getsidbyid({group_id}))'")
assert output.stdout == "{" + str(group_id) + ": {'sid': '" + group_sid + "', 'type': 2}}"

output = client.host.conn.run(
f"python -c 'import pysss_nss_idmap; print(pysss_nss_idmap.getsidbygid({group_id}))'"
)
assert output.stdout == "{" + str(group_id) + ": {'sid': '" + group_sid + "', 'type': 2}}"

output = client.host.conn.run(
f"python -c 'import pysss_nss_idmap; print(pysss_nss_idmap.getsidbyuid({group_id}))'"
)
assert output.stdout == "{}"

output = client.host.conn.run(
f"""python -c 'import pysss_nss_idmap; print(pysss_nss_idmap.getidbysid("{group_sid}"))'"""
)
assert output.stdout == "{'" + group_sid + "': {'id': " + str(group_id) + ", 'type': 2}}"

output = client.host.conn.run(
f"""python -c 'import pysss_nss_idmap; print(pysss_nss_idmap.getnamebysid("{group_sid}"))'"""
)
assert output.stdout == "{'" + group_sid + "': {'name': '" + group.name + "', 'type': 2}}"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Similar to the user operations test, using ast.literal_eval() to parse the output and compare with a dictionary will make these assertions more robust and readable.

    output = client.host.conn.run(
        f"""python -c 'import pysss_nss_idmap; print(pysss_nss_idmap.getsidbyname(\"{group.name}\"))'"""
    )
    assert ast.literal_eval(output.stdout) == {group.name: {"sid": group_sid, "type": 2}}

    output = client.host.conn.run(
        f"""python -c 'import pysss_nss_idmap; print(pysss_nss_idmap.getsidbygroupname(\"{group.name}\"))'"""
    )
    assert ast.literal_eval(output.stdout) == {group.name: {"sid": group_sid, "type": 2}}

    output = client.host.conn.run(
        f"""python -c 'import pysss_nss_idmap; print(pysss_nss_idmap.getsidbyusername(\"{group.name}\"))'"""
    )
    assert ast.literal_eval(output.stdout) == {}

    output = client.host.conn.run(f"python -c 'import pysss_nss_idmap; print(pysss_nss_idmap.getsidbyid({group_id}))'")
    assert ast.literal_eval(output.stdout) == {group_id: {"sid": group_sid, "type": 2}}

    output = client.host.conn.run(
        f"python -c 'import pysss_nss_idmap; print(pysss_nss_idmap.getsidbygid({group_id}))'"
    )
    assert ast.literal_eval(output.stdout) == {group_id: {"sid": group_sid, "type": 2}}

    output = client.host.conn.run(
        f"python -c 'import pysss_nss_idmap; print(pysss_nss_idmap.getsidbyuid({group_id}))'"
    )
    assert ast.literal_eval(output.stdout) == {}

    output = client.host.conn.run(
        f"""python -c 'import pysss_nss_idmap; print(pysss_nss_idmap.getidbysid(\"{group_sid}\"))'"""
    )
    assert ast.literal_eval(output.stdout) == {group_sid: {"id": group_id, "type": 2}}

    output = client.host.conn.run(
        f"""python -c 'import pysss_nss_idmap; print(pysss_nss_idmap.getnamebysid(\"{group_sid}\"))'"""
    )
    assert ast.literal_eval(output.stdout) == {group_sid: {"name": group.name, "type": 2}}

@sumit-bose
Copy link
Contributor Author

Hi @danlavu and @pbrezina ,

what do you think about the suggestion from Gemini to use ast. Is this something which can be used in the test or do you prefer to not use it?

bye,
Sumit

@danlavu
Copy link

danlavu commented Oct 15, 2025

Hi @danlavu and @pbrezina ,

what do you think about the suggestion from Gemini to use ast. Is this something which can be used in the test or do you prefer to not use it?

bye, Sumit

I'm not familiar with it, but everything I'm reading about it makes sense to use it, and I do like the assertions a lot better in the provided examples. I'll defer this to @pbrezina.

@sumit-bose sumit-bose force-pushed the test_pysss_nss_idmap branch 2 times, most recently from d1a4f9a to 2f11c5d Compare October 22, 2025 14:17
Copy link

@danlavu danlavu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is way better. A couple of implementation questions in line.

3. no result
:customerscenario: False
"""

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's mostly about conformity, so if we extended the framework, we could keep user/group creation as part of the test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not understand this comment?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking two different things and jumbled them into one sentence, I'm sorry. This is no longer relevant because we're not updating the framework now, but I was suggesting that.

The bulk the user setup code is getting the user and group sid. If we added user.sid/group.sid. We then can conform to other tests and add some readability. Because it wouldn't be a lot of lines to then retain the explicit user/group setup in the test code.

@pbrezina pbrezina force-pushed the master branch 2 times, most recently from f5d64b3 to b854636 Compare November 4, 2025 14:27
@sumit-bose sumit-bose force-pushed the test_pysss_nss_idmap branch 2 times, most recently from fd2d84c to 6271313 Compare November 5, 2025 11:33
Copy link

@danlavu danlavu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you Sumit!

Copy link
Contributor

@thalman thalman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks Sumit

The new system test is mostly a 1:1 replacement of the exisintg
integration test.

Reviewed-by: Dan Lavu <dlavu@redhat.com>
Reviewed-by: Tomáš Halman <thalman@redhat.com>
Reviewed-by: Dan Lavu <dlavu@redhat.com>
Reviewed-by: Tomáš Halman <thalman@redhat.com>
@sssd-bot
Copy link
Contributor

The pull request was accepted by @thalman with the following PR CI status:


🟢 CodeFactor (success)
🟢 CodeQL (success)
NEUTRAL osh-diff-scan:fedora-rawhide-x86_64:upstream (neutral)
🟢 rpm-build:centos-stream-10-x86_64:upstream (success)
🟢 rpm-build:fedora-41-x86_64:upstream (success)
🟢 rpm-build:fedora-42-x86_64:upstream (success)
🟢 rpm-build:fedora-43-x86_64:upstream (success)
🟢 rpm-build:fedora-rawhide-x86_64:upstream (success)
🟢 Analyze (target) / All tests are successful (success)
🟢 Analyze (target) / cppcheck (success)
🟢 Build / freebsd (success)
🟢 Build / make-distcheck (success)
🔴 ci / All tests are successful (failure)
🟢 ci / intgcheck (centos-10) (success)
🟢 ci / intgcheck (fedora-41) (success)
🔴 ci / intgcheck (fedora-42) (failure)
🟢 ci / intgcheck (fedora-43) (success)
🟢 ci / intgcheck (fedora-44) (success)
🟢 ci / prepare (success)
🟢 ci / system (centos-10) (success)
🟢 ci / system (fedora-41) (success)
🟢 ci / system (fedora-42) (success)
🟢 ci / system (fedora-43) (success)
🟢 ci / system (fedora-44) (success)
➖ Coverity scan / coverity (skipped)
🟢 Static code analysis / All tests are successful (success)
🟢 Static code analysis / codeql (success)
🟢 Static code analysis / pre-commit (success)
🟢 Static code analysis / python-system-tests (success)


There are unsuccessful or unfinished checks. Make sure that the failures are not related to this pull request before merging.

@sssd-bot sssd-bot force-pushed the test_pysss_nss_idmap branch from 6271313 to ac89ea8 Compare November 12, 2025 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants