mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Restore "gid_from_name" and put on a deprecation path
This argument was removed in 3001 with no deprecation path. This restores it and puts it on a proper deprecation path.
This commit is contained in:
parent
c1f6ebadab
commit
9b47f9c6cc
3 changed files with 64 additions and 0 deletions
3
changelog/57843.fixed
Normal file
3
changelog/57843.fixed
Normal file
|
@ -0,0 +1,3 @@
|
|||
The ``gid_from_name`` argument was removed from the ``user.present`` state in
|
||||
version 3001, with no deprecation path. It has been restored and put on a
|
||||
proper deprecation path.
|
|
@ -34,6 +34,7 @@ import salt.utils.data
|
|||
import salt.utils.dateutils
|
||||
import salt.utils.platform
|
||||
import salt.utils.user
|
||||
import salt.utils.versions
|
||||
from salt.exceptions import CommandExecutionError
|
||||
|
||||
# Import 3rd-party libs
|
||||
|
@ -272,6 +273,7 @@ def present(
|
|||
nologinit=False,
|
||||
allow_uid_change=False,
|
||||
allow_gid_change=False,
|
||||
**kwargs
|
||||
):
|
||||
"""
|
||||
Ensure that the named user is present with the specified properties
|
||||
|
@ -564,6 +566,28 @@ def present(
|
|||
name,
|
||||
)
|
||||
|
||||
# Warn until Silicon release, when old gid_from_name argument is used.
|
||||
# Since gid_from_name is the only thing that we're pulling from the kwargs,
|
||||
# we can also remove **kwargs from the function definition once we remove
|
||||
# the entire if block below. The following two tests will also become
|
||||
# redundant when this block is cleaned up:
|
||||
#
|
||||
# integration.states.test_user.UserTest.test_user_present_gid_from_name
|
||||
# integration.states.test_user.UserTest.test_user_present_gid_from_name_and_usergroup
|
||||
gid_from_name = kwargs.pop("gid_from_name", None)
|
||||
if gid_from_name is not None:
|
||||
msg = (
|
||||
"The 'gid_from_name' argument in the user.present state has "
|
||||
"been replaced with 'usergroup'"
|
||||
)
|
||||
if usergroup is not None:
|
||||
msg += ". Ignoring since 'usergroup' was also used."
|
||||
else:
|
||||
msg += ". Update your SLS file to get rid of this warning."
|
||||
usergroup = gid_from_name
|
||||
salt.utils.versions.warn_until("Silicon", msg)
|
||||
ret.setdefault("warnings", []).append(msg)
|
||||
|
||||
# If usergroup was specified, we'll also be creating a new
|
||||
# group. We should report this change without setting the gid
|
||||
# variable.
|
||||
|
|
|
@ -314,6 +314,42 @@ class UserTest(ModuleCase, SaltReturnAssertsMixin):
|
|||
user_info = self.run_function("user.info", [self.user_name])
|
||||
self.assertTrue(os.path.exists(user_info["home"]))
|
||||
|
||||
@skipIf(not salt.utils.platform.is_linux(), "only supported on linux")
|
||||
def test_user_present_gid_from_name(self):
|
||||
"""
|
||||
Test that gid_from_name results in warning, while it is on a
|
||||
deprecation path.
|
||||
"""
|
||||
# Add the user
|
||||
ret = self.run_state("user.present", name=self.user_name, gid_from_name=True)
|
||||
self.assertSaltTrueReturn(ret)
|
||||
ret = ret[next(iter(ret))]
|
||||
expected = [
|
||||
"The 'gid_from_name' argument in the user.present state has been "
|
||||
"replaced with 'usergroup'. Update your SLS file to get rid of "
|
||||
"this warning."
|
||||
]
|
||||
assert ret["warnings"] == expected, ret["warnings"]
|
||||
|
||||
@skipIf(not salt.utils.platform.is_linux(), "only supported on linux")
|
||||
def test_user_present_gid_from_name_and_usergroup(self):
|
||||
"""
|
||||
Test that gid_from_name results in warning, while it is on a
|
||||
deprecation path.
|
||||
"""
|
||||
# Add the user
|
||||
ret = self.run_state(
|
||||
"user.present", name=self.user_name, usergroup=True, gid_from_name=True
|
||||
)
|
||||
self.assertSaltTrueReturn(ret)
|
||||
ret = ret[next(iter(ret))]
|
||||
expected = [
|
||||
"The 'gid_from_name' argument in the user.present state has been "
|
||||
"replaced with 'usergroup'. Ignoring since 'usergroup' was also "
|
||||
"used."
|
||||
]
|
||||
assert ret["warnings"] == expected, ret["warnings"]
|
||||
|
||||
@skipIf(
|
||||
salt.utils.platform.is_windows() or salt.utils.platform.is_darwin(),
|
||||
"groups/gid not fully supported",
|
||||
|
@ -381,6 +417,7 @@ class UserTest(ModuleCase, SaltReturnAssertsMixin):
|
|||
if USER in check_user:
|
||||
del_user = self.run_function("user.delete", [USER], remove=True)
|
||||
self.assertSaltTrueReturn(self.run_state("user.absent", name=self.user_name))
|
||||
self.assertSaltTrueReturn(self.run_state("group.absent", name=self.user_name))
|
||||
|
||||
|
||||
@destructiveTest
|
||||
|
|
Loading…
Add table
Reference in a new issue