Skip to content

Tests: Add system tests for groupadd in test_groupadd.py - #1693

Open
asakure wants to merge 4 commits into
shadow-maint:masterfrom
asakure:system_tests_groupadd_22_23_24
Open

Tests: Add system tests for groupadd in test_groupadd.py#1693
asakure wants to merge 4 commits into
shadow-maint:masterfrom
asakure:system_tests_groupadd_22_23_24

Conversation

@asakure

@asakure asakure commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Add system tests for groupadd in test_groupadd.py for
existing bash tests with numbering 22, 23, 24.

@asakure
asakure marked this pull request as ready for review July 23, 2026 15:01
@asakure
asakure force-pushed the system_tests_groupadd_22_23_24 branch from cbb8850 to d010ea7 Compare August 26, 2026 06:02
Comment thread tests/system/tests/test_groupadd.py
Comment thread tests/system/framework/roles/shadow.py Outdated
Comment thread tests/system/tests/test_groupadd.py Outdated
@asakure
asakure force-pushed the system_tests_groupadd_22_23_24 branch 3 times, most recently from 8b0a946 to 0c8cf07 Compare August 27, 2026 08:28
Comment thread tests/system/tests/test_groupadd.py Outdated
Comment on lines +503 to +504
shadow.groupadd()
assert exc_info.value.rc == 2, f"Expected return code 2(invalid usage), got {exc_info.value.rc}"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Add an empty line between these two

Comment thread tests/system/framework/roles/shadow.py Outdated
Comment on lines +50 to +51
args_list = shlex.split(args[0][0] if args[0] else "")
name = args_list[-1] if args_list else ""

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

args[0][0] takes the first character of the argument, not the whole argument string.

I think a good approach would be to have the defensive programming first and then handle the parsing:

if not args or not args[0]:
    return {"name": ""}

args_list = shlex.split(args[0])
name = args_list[-1] if args_list else ""

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hi @ikerexxe with this change, test fails with error:

FAILED tests/test_groupadd_working.py::test_groupadd__no_group (shadow) - IndexError: tuple index out of range

I think an additional change would be required here:

cmd = self.host.conn.run("groupadd " + args[0], log_level=ProcessLogLevel.Error)
? Kindly suggest.

Comment thread tests/system/tests/test_groupadd.py Outdated
@pytest.mark.topology(KnownTopology.Shadow)
def test_groupadd__usage(shadow: Shadow):
"""
:title: Groupadd command displays usage with -h option and exits successfully

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Let's avoid using -h option and only state what the test does display usage

Comment thread tests/system/tests/test_groupadd.py Outdated
:setup:
1. None required
:steps:
1. Run groupadd command with -h option

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

No need to mention with -h option, as that's the how

1. None required
:steps:
1. Run groupadd command with -h option
2. Verify that groupadd command exits successfully

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You are missing an additional step here: Check usage information

Comment thread tests/system/tests/test_groupadd.py Outdated
1. Run groupadd command with -h option
2. Verify that groupadd command exits successfully
:expectedresults:
1. Command shows usage help

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'd say this should be Command runs successfully

Comment thread tests/system/tests/test_groupadd.py Outdated
2. Verify that groupadd command exits successfully
:expectedresults:
1. Command shows usage help
2. groupadd command completes successfully and displays usage information

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

In this step you are checking that the command run successfully, thus update the message accordingly

:expectedresults:
1. Command shows usage help
2. groupadd command completes successfully and displays usage information
:customerscenario: False

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Missing another step here to Check usage information

Comment thread tests/system/tests/test_groupadd.py Outdated
)
def test_groupadd__invalid_usage(shadow: Shadow, args: str):
"""
:title: Groupadd command fails with invalid usage

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

s/usage/arguments

Comment thread tests/system/tests/test_groupadd.py Outdated
1. Run groupadd command with invalid arguments
2. Verify that groupadd command fails
:expectedresults:
1. Command with invalid argument fails

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'd say this should be Attempt to create groups or something similar

This is Python transformation of the test located in
`tests/grouptools/groupadd/22_groupadd_usage/groupadd.test`
which checks that `groupadd` command shows usage with -h option.

Signed-off-by: Akshay Sakure <asakure@redhat.com>
This patch fixes the issue in shadow.py file to handle
empty or missing arguments in _parse_args and groupadd
so shadow.groupadd() does not raise TypeError or IndexError.

Signed-off-by: Akshay Sakure <asakure@redhat.com>
This is Python transformation of the test located in
`tests/grouptools/groupadd/23_groupadd_no_groups/groupadd.test`
which checks that `groupadd` fails when no groupname is
mentioned.

Signed-off-by: Akshay Sakure <asakure@redhat.com>
This is Python transformation of the test located in
`tests/grouptools/groupadd/24_groupadd_2_groups/groupadd.test`
which checks that `groupadd` command fails when two groupnames
are mentioned. It also parametrize python tests 23 and 24 into
single test.

Signed-off-by: Akshay Sakure <asakure@redhat.com>
@asakure
asakure force-pushed the system_tests_groupadd_22_23_24 branch from 0c8cf07 to e632b96 Compare August 27, 2026 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants