Deprecate runas usage on salt.states.postgres_group. Refs #6961.

This commit is contained in:
Pedro Algarvio 2013-09-20 17:06:43 +01:00
parent 0eebb64439
commit d959456e2a

View File

@ -11,6 +11,8 @@ The postgres_group module is used to create and manage Postgres groups.
postgres_group.present
'''
# Import salt libs
import salt.utils
def __virtual__():
'''
@ -27,7 +29,8 @@ def present(name,
replication=False,
password=None,
groups=None,
runas=None):
runas=None,
user=None):
'''
Ensure that the named group is present with the specified privileges
@ -57,14 +60,45 @@ def present(name,
runas
System user all operations should be performed on behalf of
.. deprecated:: 0.17.0
user
System user all operations should be performed on behalf of
.. versionadded:: 0.17.0
'''
ret = {'name': name,
'changes': {},
'result': True,
'comment': 'Group {0} is already present'.format(name)}
salt.utils.warn_until(
(0, 19),
'Please remove \'runas\' support at this stage. \'user\' support was '
'added in 0.17.0',
_dont_call_warnings=True
)
if runas:
# Warn users about the deprecation
ret.setdefault('warnings', []).append(
'The \'runas\' argument is being deprecated in favor or \'user\', '
'please update your state files.'
)
if user is not None and runas is not None:
# user wins over runas but let warn about the deprecation.
ret.setdefault('warnings', []).append(
'Passed both the \'runas\' and \'user\' arguments. Please don\'t. '
'\'runas\' is being ignored in favor of \'user\'.'
)
runas = None
elif runas is not None:
# Support old runas usage
user = runas
runas = None
# check if user exists
if __salt__['postgres.user_exists'](name, runas=runas):
if __salt__['postgres.user_exists'](name, runas=user):
return ret
# The user is not present, make it!
@ -80,7 +114,7 @@ def present(name,
replication=replication,
rolepassword=password,
groups=groups,
runas=runas):
runas=user):
ret['comment'] = 'The group {0} has been created'.format(name)
ret['changes'][name] = 'Present'
else:
@ -90,7 +124,7 @@ def present(name,
return ret
def absent(name, runas=None):
def absent(name, runas=None, user=None):
'''
Ensure that the named group is absent
@ -99,19 +133,50 @@ def absent(name, runas=None):
runas
System user all operations should be performed on behalf of
.. deprecated:: 0.17.0
user
System user all operations should be performed on behalf of
.. versionadded:: 0.17.0
'''
ret = {'name': name,
'changes': {},
'result': True,
'comment': ''}
salt.utils.warn_until(
(0, 19),
'Please remove \'runas\' support at this stage. \'user\' support was '
'added in 0.17.0',
_dont_call_warnings=True
)
if runas:
# Warn users about the deprecation
ret.setdefault('warnings', []).append(
'The \'runas\' argument is being deprecated in favor or \'user\', '
'please update your state files.'
)
if user is not None and runas is not None:
# user wins over runas but let warn about the deprecation.
ret.setdefault('warnings', []).append(
'Passed both the \'runas\' and \'user\' arguments. Please don\'t. '
'\'runas\' is being ignored in favor of \'user\'.'
)
runas = None
elif runas is not None:
# Support old runas usage
user = runas
runas = None
# check if group exists and remove it
if __salt__['postgres.user_exists'](name, runas=runas):
if __salt__['postgres.user_exists'](name, runas=user):
if __opts__['test']:
ret['result'] = None
ret['comment'] = 'Group {0} is set to be removed'.format(name)
return ret
if __salt__['postgres.group_remove'](name, runas=runas):
if __salt__['postgres.group_remove'](name, runas=user):
ret['comment'] = 'Group {0} has been removed'.format(name)
ret['changes'][name] = 'Absent'
return ret