Replace "pchanges" with "changes" to fix onchanges/prereq requisites

Since "pchanges" was never supported in the state compiler, and
"changes" is what these reqs always used, replacing "pchanges" with
"changes" will allow those requisites to work in test mode.

Conflicts:
  - salt/states/file.py
  - salt/states/linux_acl.py
  - salt/utils/napalm.py
  - tests/integration/modules/test_state.py
  - tests/unit/states/test_file.py
This commit is contained in:
Erik Johnson 2018-09-27 23:12:58 -05:00 committed by Ch3LL
parent 21d63656c1
commit 6db2beb6c0
No known key found for this signature in database
GPG key ID: 132B55A7C13EFA73
37 changed files with 290 additions and 457 deletions

View file

@ -259,10 +259,6 @@ A State Module must return a dict containing the following keys/values:
Prefer to keep line lengths short (use multiple lines as needed),
and end with punctuation (e.g. a period) to delimit multiple comments.
The return data can also, include the **pchanges** key, this stands for
`predictive changes`. The **pchanges** key informs the State system what
changes are predicted to occur.
.. note::
States should not return data which cannot be serialized such as frozensets.
@ -448,7 +444,6 @@ Example state module
'changes': {},
'result': False,
'comment': '',
'pchanges': {},
}
# Start with basic error-checking. Do all the passed parameters make sense
@ -469,7 +464,7 @@ Example state module
# in ``test=true`` mode.
if __opts__['test'] == True:
ret['comment'] = 'The state of "{0}" will be changed.'.format(name)
ret['pchanges'] = {
ret['changes'] = {
'old': current_state,
'new': 'Description, diff, whatever of the new state',
}

View file

@ -1436,25 +1436,19 @@ def extracted(name,
dir_result = __states__['file.directory'](full_path,
user=user,
group=group,
recurse=recurse,
test=__opts__['test'])
recurse=recurse)
log.debug('file.directory: %s', dir_result)
if __opts__['test']:
if dir_result.get('pchanges'):
ret['changes']['updated ownership'] = True
else:
try:
if dir_result['result']:
if dir_result['changes']:
ret['changes']['updated ownership'] = True
else:
enforce_failed.append(full_path)
except (KeyError, TypeError):
log.warning(
'Bad state return %s for file.directory state on %s',
dir_result, dirname
)
if dir_result.get('changes'):
ret['changes']['updated ownership'] = True
try:
if not dir_result['result']:
enforce_failed.append(full_path)
except (KeyError, TypeError):
log.warning(
'Bad state return %s for file.directory state on %s',
dir_result, dirname
)
for filename in enforce_files + enforce_links:
full_path = os.path.join(name, filename)

View file

@ -135,7 +135,7 @@ def present(
if __opts__['test']:
ret['result'] = None
ret['comment'] = 'Distribution {0} set for creation.'.format(name)
ret['pchanges'] = {'old': None, 'new': name}
ret['changes'] = {'old': None, 'new': name}
return ret
res = __salt__['boto_cloudfront.create_distribution'](
@ -203,7 +203,7 @@ def present(
'Distribution {0} set for new config:'.format(name),
changes_diff,
])
ret['pchanges'] = {'diff': changes_diff}
ret['changes'] = {'diff': changes_diff}
return ret
res = __salt__['boto_cloudfront.update_distribution'](

View file

@ -282,7 +282,7 @@ def object_present(
ret['result'] = None
ret['comment'] = 'S3 object {0} set to be {1}d.'.format(name, action)
ret['comment'] += '\nChanges:\n{0}'.format(changes_diff)
ret['pchanges'] = {'diff': changes_diff}
ret['changes'] = {'diff': changes_diff}
return ret
r = __salt__['boto_s3.upload_file'](

View file

@ -136,7 +136,7 @@ def present(
ret['comment'].append(
'SQS queue {0} is set to be created.'.format(name),
)
ret['pchanges'] = {'old': None, 'new': name}
ret['changes'] = {'old': None, 'new': name}
return ret
r = __salt__['boto_sqs.create'](
@ -225,7 +225,7 @@ def present(
attributes_diff,
)
)
ret['pchanges'] = {'attributes': {'diff': attributes_diff}}
ret['changes'] = {'attributes': {'diff': attributes_diff}}
return ret
r = __salt__['boto_sqs.set_attributes'](
@ -300,7 +300,7 @@ def absent(
if __opts__['test']:
ret['result'] = None
ret['comment'] = 'SQS queue {0} is set to be removed.'.format(name)
ret['pchanges'] = {'old': name, 'new': None}
ret['changes'] = {'old': name, 'new': None}
return ret
r = __salt__['boto_sqs.delete'](

View file

@ -336,7 +336,6 @@ def upgraded(name,
ret = {'name': name,
'result': True,
'changes': {},
'pchanges': {},
'comment': ''}
# Get list of currently installed packages
@ -346,12 +345,10 @@ def upgraded(name,
# Package not installed
if name.lower() not in [package.lower() for package in pre_install.keys()]:
if version:
ret['pchanges'] = {
name: 'Version {0} will be installed'.format(version)
}
ret['changes'][name] = 'Version {0} will be installed'.format(version)
ret['comment'] = 'Install version {0}'.format(version)
else:
ret['pchanges'] = {name: 'Latest version will be installed'}
ret['changes'][name] = 'Latest version will be installed'
ret['comment'] = 'Install latest version'
# Package installed
@ -378,8 +375,7 @@ def upgraded(name,
oper="==",
ver2=version):
if force:
ret['pchanges'] = {
name: 'Version {0} will be reinstalled'.format(version)}
ret['changes'][name] = 'Version {0} will be reinstalled'.format(version)
ret['comment'] = 'Reinstall {0} {1}'.format(full_name, version)
else:
ret['comment'] = '{0} {1} is already installed'.format(
@ -389,11 +385,9 @@ def upgraded(name,
# If installed version is older than new version
if salt.utils.versions.compare(
ver1=installed_version, oper="<", ver2=version):
ret['pchanges'] = {
name: 'Version {0} will be upgraded to Version {1}'.format(
installed_version, version
)
}
ret['changes'][name] = 'Version {0} will be upgraded to Version {1}'.format(
installed_version, version
)
ret['comment'] = 'Upgrade {0} {1} to {2}'.format(
full_name, installed_version, version
)
@ -409,13 +403,13 @@ def upgraded(name,
else:
ret['comment'] = 'No version found to install'
# Return if `test=True`
if __opts__['test']:
ret['result'] = None
# Return if there are no changes to be made
if not ret['changes']:
return ret
# Return if there are no changes to be made
if not ret['pchanges']:
# Return if running in test mode
if __opts__['test']:
ret['result'] = None
return ret
# Install the package
@ -439,6 +433,9 @@ def upgraded(name,
# Get list of installed packages after 'chocolatey.install'
post_install = __salt__['chocolatey.list'](local_only=True)
# Prior to this, ret['changes'] would have contained expected changes,
# replace them with the actual changes now that we have completed the
# installation.
ret['changes'] = salt.utils.data.compare_dicts(pre_install, post_install)
return ret

View file

@ -401,13 +401,11 @@ def dvs_configured(name, dvs):
''.format(dvs_name, datacenter_name)),
'result': True})
else:
ret.update({'comment': '\n'.join(comments)})
if __opts__['test']:
ret.update({'pchanges': changes,
'result': None})
else:
ret.update({'changes': changes,
'result': True})
ret.update({
'comment': '\n'.join(comments),
'changes': changes,
'result': None if __opts__['test'] else True,
})
return ret
@ -512,8 +510,10 @@ def portgroups_configured(name, dvs, portgroups):
log.info('Running state {0} on DVS \'{1}\', datacenter '
'\'{2}\''.format(name, dvs, datacenter))
changes_required = False
ret = {'name': name, 'changes': {}, 'result': None, 'comment': None,
'pchanges': {}}
ret = {'name': name,
'changes': {},
'result': None,
'comment': None}
comments = []
changes = {}
changes_required = False
@ -623,13 +623,11 @@ def portgroups_configured(name, dvs, portgroups):
'Nothing to be done.'.format(dvs, datacenter)),
'result': True})
else:
ret.update({'comment': '\n'.join(comments)})
if __opts__['test']:
ret.update({'pchanges': changes,
'result': None})
else:
ret.update({'changes': changes,
'result': True})
ret.update({
'comment': '\n'.join(comments),
'changes': changes,
'result': None if __opts__['test'] else True,
})
return ret
@ -649,8 +647,10 @@ def uplink_portgroup_configured(name, dvs, uplink_portgroup):
log.info('Running {0} on DVS \'{1}\', datacenter \'{2}\''
''.format(name, dvs, datacenter))
changes_required = False
ret = {'name': name, 'changes': {}, 'result': None, 'comment': None,
'pchanges': {}}
ret = {'name': name,
'changes': {},
'result': None,
'comment': None}
comments = []
changes = {}
changes_required = False
@ -708,11 +708,9 @@ def uplink_portgroup_configured(name, dvs, uplink_portgroup):
'Nothing to be done.'.format(dvs, datacenter)),
'result': True})
else:
ret.update({'comment': '\n'.join(comments)})
if __opts__['test']:
ret.update({'pchanges': changes,
'result': None})
else:
ret.update({'changes': changes,
'result': True})
ret.update({
'comment': '\n'.join(comments),
'changes': changes,
'result': None if __opts__['test'] else True,
})
return ret

View file

@ -89,11 +89,11 @@ def datacenter_configured(name):
dc_name = name
log.info('Running datacenter_configured for datacenter \'{0}\''
''.format(dc_name))
ret = {'name': name, 'changes': {}, 'pchanges': {},
'result': None, 'comment': 'Default'}
ret = {'name': name,
'changes': {},
'result': None,
'comment': 'Default'}
comments = []
changes = {}
pchanges = {}
si = None
try:
si = __salt__['vsphere.get_service_instance_via_proxy']()
@ -103,27 +103,19 @@ def datacenter_configured(name):
if __opts__['test']:
comments.append('State will create '
'datacenter \'{0}\'.'.format(dc_name))
log.info(comments[-1])
pchanges.update({'new': {'name': dc_name}})
else:
log.debug('Creating datacenter \'{0}\'. '.format(dc_name))
__salt__['vsphere.create_datacenter'](dc_name, si)
comments.append('Created datacenter \'{0}\'.'.format(dc_name))
log.info(comments[-1])
changes.update({'new': {'name': dc_name}})
log.info(comments[-1])
ret['changes'].update({'new': {'name': dc_name}})
else:
comments.append('Datacenter \'{0}\' already exists. Nothing to be '
'done.'.format(dc_name))
log.info(comments[-1])
__salt__['vsphere.disconnect'](si)
if __opts__['test'] and pchanges:
ret_status = None
else:
ret_status = True
ret.update({'result': ret_status,
'comment': '\n'.join(comments),
'changes': changes,
'pchanges': pchanges})
ret['comment'] = '\n'.join(comments)
ret['result'] = None if __opts__['test'] and ret['changes'] else True
return ret
except salt.exceptions.CommandExecutionError as exc:
log.error('Error: {}'.format(exc))

View file

@ -1070,8 +1070,10 @@ def diskgroups_configured(name, diskgroups, erase_disks=False):
else proxy_details['esxi_host']
log.info('Running state {0} for host \'{1}\''.format(name, hostname))
# Variable used to return the result of the invocation
ret = {'name': name, 'result': None, 'changes': {},
'pchanges': {}, 'comments': None}
ret = {'name': name,
'result': None,
'changes': {},
'comments': None}
# Signals if errors have been encountered
errors = False
# Signals if changes are required
@ -1294,12 +1296,8 @@ def diskgroups_configured(name, diskgroups, erase_disks=False):
None if __opts__['test'] else # running in test mode
False if errors else True) # found errors; defaults to True
ret.update({'result': result,
'comment': '\n'.join(comments)})
if changes:
if __opts__['test']:
ret['pchanges'] = diskgroup_changes
elif changes:
ret['changes'] = diskgroup_changes
'comment': '\n'.join(comments),
'changes': diskgroup_changes})
return ret
@ -1387,8 +1385,10 @@ def host_cache_configured(name, enabled, datastore, swap_size='100%',
else proxy_details['esxi_host']
log.trace('hostname = %s', hostname)
log.info('Running host_cache_swap_configured for host \'%s\'', hostname)
ret = {'name': hostname, 'comment': 'Default comments',
'result': None, 'changes': {}, 'pchanges': {}}
ret = {'name': hostname,
'comment': 'Default comments',
'result': None,
'changes': {}}
result = None if __opts__['test'] else True # We assume success
needs_setting = False
comments = []
@ -1582,11 +1582,8 @@ def host_cache_configured(name, enabled, datastore, swap_size='100%',
__salt__['vsphere.disconnect'](si)
log.info(comments[-1])
ret.update({'comment': '\n'.join(comments),
'result': result})
if __opts__['test']:
ret['pchanges'] = changes
else:
ret['changes'] = changes
'result': result,
'changes': changes})
return ret
except CommandExecutionError as err:
log.error('Error: %s.', err)

View file

@ -1031,36 +1031,36 @@ def _symlink_check(name, target, force, user, group, win_owner):
'''
Check the symlink function
'''
pchanges = {}
changes = {}
if not os.path.exists(name) and not __salt__['file.is_link'](name):
pchanges['new'] = name
changes['new'] = name
return None, 'Symlink {0} to {1} is set for creation'.format(
name, target
), pchanges
), changes
if __salt__['file.is_link'](name):
if __salt__['file.readlink'](name) != target:
pchanges['change'] = name
changes['change'] = name
return None, 'Link {0} target is set to be changed to {1}'.format(
name, target
), pchanges
), changes
else:
result = True
msg = 'The symlink {0} is present'.format(name)
if not _check_symlink_ownership(name, user, group, win_owner):
result = None
pchanges['ownership'] = '{0}:{1}'.format(*_get_symlink_ownership(name))
changes['ownership'] = '{0}:{1}'.format(*_get_symlink_ownership(name))
msg += (
', but the ownership of the symlink would be changed '
'from {2}:{3} to {0}:{1}'
).format(user, group, *_get_symlink_ownership(name))
return result, msg, pchanges
return result, msg, changes
else:
if force:
return None, ('The file or directory {0} is set for removal to '
'make way for a new symlink targeting {1}'
.format(name, target)), pchanges
.format(name, target)), changes
return False, ('File or directory exists where the symlink {0} '
'should be. Did you mean to use force?'.format(name)), pchanges
'should be. Did you mean to use force?'.format(name)), changes
def _test_owner(kwargs, user=None):
@ -1222,12 +1222,12 @@ def _shortcut_check(name,
'''
Check the shortcut function
'''
pchanges = {}
changes = {}
if not os.path.exists(name):
pchanges['new'] = name
changes['new'] = name
return None, 'Shortcut "{0}" to "{1}" is set for creation'.format(
name, target
), pchanges
), changes
if os.path.isfile(name):
with salt.utils.winapi.Com():
@ -1248,28 +1248,28 @@ def _shortcut_check(name,
)
if not all(state_checks):
pchanges['change'] = name
changes['change'] = name
return None, 'Shortcut "{0}" target is set to be changed to "{1}"'.format(
name, target
), pchanges
), changes
else:
result = True
msg = 'The shortcut "{0}" is present'.format(name)
if not _check_shortcut_ownership(name, user):
result = None
pchanges['ownership'] = '{0}'.format(_get_shortcut_ownership(name))
changes['ownership'] = '{0}'.format(_get_shortcut_ownership(name))
msg += (
', but the ownership of the shortcut would be changed '
'from {1} to {0}'
).format(user, _get_shortcut_ownership(name))
return result, msg, pchanges
return result, msg, changes
else:
if force:
return None, ('The link or directory "{0}" is set for removal to '
'make way for a new shortcut targeting "{1}"'
.format(name, target)), pchanges
.format(name, target)), changes
return False, ('Link or directory exists where the shortcut "{0}" '
'should be. Did you mean to use force?'.format(name)), pchanges
'should be. Did you mean to use force?'.format(name)), changes
def _makedirs(name,
@ -1499,12 +1499,12 @@ def symlink(
msg += '.'
return _error(ret, msg)
presult, pcomment, ret['pchanges'] = _symlink_check(name,
target,
force,
user,
group,
win_owner)
presult, pcomment, pchanges = _symlink_check(name,
target,
force,
user,
group,
win_owner)
if not os.path.isdir(os.path.dirname(name)):
if makedirs:
@ -1537,6 +1537,7 @@ def symlink(
if __opts__['test']:
ret['result'] = presult
ret['comment'] = pcomment
ret['changes'] = pchanges
return ret
if __salt__['file.is_link'](name):
@ -1659,7 +1660,6 @@ def absent(name,
ret = {'name': name,
'changes': {},
'pchanges': {},
'result': True,
'comment': ''}
if not name:
@ -1671,9 +1671,9 @@ def absent(name,
if name == '/':
return _error(ret, 'Refusing to make "/" absent')
if os.path.isfile(name) or os.path.islink(name):
ret['pchanges']['removed'] = name
if __opts__['test']:
ret['result'] = None
ret['changes']['removed'] = name
ret['comment'] = 'File {0} is set for removal'.format(name)
return ret
try:
@ -1688,9 +1688,9 @@ def absent(name,
return _error(ret, '{0}'.format(exc))
elif os.path.isdir(name):
ret['pchanges']['removed'] = name
if __opts__['test']:
ret['result'] = None
ret['changes']['removed'] = name
ret['comment'] = 'Directory {0} is set for removal'.format(name)
return ret
try:
@ -1849,7 +1849,6 @@ def exists(name,
ret = {'name': name,
'changes': {},
'pchanges': {},
'result': True,
'comment': ''}
if not name:
@ -1874,7 +1873,6 @@ def missing(name,
ret = {'name': name,
'changes': {},
'pchanges': {},
'result': True,
'comment': ''}
if not name:
@ -2483,7 +2481,6 @@ def managed(name,
name = os.path.expanduser(name)
ret = {'changes': {},
'pchanges': {},
'comment': '',
'name': name,
'result': True}
@ -3226,7 +3223,6 @@ def directory(name,
name = os.path.expanduser(name)
ret = {'name': name,
'changes': {},
'pchanges': {},
'result': True,
'comment': ''}
if not name:
@ -3300,19 +3296,19 @@ def directory(name,
# Remove whatever is in the way
if os.path.isfile(name):
if __opts__['test']:
ret['pchanges']['forced'] = 'File was forcibly replaced'
ret['changes']['forced'] = 'File would be forcibly replaced'
else:
os.remove(name)
ret['changes']['forced'] = 'File was forcibly replaced'
elif __salt__['file.is_link'](name):
if __opts__['test']:
ret['pchanges']['forced'] = 'Symlink was forcibly replaced'
ret['changes']['forced'] = 'Symlink would be forcibly replaced'
else:
__salt__['file.remove'](name)
ret['changes']['forced'] = 'Symlink was forcibly replaced'
else:
if __opts__['test']:
ret['pchanges']['forced'] = 'Directory was forcibly replaced'
ret['changes']['forced'] = 'Directory would be forcibly replaced'
else:
__salt__['file.remove'](name)
ret['changes']['forced'] = 'Directory was forcibly replaced'
@ -3341,11 +3337,11 @@ def directory(name,
require, exclude_pat, max_depth, follow_symlinks)
if pchanges:
ret['pchanges'].update(pchanges)
ret['changes'].update(pchanges)
# Don't run through the reset of the function if there are no changes to be
# made
if not ret['pchanges'] or __opts__['test']:
if __opts__['test'] or not ret['changes']:
ret['result'] = presult
ret['comment'] = pcomment
return ret
@ -3764,7 +3760,6 @@ def recurse(name,
ret = {
'name': name,
'changes': {},
'pchanges': {},
'result': True,
'comment': {} # { path: [comment, ...] }
}
@ -4063,7 +4058,6 @@ def retention_schedule(name, retain, strptime_format=None, timezone=None):
name = os.path.expanduser(name)
ret = {'name': name,
'changes': {'retained': [], 'deleted': [], 'ignored': []},
'pchanges': {'retained': [], 'deleted': [], 'ignored': []},
'result': True,
'comment': ''}
if not name:
@ -4173,7 +4167,7 @@ def retention_schedule(name, retain, strptime_format=None, timezone=None):
'deleted': deletable_files,
'ignored': sorted(list(ignored_files), reverse=True),
}
ret['pchanges'] = changes
ret['changes'] = changes
# TODO: track and report how much space was / would be reclaimed
if __opts__['test']:
@ -4314,7 +4308,6 @@ def line(name, content=None, match=None, mode=None, location=None,
name = os.path.expanduser(name)
ret = {'name': name,
'changes': {},
'pchanges': {},
'result': True,
'comment': ''}
if not name:
@ -4348,14 +4341,13 @@ def line(name, content=None, match=None, mode=None, location=None,
before=before, after=after, show_changes=show_changes,
backup=backup, quiet=quiet, indent=indent)
if changes:
ret['pchanges']['diff'] = changes
ret['changes']['diff'] = changes
if __opts__['test']:
ret['result'] = None
ret['comment'] = 'Changes would be made:\ndiff:\n{0}'.format(changes)
ret['comment'] = 'Changes would be made'
else:
ret['result'] = True
ret['comment'] = 'Changes were made'
ret['changes'] = {'diff': changes}
else:
ret['result'] = True
ret['comment'] = 'No changes needed to be made'
@ -4505,7 +4497,6 @@ def replace(name,
ret = {'name': name,
'changes': {},
'pchanges': {},
'result': True,
'comment': ''}
if not name:
@ -4535,14 +4526,13 @@ def replace(name,
backslash_literal=backslash_literal)
if changes:
ret['pchanges']['diff'] = changes
ret['changes']['diff'] = changes
if __opts__['test']:
ret['result'] = None
ret['comment'] = 'Changes would have been made:\ndiff:\n{0}'.format(changes)
ret['comment'] = 'Changes would have been made'
else:
ret['result'] = True
ret['comment'] = 'Changes were made'
ret['changes'] = {'diff': changes}
else:
ret['result'] = True
ret['comment'] = 'No changes needed to be made'
@ -4764,7 +4754,6 @@ def blockreplace(
ret = {'name': name,
'changes': {},
'pchanges': {},
'result': False,
'comment': ''}
if not name:
@ -4837,13 +4826,11 @@ def blockreplace(
return ret
if changes:
ret['pchanges'] = {'diff': changes}
ret['changes']['diff'] = changes
if __opts__['test']:
ret['changes']['diff'] = ret['pchanges']['diff']
ret['result'] = None
ret['comment'] = 'Changes would be made'
else:
ret['changes']['diff'] = ret['pchanges']['diff']
ret['result'] = True
ret['comment'] = 'Changes were made'
else:
@ -4894,7 +4881,6 @@ def comment(name, regex, char='#', backup='.bak'):
ret = {'name': name,
'changes': {},
'pchanges': {},
'result': False,
'comment': ''}
if not name:
@ -4924,8 +4910,8 @@ def comment(name, regex, char='#', backup='.bak'):
else:
return _error(ret, '{0}: Pattern not found'.format(unanchor_regex))
ret['pchanges'][name] = 'updated'
if __opts__['test']:
ret['changes'][name] = 'updated'
ret['comment'] = 'File {0} is set to be updated'.format(name)
ret['result'] = None
return ret
@ -5004,7 +4990,6 @@ def uncomment(name, regex, char='#', backup='.bak'):
ret = {'name': name,
'changes': {},
'pchanges': {},
'result': False,
'comment': ''}
if not name:
@ -5031,26 +5016,20 @@ def uncomment(name, regex, char='#', backup='.bak'):
else:
return _error(ret, '{0}: Pattern not found'.format(regex))
ret['pchanges'][name] = 'updated'
if __opts__['test']:
ret['changes'][name] = 'updated'
ret['comment'] = 'File {0} is set to be updated'.format(name)
ret['result'] = None
return ret
with salt.utils.files.fopen(name, 'rb') as fp_:
slines = fp_.read()
if six.PY3:
slines = slines.decode(__salt_system_encoding__)
slines = slines.splitlines(True)
slines = salt.utils.data.decode(fp_.readlines())
# Perform the edit
__salt__['file.comment_line'](name, regex, char, False, backup)
with salt.utils.files.fopen(name, 'rb') as fp_:
nlines = fp_.read()
if six.PY3:
nlines = nlines.decode(__salt_system_encoding__)
nlines = nlines.splitlines(True)
nlines = salt.utils.data.decode(fp_.readlines())
# Check the result
ret['result'] = __salt__['file.search'](
@ -5214,10 +5193,9 @@ def append(name,
.. versionadded:: 0.9.5
'''
ret = {'name': name,
'changes': {},
'pchanges': {},
'result': False,
'comment': ''}
'changes': {},
'result': False,
'comment': ''}
if not name:
return _error(ret, 'Must provide name to file.append')
@ -5252,12 +5230,12 @@ def append(name,
except CommandExecutionError as exc:
return _error(ret, 'Drive {0} is not mapped'.format(exc.message))
if salt.utils.platform.is_windows():
check_res, check_msg, ret['pchanges'] = _check_directory_win(dirname)
else:
check_res, check_msg, ret['pchanges'] = _check_directory(dirname)
check_res, check_msg, check_changes = _check_directory_win(dirname) \
if salt.utils.platform.is_windows() \
else _check_directory(dirname)
if not check_res:
ret['changes'] = check_changes
return _error(ret, check_msg)
check_res, check_msg = _check_file(name)
@ -5506,7 +5484,6 @@ def prepend(name,
ret = {'name': name,
'changes': {},
'pchanges': {},
'result': False,
'comment': ''}
if not name:
@ -5536,11 +5513,12 @@ def prepend(name,
except CommandExecutionError as exc:
return _error(ret, 'Drive {0} is not mapped'.format(exc.message))
if salt.utils.platform.is_windows():
check_res, check_msg, ret['pchanges'] = _check_directory_win(dirname)
else:
check_res, check_msg, ret['pchanges'] = _check_directory(dirname)
check_res, check_msg, check_changes = _check_directory_win(dirname) \
if salt.utils.platform.is_windows() \
else _check_directory(dirname)
if not check_res:
ret['changes'] = check_changes
return _error(ret, check_msg)
check_res, check_msg = _check_file(name)
@ -7399,17 +7377,18 @@ def shortcut(
msg += '.'
return _error(ret, msg)
presult, pcomment, ret['pchanges'] = _shortcut_check(name,
target,
arguments,
working_dir,
description,
icon_location,
force,
user)
presult, pcomment, pchanges = _shortcut_check(name,
target,
arguments,
working_dir,
description,
icon_location,
force,
user)
if __opts__['test']:
ret['result'] = presult
ret['comment'] = pcomment
ret['changes'] = pchanges
return ret
if not os.path.isdir(os.path.dirname(name)):

View file

@ -52,15 +52,16 @@ def present(name, auth=None, **kwargs):
'result': True,
'comment': ''}
kwargs = __utils__['args.clean_kwargs'](**kwargs)
__salt__['glanceng.setup_clouds'](auth)
image = __salt__['glanceng.image_get'](name=name)
if not image:
if __opts__['test'] is True:
if __opts__['test']:
ret['result'] = None
ret['changes'] = kwargs
ret['pchanges'] = ret['changes']
ret['comment'] = 'Image {} will be created.'.format(name)
return ret
@ -91,10 +92,9 @@ def absent(name, auth=None):
image = __salt__['glanceng.image_get'](name=name)
if image:
if __opts__['test'] is True:
if __opts__['test']:
ret['result'] = None
ret['changes'] = {'name': name}
ret['pchanges'] = ret['changes']
ret['comment'] = 'Image {} will be deleted.'.format(name)
return ret

View file

@ -144,8 +144,7 @@ def latest_active(name, at_time=None, **kwargs): # pylint: disable=unused-argum
if __opts__['test']:
ret['result'] = None
ret['changes'] = {}
ret['pchanges'] = {'kernel': {
ret['changes'] = {'kernel': {
'old': active,
'new': latest
}}

View file

@ -56,15 +56,16 @@ def present(name, auth=None, **kwargs):
'result': True,
'comment': ''}
kwargs = __utils__['args.clean_kwargs'](**kwargs)
__salt__['keystoneng.setup_clouds'](auth)
domain = __salt__['keystoneng.domain_get'](name=name)
if not domain:
if __opts__['test'] is True:
if __opts__['test']:
ret['result'] = None
ret['changes'] = kwargs
ret['pchanges'] = ret['changes']
ret['comment'] = 'Domain {} will be created.'.format(name)
return ret
@ -76,10 +77,9 @@ def present(name, auth=None, **kwargs):
changes = __salt__['keystoneng.compare_changes'](domain, **kwargs)
if changes:
if __opts__['test'] is True:
if __opts__['test']:
ret['result'] = None
ret['changes'] = changes
ret['pchanges'] = ret['changes']
ret['comment'] = 'Domain {} will be updated.'.format(name)
return ret
@ -111,7 +111,6 @@ def absent(name, auth=None):
if __opts__['test'] is True:
ret['result'] = None
ret['changes'] = {'name': name}
ret['pchanges'] = ret['changes']
ret['comment'] = 'Domain {} will be deleted.'.format(name)
return ret

View file

@ -101,6 +101,8 @@ def present(name, service_name, auth=None, **kwargs):
'result': True,
'comment': ''}
kwargs = __utils__['args.clean_kwargs'](**kwargs)
__salt__['keystoneng.setup_clouds'](auth)
success, val = _, endpoint = _common(ret, name, service_name, kwargs)
@ -111,7 +113,6 @@ def present(name, service_name, auth=None, **kwargs):
if __opts__['test'] is True:
ret['result'] = None
ret['changes'] = kwargs
ret['pchanges'] = ret['changes']
ret['comment'] = 'Endpoint will be created.'
return ret
@ -131,7 +132,6 @@ def present(name, service_name, auth=None, **kwargs):
if __opts__['test'] is True:
ret['result'] = None
ret['changes'] = changes
ret['pchanges'] = ret['changes']
ret['comment'] = 'Endpoint will be updated.'
return ret
@ -174,7 +174,6 @@ def absent(name, service_name, auth=None, **kwargs):
if __opts__['test'] is True:
ret['result'] = None
ret['changes'] = {'id': endpoint.id}
ret['pchanges'] = ret['changes']
ret['comment'] = 'Endpoint will be deleted.'
return ret

View file

@ -73,6 +73,8 @@ def present(name, auth=None, **kwargs):
__salt__['keystoneng.setup_cloud'](auth)
kwargs = __utils__['args.clean_kwargs'](**kwargs)
kwargs['name'] = name
group = _common(kwargs)
@ -80,7 +82,6 @@ def present(name, auth=None, **kwargs):
if __opts__['test'] is True:
ret['result'] = None
ret['changes'] = kwargs
ret['pchanges'] = ret['changes']
ret['comment'] = 'Group will be created.'
return ret
@ -94,7 +95,6 @@ def present(name, auth=None, **kwargs):
if __opts__['test'] is True:
ret['result'] = None
ret['changes'] = changes
ret['pchanges'] = ret['changes']
ret['comment'] = 'Group will be updated.'
return ret
@ -120,6 +120,8 @@ def absent(name, auth=None, **kwargs):
'result': True,
'comment': ''}
kwargs = __utils__['args.clean_kwargs'](**kwargs)
__salt__['keystoneng.setup_cloud'](auth)
kwargs['name'] = name
@ -129,7 +131,6 @@ def absent(name, auth=None, **kwargs):
if __opts__['test'] is True:
ret['result'] = None
ret['changes'] = {'id': group.id}
ret['pchanges'] = ret['changes']
ret['comment'] = 'Group will be deleted.'
return ret

View file

@ -72,6 +72,8 @@ def present(name, auth=None, **kwargs):
'result': True,
'comment': ''}
kwargs = __utils__['args.clean_kwargs'](**kwargs)
__salt__['keystoneng.setup_clouds'](auth)
kwargs['name'] = name
@ -81,7 +83,6 @@ def present(name, auth=None, **kwargs):
if __opts__['test'] is True:
ret['result'] = None
ret['changes'] = kwargs
ret['pchanges'] = ret['changes']
ret['comment'] = 'Project will be created.'
return ret
@ -95,7 +96,6 @@ def present(name, auth=None, **kwargs):
if __opts__['test'] is True:
ret['result'] = None
ret['changes'] = changes
ret['pchanges'] = ret['changes']
ret['comment'] = 'Project will be updated.'
return ret
@ -121,6 +121,8 @@ def absent(name, auth=None, **kwargs):
'result': True,
'comment': ''}
kwargs = __utils__['args.clean_kwargs'](**kwargs)
__salt__['keystoneng.setup_clouds'](auth)
kwargs['name'] = name
@ -130,7 +132,6 @@ def absent(name, auth=None, **kwargs):
if __opts__['test'] is True:
ret['result'] = None
ret['changes'] = {'id': project.id}
ret['pchanges'] = ret['changes']
ret['comment'] = 'Project will be deleted.'
return ret

View file

@ -52,6 +52,8 @@ def present(name, auth=None, **kwargs):
'result': True,
'comment': ''}
kwargs = __utils__['args.clean_kwargs'](**kwargs)
__salt__['keystoneng.setup_clouds'](auth)
kwargs['name'] = name
@ -61,7 +63,6 @@ def present(name, auth=None, **kwargs):
if __opts__['test'] is True:
ret['result'] = None
ret['changes'] = kwargs
ret['pchanges'] = ret['changes']
ret['comment'] = 'Role will be created.'
return ret
@ -95,7 +96,6 @@ def absent(name, auth=None, **kwargs):
if __opts__['test'] is True:
ret['result'] = None
ret['changes'] = {'id': role.id}
ret['pchanges'] = ret['changes']
ret['comment'] = 'Role will be deleted.'
return ret

View file

@ -61,6 +61,8 @@ def present(name, auth=None, **kwargs):
'result': True,
'comment': ''}
kwargs = __utils__['args.clean_kwargs'](**kwargs)
__salt__['keystoneng.setup_clouds'](auth)
service = __salt__['keystoneng.service_get'](name=name)
@ -69,7 +71,6 @@ def present(name, auth=None, **kwargs):
if __opts__['test'] is True:
ret['result'] = None
ret['changes'] = kwargs
ret['pchanges'] = ret['changes']
ret['comment'] = 'Service will be created.'
return ret
@ -84,7 +85,6 @@ def present(name, auth=None, **kwargs):
if __opts__['test'] is True:
ret['result'] = None
ret['changes'] = changes
ret['pchanges'] = ret['changes']
ret['comment'] = 'Service will be updated.'
return ret
@ -117,7 +117,6 @@ def absent(name, auth=None):
if __opts__['test'] is True:
ret['result'] = None
ret['changes'] = {'id': service.id}
ret['pchanges'] = ret['changes']
ret['comment'] = 'Service will be deleted.'
return ret

View file

@ -83,6 +83,8 @@ def present(name, auth=None, **kwargs):
'result': True,
'comment': ''}
kwargs = __utils__['args.clean_kwargs'](**kwargs)
__salt__['keystoneng.setup_clouds'](auth)
kwargs['name'] = name
@ -92,7 +94,6 @@ def present(name, auth=None, **kwargs):
if __opts__['test'] is True:
ret['result'] = None
ret['changes'] = kwargs
ret['pchanges'] = ret['changes']
ret['comment'] = 'User will be created.'
return ret
@ -106,7 +107,6 @@ def present(name, auth=None, **kwargs):
if __opts__['test'] is True:
ret['result'] = None
ret['changes'] = changes
ret['pchanges'] = ret['changes']
ret['comment'] = 'User will be updated.'
return ret
@ -133,6 +133,8 @@ def absent(name, auth=None, **kwargs):
'result': True,
'comment': ''}
kwargs = __utils__['args.clean_kwargs'](**kwargs)
__salt__['keystoneng.setup_clouds'](auth)
kwargs['name'] = name
@ -142,7 +144,6 @@ def absent(name, auth=None, **kwargs):
if __opts__['test'] is True:
ret['result'] = None
ret['changes'] = {'id': user.id}
ret['pchanges'] = ret['changes']
ret['comment'] = 'User will be deleted.'
return ret

View file

@ -103,7 +103,6 @@ def present(name, acl_type, acl_name='', perms='', recurse=False, force=False):
ret = {'name': name,
'result': True,
'changes': {},
'pchanges': {},
'comment': ''}
_octal = {'r': 4, 'w': 2, 'x': 1, '-': 0}
@ -176,7 +175,7 @@ def present(name, acl_type, acl_name='', perms='', recurse=False, force=False):
acl_name,
new_perms,
perms),
'result': None, 'pchanges': changes})
'result': None, 'changes': changes})
return ret
try:
if force:
@ -199,7 +198,7 @@ def present(name, acl_type, acl_name='', perms='', recurse=False, force=False):
if __opts__['test']:
ret.update({'comment': 'New permissions will be applied for '
'{0}: {1}'.format(acl_name, perms),
'result': None, 'pchanges': changes})
'result': None, 'changes': changes})
ret['result'] = None
return ret

View file

@ -94,8 +94,6 @@ def managed(name,
compliance_report: ``False``
Return the compliance report in the comment.
The compliance report structured object can be found however
in the ``pchanges`` field of the output (not displayed on the CLI).
.. versionadded:: 2017.7.3

View file

@ -72,6 +72,8 @@ def present(name, auth=None, **kwargs):
'result': True,
'comment': ''}
kwargs = __utils__['args.clean_kwargs'](**kwargs)
__salt__['neutronng.setup_clouds'](auth)
kwargs['name'] = name
@ -81,7 +83,6 @@ def present(name, auth=None, **kwargs):
if __opts__['test'] is True:
ret['result'] = None
ret['changes'] = kwargs
ret['pchanges'] = ret['changes']
ret['comment'] = 'Network will be created.'
return ret
@ -115,7 +116,6 @@ def present(name, auth=None, **kwargs):
if __opts__['test'] is True:
ret['result'] = None
ret['changes'] = changes
ret['pchanges'] = ret['changes']
ret['comment'] = 'Project will be updated.'
return ret
@ -140,6 +140,8 @@ def absent(name, auth=None, **kwargs):
'result': True,
'comment': ''}
kwargs = __utils__['args.clean_kwargs'](**kwargs)
__salt__['neutronng.setup_clouds'](auth)
kwargs['name'] = name
@ -149,7 +151,6 @@ def absent(name, auth=None, **kwargs):
if __opts__['test'] is True:
ret['result'] = None
ret['changes'] = {'id': network.id}
ret['pchanges'] = ret['changes']
ret['comment'] = 'Network will be deleted.'
return ret

View file

@ -74,6 +74,8 @@ def present(name, auth=None, **kwargs):
'result': True,
'comment': ''}
kwargs = __utils__['args.clean_kwargs'](**kwargs)
__salt__['neutronng.setup_clouds'](auth)
if 'project_name' in kwargs:
@ -95,7 +97,6 @@ def present(name, auth=None, **kwargs):
if __opts__['test'] is True:
ret['result'] = None
ret['changes'] = kwargs
ret['pchanges'] = ret['changes']
ret['comment'] = 'Security Group will be created.'
return ret
@ -109,7 +110,6 @@ def present(name, auth=None, **kwargs):
if __opts__['test'] is True:
ret['result'] = None
ret['changes'] = changes
ret['pchanges'] = ret['changes']
ret['comment'] = 'Security Group will be updated.'
return ret
@ -133,6 +133,8 @@ def absent(name, auth=None, **kwargs):
'result': True,
'comment': ''}
kwargs = __utils__['args.clean_kwargs'](**kwargs)
__salt__['neutronng.setup_clouds'](auth)
kwargs['project_id'] = __salt__['keystoneng.project_get'](
@ -147,7 +149,6 @@ def absent(name, auth=None, **kwargs):
if __opts__['test'] is True:
ret['result'] = None
ret['changes'] = {'id': secgroup.id}
ret['pchanges'] = ret['changes']
ret['comment'] = 'Security group will be deleted.'
return ret

View file

@ -77,6 +77,8 @@ def present(name, auth=None, **kwargs):
'result': True,
'comment': ''}
kwargs = __utils__['args.clean_kwargs'](**kwargs)
__salt__['neutronng.setup_clouds'](auth)
if 'project_name' in kwargs:
@ -112,7 +114,6 @@ def present(name, auth=None, **kwargs):
if __opts__['test'] is True:
ret['result'] = None
ret['changes'] = kwargs
ret['pchanges'] = ret['changes']
ret['comment'] = 'Security Group rule will be created.'
return ret
@ -166,10 +167,9 @@ def absent(name, auth=None, **kwargs):
rule_exists = True
if rule_exists:
if __opts__['test'] is True:
if __opts__['test']:
ret['result'] = None
ret['changes'] = {'id': kwargs['rule_id']}
ret['pchanges'] = ret['changes']
ret['comment'] = 'Security group rule will be deleted.'
return ret

View file

@ -96,16 +96,17 @@ def present(name, auth=None, **kwargs):
'result': True,
'comment': ''}
kwargs = __utils__['args.clean_kwargs'](**kwargs)
__salt__['neutronng.setup_clouds'](auth)
kwargs['subnet_name'] = name
subnet = __salt__['neutronng.subnet_get'](name=name)
if subnet is None:
if __opts__['test'] is True:
if __opts__['test']:
ret['result'] = None
ret['changes'] = kwargs
ret['pchanges'] = ret['changes']
ret['comment'] = 'Subnet will be created.'
return ret
@ -119,7 +120,6 @@ def present(name, auth=None, **kwargs):
if __opts__['test'] is True:
ret['result'] = None
ret['changes'] = changes
ret['pchanges'] = ret['changes']
ret['comment'] = 'Project will be updated.'
return ret
@ -160,7 +160,6 @@ def absent(name, auth=None):
if __opts__['test'] is True:
ret['result'] = None
ret['changes'] = {'id': subnet.id}
ret['pchanges'] = ret['changes']
ret['comment'] = 'Project will be deleted.'
return ret

View file

@ -156,8 +156,10 @@ def default_vsan_policy_configured(name, policy):
'\'{1}\''.format(name, vcenter))
log.trace('policy = {0}'.format(policy))
changes_required = False
ret = {'name': name, 'changes': {}, 'result': None, 'comment': None,
'pchanges': {}}
ret = {'name': name,
'changes': {},
'result': None,
'comment': None}
comments = []
changes = {}
changes_required = False
@ -266,13 +268,11 @@ def default_vsan_policy_configured(name, policy):
'Nothing to be done.'.format(vcenter)),
'result': True})
else:
ret.update({'comment': '\n'.join(comments)})
if __opts__['test']:
ret.update({'pchanges': changes,
'result': None})
else:
ret.update({'changes': changes,
'result': True})
ret.update({
'comment': '\n'.join(comments),
'changes': changes,
'result': None if __opts__['test'] else True,
})
return ret
@ -286,8 +286,10 @@ def storage_policies_configured(name, policies):
comments = []
changes = []
changes_required = False
ret = {'name': name, 'changes': {}, 'result': None, 'comment': None,
'pchanges': {}}
ret = {'name': name,
'changes': {},
'result': None,
'comment': None}
log.trace('policies = {0}'.format(policies))
si = None
try:
@ -430,13 +432,11 @@ def storage_policies_configured(name, policies):
'Nothing to be done.'.format(vcenter)),
'result': True})
else:
ret.update({'comment': '\n'.join(comments)})
if __opts__['test']:
ret.update({'pchanges': {'storage_policies': changes},
'result': None})
else:
ret.update({'changes': {'storage_policies': changes},
'result': True})
ret.update({
'comment': '\n'.join(comments),
'changes': {'storage_policies': changes},
'result': None if __opts__['test'] else True,
})
return ret
@ -454,8 +454,10 @@ def default_storage_policy_assigned(name, policy, datastore):
''.format(name, policy, datastore))
changes = {}
changes_required = False
ret = {'name': name, 'changes': {}, 'result': None, 'comment': None,
'pchanges': {}}
ret = {'name': name,
'changes': {},
'result': None,
'comment': None}
si = None
try:
si = __salt__['vsphere.get_service_instance_via_proxy']()
@ -488,14 +490,13 @@ def default_storage_policy_assigned(name, policy, datastore):
ret.update({'comment': exc.strerror,
'result': False if not __opts__['test'] else None})
return ret
ret['comment'] = comment
if changes_required:
if __opts__['test']:
ret.update({'result': None,
'pchanges': changes})
else:
ret.update({'result': True,
'changes': changes})
ret.update({
'changes': changes,
'result': None if __opts__['test'] else True,
})
else:
ret['result'] = True
return ret

View file

@ -199,8 +199,7 @@ def baseline_snapshot(name, number=None, tag=None, include_diff=True, config='ro
filename=file).get(file, {}))
if __opts__['test'] and status:
ret['pchanges'] = status
ret['changes'] = ret['pchanges']
ret['changes'] = status
ret['comment'] = "{0} files changes are set to be undone".format(len(status.keys()))
ret['result'] = None
elif __opts__['test'] and not status:

View file

@ -34,10 +34,9 @@ def alias(name, collections, **kwargs):
'changes': {},
'result': False,
'comment': '',
'pchanges': {},
}
if __salt__["solrcloud.alias_exists"](name, **kwargs):
if __salt__['solrcloud.alias_exists'](name, **kwargs):
alias_content = __salt__['solrcloud.alias_get_collections'](name, **kwargs)
diff = set(alias_content).difference(set(collections))
@ -48,38 +47,31 @@ def alias(name, collections, **kwargs):
if __opts__['test']:
ret['comment'] = 'The alias "{0}" will be updated.'.format(name)
ret['pchanges'] = {
'old': ",".join(alias_content),
'new': ",".join(collections)
}
ret['result'] = None
else:
__salt__["solrcloud.alias_set_collections"](name, collections, **kwargs)
__salt__['solrcloud.alias_set_collections'](name, collections, **kwargs)
ret['comment'] = 'The alias "{0}" has been updated.'.format(name)
ret['changes'] = {
'old': ",".join(alias_content),
'new': ",".join(collections)
}
ret['result'] = True
ret['changes'] = {
'old': ','.join(alias_content),
'new': ','.join(collections),
}
else:
if __opts__['test']:
ret['comment'] = 'The alias "{0}" will be created.'.format(name)
ret['pchanges'] = {
'old': None,
'new': ",".join(collections)
}
ret['result'] = None
else:
__salt__["solrcloud.alias_set_collections"](name, collections, **kwargs)
__salt__['solrcloud.alias_set_collections'](name, collections, **kwargs)
ret['comment'] = 'The alias "{0}" has been created.'.format(name)
ret['changes'] = {
'old': None,
'new': ",".join(collections)
}
ret['result'] = True
ret['changes'] = {
'old': None,
'new': ','.join(collections),
}
return ret
@ -101,7 +93,6 @@ def collection(name, options=None, **kwargs):
'changes': {},
'result': False,
'comment': '',
'pchanges': {},
}
if options is None:
@ -137,42 +128,32 @@ def collection(name, options=None, **kwargs):
if __opts__['test']:
ret['comment'] = 'Collection options "{0}" will be changed.'.format(name)
ret['pchanges'] = {
'old': salt.utils.json.dumps(current_options, sort_keys=True, indent=4, separators=(',', ': ')),
'new': salt.utils.json.dumps(options, sort_keys=True, indent=4, separators=(',', ': '))
}
ret['result'] = None
return ret
else:
__salt__["solrcloud.collection_set_options"](name, diff, **kwargs)
__salt__['solrcloud.collection_set_options'](name, diff, **kwargs)
ret['comment'] = 'Parameters were updated for collection "{0}".'.format(name)
ret['result'] = True
ret['changes'] = {
'old': salt.utils.json.dumps(current_options, sort_keys=True, indent=4, separators=(',', ': ')),
'new': salt.utils.json.dumps(options, sort_keys=True, indent=4, separators=(',', ': '))
}
return ret
ret['changes'] = {
'old': salt.utils.json.dumps(current_options, sort_keys=True, indent=4, separators=(',', ': ')),
'new': salt.utils.json.dumps(options, sort_keys=True, indent=4, separators=(',', ': '))
}
return ret
else:
new_changes = salt.utils.json.dumps(options, sort_keys=True, indent=4, separators=(',', ': '))
if __opts__['test']:
ret['comment'] = 'The collection "{0}" will be created.'.format(name)
ret['pchanges'] = {
'old': None,
'new': str('options=') + new_changes # future lint: disable=blacklisted-function
}
ret['result'] = None
else:
__salt__["solrcloud.collection_create"](name, options, **kwargs)
ret['comment'] = 'The collection "{0}" has been created.'.format(name)
ret['changes'] = {
'old': None,
'new': str('options=') + new_changes # future lint: disable=blacklisted-function
}
ret['result'] = True
ret['changes'] = {
'old': None,
'new': str('options=') + new_changes # future lint: disable=blacklisted-function
}
return ret

View file

@ -492,7 +492,6 @@ def default_ret(name):
'''
ret = {
'name': name,
'pchanges': {},
'changes': {},
'result': False,
'comment': ''
@ -510,22 +509,16 @@ def loaded_ret(ret, loaded, test, debug, compliance_report=False, opts=None):
'''
# Always get the comment
changes = {}
pchanges = {}
ret['comment'] = loaded['comment']
if 'diff' in loaded:
changes['diff'] = loaded['diff']
pchanges['diff'] = loaded['diff']
if 'commit_id' in loaded:
changes['commit_id'] = loaded['commit_id']
pchanges['commit_id'] = loaded['commit_id']
if 'compliance_report' in loaded:
if compliance_report:
changes['compliance_report'] = loaded['compliance_report']
pchanges['compliance_report'] = loaded['compliance_report']
if debug and 'loaded_config' in loaded:
changes['loaded_config'] = loaded['loaded_config']
pchanges['loaded_config'] = loaded['loaded_config']
ret['pchanges'] = pchanges
if changes.get('diff'):
ret['comment'] = '{comment_base}\n\nConfiguration diff:\n\n{diff}'.format(comment_base=ret['comment'],
diff=changes['diff'])

View file

@ -212,10 +212,6 @@ def merge_subreturn(original_return, sub_return, subkey=None):
original_return.setdefault('changes', {})
original_return['changes'][subkey] = sub_return['changes']
if sub_return.get('pchanges'): # pchanges may or may not exist
original_return.setdefault('pchanges', {})
original_return['pchanges'][subkey] = sub_return['pchanges']
return original_return

View file

@ -751,7 +751,6 @@ class FileTest(ModuleCase, SaltReturnAssertsMixin):
source_hash=uppercase_hash
)
assert ret[state_name]['result'] is True
assert ret[state_name]['pchanges'] == {}
assert ret[state_name]['changes'] == {}
# Test uppercase source_hash using test=true
@ -764,7 +763,6 @@ class FileTest(ModuleCase, SaltReturnAssertsMixin):
test=True
)
assert ret[state_name]['result'] is True
assert ret[state_name]['pchanges'] == {}
assert ret[state_name]['changes'] == {}
finally:

View file

@ -91,7 +91,7 @@ class BotoCloudfrontTestCase(TestCase, LoaderModuleMockMixin):
self.base_ret_with({
'result': None,
'comment': comment,
'pchanges': {'old': None, 'new': self.name},
'changes': {'old': None, 'new': self.name},
}),
)
@ -191,7 +191,7 @@ class BotoCloudfrontTestCase(TestCase, LoaderModuleMockMixin):
self.base_ret_with({
'result': None,
'comment': '\n'.join([header, diff]),
'pchanges': {'diff': diff},
'changes': {'diff': diff},
}),
)

View file

@ -74,7 +74,7 @@ class BotoSqsTestCase(TestCase, LoaderModuleMockMixin):
ret.update({
'result': None,
'comment': comt,
'pchanges': {'old': None, 'new': 'mysqs'},
'changes': {'old': None, 'new': 'mysqs'},
})
self.assertDictEqual(boto_sqs.present(name), ret)
diff = textwrap.dedent('''\
@ -101,7 +101,7 @@ class BotoSqsTestCase(TestCase, LoaderModuleMockMixin):
]
ret.update({
'comment': comt,
'pchanges': {'attributes': {'diff': diff}},
'changes': {'attributes': {'diff': diff}},
})
self.assertDictEqual(boto_sqs.present(name, attributes), ret)
@ -133,6 +133,6 @@ class BotoSqsTestCase(TestCase, LoaderModuleMockMixin):
ret.update({
'result': None,
'comment': comt,
'pchanges': {'old': name, 'new': None},
'changes': {'old': name, 'new': None},
})
self.assertDictEqual(boto_sqs.absent(name), ret)

View file

@ -64,7 +64,6 @@ class DatacenterConfiguredTestCase(TestCase, LoaderModuleMockMixin):
res = esxdatacenter.datacenter_configured('fake_dc')
self.assertDictEqual(res, {'name': 'fake_dc',
'changes': {},
'pchanges': {},
'result': True,
'comment': 'Datacenter \'fake_dc\' already '
'exists. Nothing to be done.'})
@ -78,7 +77,6 @@ class DatacenterConfiguredTestCase(TestCase, LoaderModuleMockMixin):
res = esxdatacenter.datacenter_configured('fake_dc')
self.assertDictEqual(res, {'name': 'fake_dc',
'changes': {},
'pchanges': {},
'result': True,
'comment': 'Datacenter \'proxy_dc\' '
'already exists. Nothing to be done.'})
@ -112,7 +110,6 @@ class DatacenterConfiguredTestCase(TestCase, LoaderModuleMockMixin):
self.assertDictEqual(res,
{'name': 'fake_dc',
'changes': {'new': {'name': 'fake_dc'}},
'pchanges': {},
'result': True,
'comment': 'Created datacenter \'fake_dc\'.'})
@ -124,8 +121,7 @@ class DatacenterConfiguredTestCase(TestCase, LoaderModuleMockMixin):
res = esxdatacenter.datacenter_configured('fake_dc')
self.assertDictEqual(res,
{'name': 'fake_dc',
'changes': {},
'pchanges': {'new': {'name': 'fake_dc'}},
'changes': {'new': {'name': 'fake_dc'}},
'result': None,
'comment': 'State will create '
'datacenter \'fake_dc\'.'})
@ -138,7 +134,6 @@ class DatacenterConfiguredTestCase(TestCase, LoaderModuleMockMixin):
res = esxdatacenter.datacenter_configured('fake_dc')
self.assertDictEqual(res, {'name': 'fake_dc',
'changes': {},
'pchanges': {},
'result': True,
'comment': 'Datacenter \'fake_dc\' already '
'exists. Nothing to be done.'})
@ -154,7 +149,6 @@ class DatacenterConfiguredTestCase(TestCase, LoaderModuleMockMixin):
self.assertEqual(mock_disconnect.call_count, 0)
self.assertDictEqual(res, {'name': 'fake_dc',
'changes': {},
'pchanges': {},
'result': False,
'comment': 'Error'})
@ -169,7 +163,6 @@ class DatacenterConfiguredTestCase(TestCase, LoaderModuleMockMixin):
mock_disconnect.assert_called_once_with(self.mock_si)
self.assertDictEqual(res, {'name': 'fake_dc',
'changes': {},
'pchanges': {},
'result': False,
'comment': 'Error'})
@ -182,6 +175,5 @@ class DatacenterConfiguredTestCase(TestCase, LoaderModuleMockMixin):
res = esxdatacenter.datacenter_configured('fake_dc')
self.assertDictEqual(res, {'name': 'fake_dc',
'changes': {},
'pchanges': {},
'result': None,
'comment': 'Error'})

View file

@ -226,7 +226,7 @@ class TestFileState(TestCase, LoaderModuleMockMixin):
comt = 'Symlink {0} to {1} is set for creation'.format(name, target)
ret = return_val({'comment': comt,
'result': None,
'pchanges': {'new': name}})
'changes': {'new': name}})
self.assertDictEqual(filestate.symlink(name, target, user=user,
group=group), ret)
@ -249,7 +249,7 @@ class TestFileState(TestCase, LoaderModuleMockMixin):
comt = 'Directory {0} for symlink is not present'.format(test_dir)
ret = return_val({'comment': comt,
'result': False,
'pchanges': {'new': name}})
'changes': {}})
self.assertDictEqual(filestate.symlink(name, target,
user=user,
group=group), ret)
@ -271,7 +271,7 @@ class TestFileState(TestCase, LoaderModuleMockMixin):
comt = 'Symlink {0} is present and owned by {1}:{2}'.format(name, user, group)
ret = return_val({'comment': comt,
'result': True,
'pchanges': {}})
'changes': {}})
self.assertDictEqual(filestate.symlink(name, target,
user=user,
group=group), ret)
@ -292,7 +292,7 @@ class TestFileState(TestCase, LoaderModuleMockMixin):
'{1} - backup: {2}'.format(name, target, os.path.join(test_dir, 'SALT'))
ret.update({'comment': comt,
'result': False,
'pchanges': {'new': name}})
'changes': {}})
self.assertDictEqual(
filestate.symlink(name, target, user=user, group=group,
backupname='SALT'),
@ -312,7 +312,7 @@ class TestFileState(TestCase, LoaderModuleMockMixin):
comt = 'Backupname must be an absolute path or a file name: {0}'.format('tmp/SALT')
ret.update({'comment': comt,
'result': False,
'pchanges': {'new': name}})
'changes': {}})
self.assertDictEqual(
filestate.symlink(name, target, user=user, group=group, backupname='tmp/SALT'),
ret)
@ -331,7 +331,7 @@ class TestFileState(TestCase, LoaderModuleMockMixin):
patch('salt.utils.win_functions.get_sid_from_name', return_value='test-sid'):
comt = 'File exists where the symlink {0} should be'.format(name)
ret = return_val({'comment': comt,
'pchanges': {'new': name},
'changes': {},
'result': False})
self.assertDictEqual(
filestate.symlink(name, target, user=user, group=group),
@ -353,7 +353,7 @@ class TestFileState(TestCase, LoaderModuleMockMixin):
comt = 'File exists where the symlink {0} should be'.format(name)
ret = return_val({'comment': comt,
'result': False,
'pchanges': {'new': name}})
'changes': {}})
self.assertDictEqual(
filestate.symlink(name, target, user=user, group=group),
ret)
@ -374,7 +374,7 @@ class TestFileState(TestCase, LoaderModuleMockMixin):
comt = 'Directory exists where the symlink {0} should be'.format(name)
ret = return_val({'comment': comt,
'result': False,
'pchanges': {'new': name}})
'changes': {}})
self.assertDictEqual(
filestate.symlink(name, target, user=user, group=group),
ret)
@ -394,7 +394,7 @@ class TestFileState(TestCase, LoaderModuleMockMixin):
comt = 'Unable to create new symlink {0} -> {1}: '.format(name, target)
ret = return_val({'comment': comt,
'result': False,
'pchanges': {'new': name}})
'changes': {}})
self.assertDictEqual(
filestate.symlink(name, target, user=user, group=group),
ret)
@ -417,7 +417,6 @@ class TestFileState(TestCase, LoaderModuleMockMixin):
comt = 'Created new symlink {0} -> {1}'.format(name, target)
ret = return_val({'comment': comt,
'result': True,
'pchanges': {'new': name},
'changes': {'new': name}})
self.assertDictEqual(
filestate.symlink(name, target, user=user, group=group),
@ -443,7 +442,6 @@ class TestFileState(TestCase, LoaderModuleMockMixin):
'ownership to {2}:{3}'.format(name, target, user, group)
ret = return_val({'comment': comt,
'result': False,
'pchanges': {'new': name},
'changes': {'new': name}})
self.assertDictEqual(
filestate.symlink(name, target, user=user, group=group),
@ -459,7 +457,6 @@ class TestFileState(TestCase, LoaderModuleMockMixin):
ret = {'name': name,
'result': False,
'comment': '',
'pchanges': {},
'changes': {}}
mock_t = MagicMock(return_value=True)
@ -490,17 +487,15 @@ class TestFileState(TestCase, LoaderModuleMockMixin):
ret.update({'comment': comt,
'name': name,
'result': None,
'pchanges': {'removed': '/fake/file.conf'}})
'changes': {'removed': '/fake/file.conf'}})
self.assertDictEqual(filestate.absent(name), ret)
ret.update({'pchanges': {}})
with patch.dict(filestate.__opts__, {'test': False}):
with patch.dict(filestate.__salt__,
{'file.remove': mock_file}):
comt = ('Removed file {0}'.format(name))
ret.update({'comment': comt, 'result': True,
'changes': {'removed': name},
'pchanges': {'removed': name}})
'changes': {'removed': name}})
self.assertDictEqual(filestate.absent(name), ret)
comt = ('Removed file {0}'.format(name))
@ -508,7 +503,6 @@ class TestFileState(TestCase, LoaderModuleMockMixin):
'result': False,
'changes': {}})
self.assertDictEqual(filestate.absent(name), ret)
ret.update({'pchanges': {}})
with patch.object(os.path, 'isfile', mock_f):
with patch.object(os.path, 'isdir', mock_t):
@ -516,7 +510,7 @@ class TestFileState(TestCase, LoaderModuleMockMixin):
comt = \
'Directory {0} is set for removal'.format(name)
ret.update({'comment': comt,
'pchanges': {'removed': name},
'changes': {'removed': name},
'result': None})
self.assertDictEqual(filestate.absent(name), ret)
@ -533,7 +527,6 @@ class TestFileState(TestCase, LoaderModuleMockMixin):
ret.update({'comment': comt, 'result': False,
'changes': {}})
self.assertDictEqual(filestate.absent(name), ret)
ret.update({'pchanges': {}})
with patch.object(os.path, 'isdir', mock_f):
with patch.dict(filestate.__opts__, {'test': True}):
@ -552,8 +545,7 @@ class TestFileState(TestCase, LoaderModuleMockMixin):
ret = {'name': name,
'result': False,
'comment': '',
'changes': {},
'pchanges': {}}
'changes': {}}
mock_t = MagicMock(return_value=True)
mock_f = MagicMock(return_value=False)
@ -589,7 +581,7 @@ class TestFileState(TestCase, LoaderModuleMockMixin):
mock_f = MagicMock(return_value=False)
comt = ('Must provide name to file.missing')
ret.update({'comment': comt, 'name': '', 'pchanges': {}})
ret.update({'comment': comt, 'name': '', 'changes': {}})
self.assertDictEqual(filestate.missing(''), ret)
with patch.object(os.path, 'exists', mock_t):
@ -680,7 +672,7 @@ class TestFileState(TestCase, LoaderModuleMockMixin):
'file.manage_file': mock_ex,
'cmd.run_all': mock_cmd_fail}):
comt = ('Destination file name is required')
ret.update({'comment': comt, 'name': '', 'pchanges': {}})
ret.update({'comment': comt, 'name': '', 'changes': {}})
self.assertDictEqual(filestate.managed(''), ret)
with patch.object(os.path, 'isfile', mock_f):
@ -785,13 +777,12 @@ class TestFileState(TestCase, LoaderModuleMockMixin):
comt = ('check_cmd execution failed')
ret.update({'comment': comt, 'result': False, 'skip_watch': True})
ret.pop('pchanges')
self.assertDictEqual(filestate.managed
(name, user=user, group=group,
check_cmd='A'), ret)
comt = ('check_cmd execution failed')
ret.update({'comment': True, 'pchanges': {}})
ret.update({'comment': True, 'changes': {}})
ret.pop('skip_watch', None)
self.assertDictEqual(filestate.managed
(name, user=user, group=group),
@ -848,7 +839,7 @@ class TestFileState(TestCase, LoaderModuleMockMixin):
ret = {'name': name,
'result': False,
'comment': '',
'pchanges': {},
'changes': {},
'changes': {}}
comt = ('Must provide name to file.directory')
@ -940,12 +931,10 @@ class TestFileState(TestCase, LoaderModuleMockMixin):
else:
comt = ('The following files will be changed:\n{0}:'
' directory - new\n'.format(name))
p_chg = {name: {'directory': 'new'}}
ret.update({
'comment': comt,
'result': None,
'pchanges': p_chg,
'changes': {}
'changes': {name: {'directory': 'new'}}
})
self.assertDictEqual(filestate.directory(name,
user=user,
@ -956,7 +945,7 @@ class TestFileState(TestCase, LoaderModuleMockMixin):
with patch.object(os.path, 'isdir', mock_f):
comt = ('No directory to create {0} in'
.format(name))
ret.update({'comment': comt, 'result': False, 'changes': {}})
ret.update({'comment': comt, 'result': False})
self.assertDictEqual(filestate.directory
(name, user=user, group=group),
ret)
@ -975,7 +964,7 @@ class TestFileState(TestCase, LoaderModuleMockMixin):
'options "ignore_files" and '
'"ignore_dirs" at the same '
'time.',
'pchanges': {}})
'changes': {}})
with patch.object(os.path, 'isdir', mock_t):
self.assertDictEqual(filestate.directory
(name, user=user,
@ -1003,7 +992,6 @@ class TestFileState(TestCase, LoaderModuleMockMixin):
ret = {'name': name,
'result': False,
'comment': '',
'pchanges': {},
'changes': {}}
comt = ("'mode' is not allowed in 'file.recurse'."
@ -1092,7 +1080,7 @@ class TestFileState(TestCase, LoaderModuleMockMixin):
'changes': {}}
comt = ('Must provide name to file.replace')
ret.update({'comment': comt, 'name': '', 'pchanges': {}})
ret.update({'comment': comt, 'name': '', 'changes': {}})
self.assertDictEqual(filestate.replace('', pattern, repl), ret)
mock_t = MagicMock(return_value=True)
@ -1126,7 +1114,6 @@ class TestFileState(TestCase, LoaderModuleMockMixin):
ret = {'name': name,
'result': False,
'comment': '',
'pchanges': {},
'changes': {}}
comt = ('Must provide name to file.blockreplace')
@ -1146,8 +1133,7 @@ class TestFileState(TestCase, LoaderModuleMockMixin):
with patch.dict(filestate.__opts__, {'test': True}):
comt = ('Changes would be made')
ret.update({'comment': comt, 'result': None,
'changes': {'diff': True},
'pchanges': {'diff': True}})
'changes': {'diff': True}})
self.assertDictEqual(filestate.blockreplace(name), ret)
# 'comment' function tests: 1
@ -1163,7 +1149,6 @@ class TestFileState(TestCase, LoaderModuleMockMixin):
ret = {'name': name,
'result': False,
'comment': '',
'pchanges': {},
'changes': {}}
comt = ('Must provide name to file.comment')
@ -1194,14 +1179,15 @@ class TestFileState(TestCase, LoaderModuleMockMixin):
'file.comment_line': mock_t}):
with patch.dict(filestate.__opts__, {'test': True}):
comt = ('File {0} is set to be updated'.format(name))
ret.update({'comment': comt, 'result': None, 'pchanges': {name: 'updated'}})
ret.update({'comment': comt, 'result': None, 'changes': {name: 'updated'}})
self.assertDictEqual(filestate.comment(name, regex), ret)
with patch.dict(filestate.__opts__, {'test': False}):
with patch.object(salt.utils.files, 'fopen',
MagicMock(mock_open())):
comt = ('Commented lines successfully')
ret.update({'comment': comt, 'result': True})
ret.update({'comment': comt, 'result': True,
'changes': {}})
self.assertDictEqual(filestate.comment(name, regex),
ret)
@ -1216,7 +1202,6 @@ class TestFileState(TestCase, LoaderModuleMockMixin):
regex = 'bind 127.0.0.1'
ret = {'name': name,
'pchanges': {},
'result': False,
'comment': '',
'changes': {}}
@ -1249,14 +1234,16 @@ class TestFileState(TestCase, LoaderModuleMockMixin):
with patch.dict(filestate.__opts__, {'test': True}):
comt = ('File {0} is set to be updated'.format(name))
ret.update({'comment': comt, 'result': None, 'pchanges': {name: 'updated'}, })
ret.update({'comment': comt, 'result': None,
'changes': {name: 'updated'}})
self.assertDictEqual(filestate.uncomment(name, regex), ret)
with patch.dict(filestate.__opts__, {'test': False}):
with patch.object(salt.utils.files, 'fopen',
MagicMock(mock_open())):
comt = ('Uncommented lines successfully')
ret.update({'comment': comt, 'result': True})
ret.update({'comment': comt, 'result': True,
'changes': {}})
self.assertDictEqual(filestate.uncomment(name, regex), ret)
# 'prepend' function tests: 1
@ -1276,7 +1263,6 @@ class TestFileState(TestCase, LoaderModuleMockMixin):
ret = {'name': name,
'result': False,
'comment': '',
'pchanges': {},
'changes': {}}
comt = ('Must provide name to file.prepend')
@ -1299,24 +1285,23 @@ class TestFileState(TestCase, LoaderModuleMockMixin):
'file.prepend': mock_t}):
comt = ('The following files will be changed:\n/tmp/etc:'
' directory - new\n')
pchanges = {'/tmp/etc': {'directory': 'new'}}
changes = {'/tmp/etc': {'directory': 'new'}}
if salt.utils.platform.is_windows():
comt = 'The directory "c:\\tmp\\etc" will be changed'
pchanges = {'c:\\tmp\\etc': {'directory': 'new'}}
ret.update({'comment': comt, 'name': name, 'pchanges': pchanges})
changes = {'c:\\tmp\\etc': {'directory': 'new'}}
ret.update({'comment': comt, 'name': name, 'changes': changes})
self.assertDictEqual(filestate.prepend(name, makedirs=True),
ret)
with patch.object(os.path, 'isabs', mock_f):
comt = ('Specified file {0} is not an absolute path'
.format(name))
ret.update({'comment': comt, 'pchanges': {}})
ret.update({'comment': comt, 'changes': {}})
self.assertDictEqual(filestate.prepend(name), ret)
with patch.object(os.path, 'isabs', mock_t):
with patch.object(os.path, 'exists', mock_t):
comt = ("Failed to load template file {0}".format(source))
ret.pop('pchanges')
ret.update({'comment': comt, 'name': source, 'data': []})
self.assertDictEqual(filestate.prepend(name, source=source),
ret)
@ -1330,8 +1315,9 @@ class TestFileState(TestCase, LoaderModuleMockMixin):
change = {'diff': 'Replace binary file'}
comt = ('File {0} is set to be updated'
.format(name))
ret.update({'comment': comt, 'result': None,
'changes': change, 'pchanges': {}})
ret.update({'comment': comt,
'result': None,
'changes': change})
self.assertDictEqual(filestate.prepend
(name, text=text), ret)
@ -1849,7 +1835,6 @@ class TestFileState(TestCase, LoaderModuleMockMixin):
expected_ret = {
'name': fake_name,
'changes': {'retained': [], 'deleted': [], 'ignored': []},
'pchanges': {'retained': [], 'deleted': [], 'ignored': []},
'result': True,
'comment': 'Name provided to file.retention must be a directory',
}
@ -1895,8 +1880,7 @@ class TestFileState(TestCase, LoaderModuleMockMixin):
deleted_files = sorted(list(set(fake_file_list) - retained_files - set(ignored_files)), reverse=True)
retained_files = sorted(list(retained_files), reverse=True)
changes = {'retained': retained_files, 'deleted': deleted_files, 'ignored': ignored_files}
expected_ret['pchanges'] = changes
expected_ret['changes'] = {'retained': retained_files, 'deleted': deleted_files, 'ignored': ignored_files}
if test:
expected_ret['result'] = None
expected_ret['comment'] = ('{0} backups would have been removed from {1}.\n'
@ -1904,7 +1888,6 @@ class TestFileState(TestCase, LoaderModuleMockMixin):
else:
expected_ret['comment'] = ('{0} backups were removed from {1}.\n'
''.format(len(deleted_files), fake_name))
expected_ret['changes'] = changes
mock_remove.assert_has_calls(
[call(os.path.join(fake_name, x)) for x in deleted_files],
any_order=True

View file

@ -69,13 +69,12 @@ class LinuxAclTestCase(TestCase, LoaderModuleMockMixin):
''.format(acl_name, perms))
ret = {'name': name,
'comment': comt,
'changes': {},
'pchanges': {'new': {'acl_name': acl_name,
'changes': {'new': {'acl_name': acl_name,
'acl_type': acl_type,
'perms': perms},
'old': {'acl_name': acl_name,
'acl_type': acl_type,
'perms': 'r-x'}},
'old': {'acl_name': acl_name,
'acl_type': acl_type,
'perms': 'r-x'}},
'result': None}
self.assertDictEqual(linux_acl.present(name, acl_type, acl_name,
@ -92,7 +91,6 @@ class LinuxAclTestCase(TestCase, LoaderModuleMockMixin):
'old': {'acl_name': acl_name,
'acl_type': acl_type,
'perms': 'r-x'}},
'pchanges': {},
'result': True}
self.assertDictEqual(linux_acl.present(name, acl_type,
acl_name, perms),
@ -106,7 +104,6 @@ class LinuxAclTestCase(TestCase, LoaderModuleMockMixin):
ret = {'name': name,
'comment': comt,
'changes': {},
'pchanges': {},
'result': False}
self.assertDictEqual(linux_acl.present(name, acl_type,
acl_name, perms),
@ -118,10 +115,9 @@ class LinuxAclTestCase(TestCase, LoaderModuleMockMixin):
'for {0}: {1}'.format(acl_name, perms))
ret = {'name': name,
'comment': comt,
'changes': {},
'pchanges': {'new': {'acl_name': acl_name,
'acl_type': acl_type,
'perms': perms}},
'changes': {'new': {'acl_name': acl_name,
'acl_type': acl_type,
'perms': perms}},
'result': None}
self.assertDictEqual(linux_acl.present(name, acl_type,
acl_name, perms),
@ -135,7 +131,6 @@ class LinuxAclTestCase(TestCase, LoaderModuleMockMixin):
'changes': {'new': {'acl_name': acl_name,
'acl_type': acl_type,
'perms': perms}},
'pchanges': {},
'result': True}
self.assertDictEqual(linux_acl.present(name, acl_type,
acl_name, perms),
@ -149,7 +144,6 @@ class LinuxAclTestCase(TestCase, LoaderModuleMockMixin):
ret = {'name': name,
'comment': comt,
'changes': {},
'pchanges': {},
'result': False}
self.assertDictEqual(linux_acl.present(name, acl_type,
acl_name, perms),
@ -163,13 +157,12 @@ class LinuxAclTestCase(TestCase, LoaderModuleMockMixin):
''.format(acl_name, perms))
ret = {'name': name,
'comment': comt,
'changes': {},
'pchanges': {'new': {'acl_name': acl_name,
'changes': {'new': {'acl_name': acl_name,
'acl_type': acl_type,
'perms': perms},
'old': {'acl_name': acl_name,
'acl_type': acl_type,
'perms': 'rwx'}},
'old': {'acl_name': acl_name,
'acl_type': acl_type,
'perms': 'rwx'}},
'result': None}
self.assertDictEqual(linux_acl.present(name, acl_type, acl_name,
@ -183,7 +176,6 @@ class LinuxAclTestCase(TestCase, LoaderModuleMockMixin):
ret = {'name': name,
'comment': comt,
'changes': {},
'pchanges': {},
'result': True}
self.assertDictEqual(linux_acl.present(name, acl_type, acl_name,
@ -191,8 +183,7 @@ class LinuxAclTestCase(TestCase, LoaderModuleMockMixin):
# No acl type
comt = ('ACL Type does not exist')
ret = {'name': name, 'comment': comt, 'result': False,
'changes': {}, 'pchanges': {}}
ret = {'name': name, 'comment': comt, 'result': False, 'changes': {}}
self.assertDictEqual(linux_acl.present(name, acl_type, acl_name,
perms), ret)

View file

@ -527,56 +527,6 @@ class UtilStateMergeSubreturnTestcase(TestCase):
'alarms': secondary_changes,
})
def test_merge_pchanges(self):
primary_pchanges = {'old': None, 'new': 'my_resource'}
secondary_pchanges = {'old': None, 'new': ['alarm-1', 'alarm-2']}
# Neither main nor sub pchanges case
m = copy.deepcopy(self.main_ret)
s = copy.deepcopy(self.sub_ret)
res = salt.utils.state.merge_subreturn(m, s)
self.assertNotIn('pchanges', res)
# No main pchanges, sub pchanges
m = copy.deepcopy(self.main_ret)
s = copy.deepcopy(self.sub_ret)
s['pchanges'] = copy.deepcopy(secondary_pchanges)
res = salt.utils.state.merge_subreturn(m, s)
self.assertDictEqual(res['pchanges'], {
'secondary': secondary_pchanges
})
# Main pchanges, no sub pchanges
m = copy.deepcopy(self.main_ret)
m['pchanges'] = copy.deepcopy(primary_pchanges)
s = copy.deepcopy(self.sub_ret)
res = salt.utils.state.merge_subreturn(m, s)
self.assertDictEqual(res['pchanges'], primary_pchanges)
# Both main and sub pchanges, new pchanges don't affect existing ones
m = copy.deepcopy(self.main_ret)
m['pchanges'] = copy.deepcopy(primary_pchanges)
s = copy.deepcopy(self.sub_ret)
s['pchanges'] = copy.deepcopy(secondary_pchanges)
res = salt.utils.state.merge_subreturn(m, s)
self.assertDictEqual(res['pchanges'], {
'old': None,
'new': 'my_resource',
'secondary': secondary_pchanges,
})
# The subkey parameter is respected
m = copy.deepcopy(self.main_ret)
m['pchanges'] = copy.deepcopy(primary_pchanges)
s = copy.deepcopy(self.sub_ret)
s['pchanges'] = copy.deepcopy(secondary_pchanges)
res = salt.utils.state.merge_subreturn(m, s, subkey='alarms')
self.assertDictEqual(res['pchanges'], {
'old': None,
'new': 'my_resource',
'alarms': secondary_pchanges,
})
def test_merge_comments(self):
main_comment_1 = 'First primary comment.'
main_comment_2 = 'Second primary comment.'