Skip to content
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

Query all usernames and group names #711

Merged
merged 1 commit into from
Mar 29, 2025

Conversation

CarstenGrohmann
Copy link
Contributor

@CarstenGrohmann CarstenGrohmann commented Jun 27, 2023

We need some functionality to query all user names as well as all group names. I implemented in two functions:

  • query all (local and remove) users and groups with getent passwd resp. getent group
  • query local users and groups with cat /etc/passwd resp. cat /etc/group

Small tests of all functions are also part of this pull request.

What do you think about such functionality?

@philpep philpep added feature enhancement This issue/PR relates to a feature request. and removed feature labels Aug 24, 2023
"""
all_users = [
line.split(":")[0]
for line in self.check_output("getent passwd").splitlines()
Copy link
Contributor

@martinhoyer martinhoyer Jun 12, 2024

Choose a reason for hiding this comment

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

I think we could use pwd?

import pwd
all_users = [pw.pw_name for pw in pwd.getpwall()]

(same with grp for groups)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, this is not possible because testinfra only executes Unix commands on the remote host.

@philpep philpep force-pushed the add_get_all_users branch from 4fa35c1 to 2e0e478 Compare March 29, 2025 14:03
@philpep philpep merged commit 4a5fa6e into pytest-dev:main Mar 29, 2025
7 checks passed
@philpep
Copy link
Contributor

philpep commented Mar 29, 2025

Merged, thanks!

@CarstenGrohmann CarstenGrohmann deleted the add_get_all_users branch March 30, 2025 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This issue/PR relates to a feature request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants