Skip to content

Commit

Permalink
distro(freebsd): add_user: respect homedir (#5061)
Browse files Browse the repository at this point in the history
reportedly, passing `homedir` to a user struct doesn't actually change
the homedir to the desired value. This is because we hard-code the path.
Respect the value we are passed, and only make up a default when we
don't get a `homedir`.

Simplify style to remove cerimonious verbosity around strings, and amend
tests to verify what we did.

Sponsored by: The FreeBSD Foundation
  • Loading branch information
igalic committed Mar 16, 2024
1 parent 3ad7f28 commit 82a5fb3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
10 changes: 3 additions & 7 deletions cloudinit/distros/freebsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,10 @@ def add_user(self, name, **kwargs):
pw_useradd_cmd.append("-d/nonexistent")
log_pw_useradd_cmd.append("-d/nonexistent")
else:
pw_useradd_cmd.append(
"-d{home_dir}/{name}".format(home_dir=self.home_dir, name=name)
)
homedir = kwargs.get("homedir", f"{self.home_dir}/{name}")
pw_useradd_cmd.append("-d" + homedir)
pw_useradd_cmd.append("-m")
log_pw_useradd_cmd.append(
"-d{home_dir}/{name}".format(home_dir=self.home_dir, name=name)
)

log_pw_useradd_cmd.append("-d" + homedir)
log_pw_useradd_cmd.append("-m")

# Run the command
Expand Down
2 changes: 2 additions & 0 deletions tests/unittests/config/test_cc_users_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def test_handle_users_in_cfg_calls_create_users_on_bsd(
"lock_passwd": True,
"groups": ["wheel"],
"shell": "/bin/tcsh",
"homedir": "/home/freebsd",
}
}
metadata = {}
Expand All @@ -116,6 +117,7 @@ def test_handle_users_in_cfg_calls_create_users_on_bsd(
groups="wheel",
lock_passwd=True,
shell="/bin/tcsh",
homedir="/home/freebsd",
),
mock.call("me2", uid=1234, default=False),
],
Expand Down

0 comments on commit 82a5fb3

Please sign in to comment.