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), Prefer to keep line lengths short (use multiple lines as needed),
and end with punctuation (e.g. a period) to delimit multiple comments. 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:: .. note::
States should not return data which cannot be serialized such as frozensets. States should not return data which cannot be serialized such as frozensets.
@ -448,7 +444,6 @@ Example state module
'changes': {}, 'changes': {},
'result': False, 'result': False,
'comment': '', 'comment': '',
'pchanges': {},
} }
# Start with basic error-checking. Do all the passed parameters make sense # Start with basic error-checking. Do all the passed parameters make sense
@ -469,7 +464,7 @@ Example state module
# in ``test=true`` mode. # in ``test=true`` mode.
if __opts__['test'] == True: if __opts__['test'] == True:
ret['comment'] = 'The state of "{0}" will be changed.'.format(name) ret['comment'] = 'The state of "{0}" will be changed.'.format(name)
ret['pchanges'] = { ret['changes'] = {
'old': current_state, 'old': current_state,
'new': 'Description, diff, whatever of the new 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, dir_result = __states__['file.directory'](full_path,
user=user, user=user,
group=group, group=group,
recurse=recurse, recurse=recurse)
test=__opts__['test'])
log.debug('file.directory: %s', dir_result) log.debug('file.directory: %s', dir_result)
if __opts__['test']: if dir_result.get('changes'):
if dir_result.get('pchanges'): ret['changes']['updated ownership'] = True
ret['changes']['updated ownership'] = True try:
else: if not dir_result['result']:
try: enforce_failed.append(full_path)
if dir_result['result']: except (KeyError, TypeError):
if dir_result['changes']: log.warning(
ret['changes']['updated ownership'] = True 'Bad state return %s for file.directory state on %s',
else: dir_result, dirname
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: for filename in enforce_files + enforce_links:
full_path = os.path.join(name, filename) full_path = os.path.join(name, filename)

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -89,11 +89,11 @@ def datacenter_configured(name):
dc_name = name dc_name = name
log.info('Running datacenter_configured for datacenter \'{0}\'' log.info('Running datacenter_configured for datacenter \'{0}\''
''.format(dc_name)) ''.format(dc_name))
ret = {'name': name, 'changes': {}, 'pchanges': {}, ret = {'name': name,
'result': None, 'comment': 'Default'} 'changes': {},
'result': None,
'comment': 'Default'}
comments = [] comments = []
changes = {}
pchanges = {}
si = None si = None
try: try:
si = __salt__['vsphere.get_service_instance_via_proxy']() si = __salt__['vsphere.get_service_instance_via_proxy']()
@ -103,27 +103,19 @@ def datacenter_configured(name):
if __opts__['test']: if __opts__['test']:
comments.append('State will create ' comments.append('State will create '
'datacenter \'{0}\'.'.format(dc_name)) 'datacenter \'{0}\'.'.format(dc_name))
log.info(comments[-1])
pchanges.update({'new': {'name': dc_name}})
else: else:
log.debug('Creating datacenter \'{0}\'. '.format(dc_name)) log.debug('Creating datacenter \'{0}\'. '.format(dc_name))
__salt__['vsphere.create_datacenter'](dc_name, si) __salt__['vsphere.create_datacenter'](dc_name, si)
comments.append('Created datacenter \'{0}\'.'.format(dc_name)) comments.append('Created datacenter \'{0}\'.'.format(dc_name))
log.info(comments[-1]) log.info(comments[-1])
changes.update({'new': {'name': dc_name}}) ret['changes'].update({'new': {'name': dc_name}})
else: else:
comments.append('Datacenter \'{0}\' already exists. Nothing to be ' comments.append('Datacenter \'{0}\' already exists. Nothing to be '
'done.'.format(dc_name)) 'done.'.format(dc_name))
log.info(comments[-1]) log.info(comments[-1])
__salt__['vsphere.disconnect'](si) __salt__['vsphere.disconnect'](si)
if __opts__['test'] and pchanges: ret['comment'] = '\n'.join(comments)
ret_status = None ret['result'] = None if __opts__['test'] and ret['changes'] else True
else:
ret_status = True
ret.update({'result': ret_status,
'comment': '\n'.join(comments),
'changes': changes,
'pchanges': pchanges})
return ret return ret
except salt.exceptions.CommandExecutionError as exc: except salt.exceptions.CommandExecutionError as exc:
log.error('Error: {}'.format(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'] else proxy_details['esxi_host']
log.info('Running state {0} for host \'{1}\''.format(name, hostname)) log.info('Running state {0} for host \'{1}\''.format(name, hostname))
# Variable used to return the result of the invocation # Variable used to return the result of the invocation
ret = {'name': name, 'result': None, 'changes': {}, ret = {'name': name,
'pchanges': {}, 'comments': None} 'result': None,
'changes': {},
'comments': None}
# Signals if errors have been encountered # Signals if errors have been encountered
errors = False errors = False
# Signals if changes are required # 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 None if __opts__['test'] else # running in test mode
False if errors else True) # found errors; defaults to True False if errors else True) # found errors; defaults to True
ret.update({'result': result, ret.update({'result': result,
'comment': '\n'.join(comments)}) 'comment': '\n'.join(comments),
if changes: 'changes': diskgroup_changes})
if __opts__['test']:
ret['pchanges'] = diskgroup_changes
elif changes:
ret['changes'] = diskgroup_changes
return ret return ret
@ -1387,8 +1385,10 @@ def host_cache_configured(name, enabled, datastore, swap_size='100%',
else proxy_details['esxi_host'] else proxy_details['esxi_host']
log.trace('hostname = %s', hostname) log.trace('hostname = %s', hostname)
log.info('Running host_cache_swap_configured for host \'%s\'', hostname) log.info('Running host_cache_swap_configured for host \'%s\'', hostname)
ret = {'name': hostname, 'comment': 'Default comments', ret = {'name': hostname,
'result': None, 'changes': {}, 'pchanges': {}} 'comment': 'Default comments',
'result': None,
'changes': {}}
result = None if __opts__['test'] else True # We assume success result = None if __opts__['test'] else True # We assume success
needs_setting = False needs_setting = False
comments = [] comments = []
@ -1582,11 +1582,8 @@ def host_cache_configured(name, enabled, datastore, swap_size='100%',
__salt__['vsphere.disconnect'](si) __salt__['vsphere.disconnect'](si)
log.info(comments[-1]) log.info(comments[-1])
ret.update({'comment': '\n'.join(comments), ret.update({'comment': '\n'.join(comments),
'result': result}) 'result': result,
if __opts__['test']: 'changes': changes})
ret['pchanges'] = changes
else:
ret['changes'] = changes
return ret return ret
except CommandExecutionError as err: except CommandExecutionError as err:
log.error('Error: %s.', 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 Check the symlink function
''' '''
pchanges = {} changes = {}
if not os.path.exists(name) and not __salt__['file.is_link'](name): 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( return None, 'Symlink {0} to {1} is set for creation'.format(
name, target name, target
), pchanges ), changes
if __salt__['file.is_link'](name): if __salt__['file.is_link'](name):
if __salt__['file.readlink'](name) != target: 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( return None, 'Link {0} target is set to be changed to {1}'.format(
name, target name, target
), pchanges ), changes
else: else:
result = True result = True
msg = 'The symlink {0} is present'.format(name) msg = 'The symlink {0} is present'.format(name)
if not _check_symlink_ownership(name, user, group, win_owner): if not _check_symlink_ownership(name, user, group, win_owner):
result = None result = None
pchanges['ownership'] = '{0}:{1}'.format(*_get_symlink_ownership(name)) changes['ownership'] = '{0}:{1}'.format(*_get_symlink_ownership(name))
msg += ( msg += (
', but the ownership of the symlink would be changed ' ', but the ownership of the symlink would be changed '
'from {2}:{3} to {0}:{1}' 'from {2}:{3} to {0}:{1}'
).format(user, group, *_get_symlink_ownership(name)) ).format(user, group, *_get_symlink_ownership(name))
return result, msg, pchanges return result, msg, changes
else: else:
if force: if force:
return None, ('The file or directory {0} is set for removal to ' return None, ('The file or directory {0} is set for removal to '
'make way for a new symlink targeting {1}' '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} ' 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): def _test_owner(kwargs, user=None):
@ -1222,12 +1222,12 @@ def _shortcut_check(name,
''' '''
Check the shortcut function Check the shortcut function
''' '''
pchanges = {} changes = {}
if not os.path.exists(name): if not os.path.exists(name):
pchanges['new'] = name changes['new'] = name
return None, 'Shortcut "{0}" to "{1}" is set for creation'.format( return None, 'Shortcut "{0}" to "{1}" is set for creation'.format(
name, target name, target
), pchanges ), changes
if os.path.isfile(name): if os.path.isfile(name):
with salt.utils.winapi.Com(): with salt.utils.winapi.Com():
@ -1248,28 +1248,28 @@ def _shortcut_check(name,
) )
if not all(state_checks): if not all(state_checks):
pchanges['change'] = name changes['change'] = name
return None, 'Shortcut "{0}" target is set to be changed to "{1}"'.format( return None, 'Shortcut "{0}" target is set to be changed to "{1}"'.format(
name, target name, target
), pchanges ), changes
else: else:
result = True result = True
msg = 'The shortcut "{0}" is present'.format(name) msg = 'The shortcut "{0}" is present'.format(name)
if not _check_shortcut_ownership(name, user): if not _check_shortcut_ownership(name, user):
result = None result = None
pchanges['ownership'] = '{0}'.format(_get_shortcut_ownership(name)) changes['ownership'] = '{0}'.format(_get_shortcut_ownership(name))
msg += ( msg += (
', but the ownership of the shortcut would be changed ' ', but the ownership of the shortcut would be changed '
'from {1} to {0}' 'from {1} to {0}'
).format(user, _get_shortcut_ownership(name)) ).format(user, _get_shortcut_ownership(name))
return result, msg, pchanges return result, msg, changes
else: else:
if force: if force:
return None, ('The link or directory "{0}" is set for removal to ' return None, ('The link or directory "{0}" is set for removal to '
'make way for a new shortcut targeting "{1}"' '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}" ' 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, def _makedirs(name,
@ -1499,12 +1499,12 @@ def symlink(
msg += '.' msg += '.'
return _error(ret, msg) return _error(ret, msg)
presult, pcomment, ret['pchanges'] = _symlink_check(name, presult, pcomment, pchanges = _symlink_check(name,
target, target,
force, force,
user, user,
group, group,
win_owner) win_owner)
if not os.path.isdir(os.path.dirname(name)): if not os.path.isdir(os.path.dirname(name)):
if makedirs: if makedirs:
@ -1537,6 +1537,7 @@ def symlink(
if __opts__['test']: if __opts__['test']:
ret['result'] = presult ret['result'] = presult
ret['comment'] = pcomment ret['comment'] = pcomment
ret['changes'] = pchanges
return ret return ret
if __salt__['file.is_link'](name): if __salt__['file.is_link'](name):
@ -1659,7 +1660,6 @@ def absent(name,
ret = {'name': name, ret = {'name': name,
'changes': {}, 'changes': {},
'pchanges': {},
'result': True, 'result': True,
'comment': ''} 'comment': ''}
if not name: if not name:
@ -1671,9 +1671,9 @@ def absent(name,
if name == '/': if name == '/':
return _error(ret, 'Refusing to make "/" absent') return _error(ret, 'Refusing to make "/" absent')
if os.path.isfile(name) or os.path.islink(name): if os.path.isfile(name) or os.path.islink(name):
ret['pchanges']['removed'] = name
if __opts__['test']: if __opts__['test']:
ret['result'] = None ret['result'] = None
ret['changes']['removed'] = name
ret['comment'] = 'File {0} is set for removal'.format(name) ret['comment'] = 'File {0} is set for removal'.format(name)
return ret return ret
try: try:
@ -1688,9 +1688,9 @@ def absent(name,
return _error(ret, '{0}'.format(exc)) return _error(ret, '{0}'.format(exc))
elif os.path.isdir(name): elif os.path.isdir(name):
ret['pchanges']['removed'] = name
if __opts__['test']: if __opts__['test']:
ret['result'] = None ret['result'] = None
ret['changes']['removed'] = name
ret['comment'] = 'Directory {0} is set for removal'.format(name) ret['comment'] = 'Directory {0} is set for removal'.format(name)
return ret return ret
try: try:
@ -1849,7 +1849,6 @@ def exists(name,
ret = {'name': name, ret = {'name': name,
'changes': {}, 'changes': {},
'pchanges': {},
'result': True, 'result': True,
'comment': ''} 'comment': ''}
if not name: if not name:
@ -1874,7 +1873,6 @@ def missing(name,
ret = {'name': name, ret = {'name': name,
'changes': {}, 'changes': {},
'pchanges': {},
'result': True, 'result': True,
'comment': ''} 'comment': ''}
if not name: if not name:
@ -2483,7 +2481,6 @@ def managed(name,
name = os.path.expanduser(name) name = os.path.expanduser(name)
ret = {'changes': {}, ret = {'changes': {},
'pchanges': {},
'comment': '', 'comment': '',
'name': name, 'name': name,
'result': True} 'result': True}
@ -3226,7 +3223,6 @@ def directory(name,
name = os.path.expanduser(name) name = os.path.expanduser(name)
ret = {'name': name, ret = {'name': name,
'changes': {}, 'changes': {},
'pchanges': {},
'result': True, 'result': True,
'comment': ''} 'comment': ''}
if not name: if not name:
@ -3300,19 +3296,19 @@ def directory(name,
# Remove whatever is in the way # Remove whatever is in the way
if os.path.isfile(name): if os.path.isfile(name):
if __opts__['test']: if __opts__['test']:
ret['pchanges']['forced'] = 'File was forcibly replaced' ret['changes']['forced'] = 'File would be forcibly replaced'
else: else:
os.remove(name) os.remove(name)
ret['changes']['forced'] = 'File was forcibly replaced' ret['changes']['forced'] = 'File was forcibly replaced'
elif __salt__['file.is_link'](name): elif __salt__['file.is_link'](name):
if __opts__['test']: if __opts__['test']:
ret['pchanges']['forced'] = 'Symlink was forcibly replaced' ret['changes']['forced'] = 'Symlink would be forcibly replaced'
else: else:
__salt__['file.remove'](name) __salt__['file.remove'](name)
ret['changes']['forced'] = 'Symlink was forcibly replaced' ret['changes']['forced'] = 'Symlink was forcibly replaced'
else: else:
if __opts__['test']: if __opts__['test']:
ret['pchanges']['forced'] = 'Directory was forcibly replaced' ret['changes']['forced'] = 'Directory would be forcibly replaced'
else: else:
__salt__['file.remove'](name) __salt__['file.remove'](name)
ret['changes']['forced'] = 'Directory was forcibly replaced' ret['changes']['forced'] = 'Directory was forcibly replaced'
@ -3341,11 +3337,11 @@ def directory(name,
require, exclude_pat, max_depth, follow_symlinks) require, exclude_pat, max_depth, follow_symlinks)
if pchanges: 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 # Don't run through the reset of the function if there are no changes to be
# made # made
if not ret['pchanges'] or __opts__['test']: if __opts__['test'] or not ret['changes']:
ret['result'] = presult ret['result'] = presult
ret['comment'] = pcomment ret['comment'] = pcomment
return ret return ret
@ -3764,7 +3760,6 @@ def recurse(name,
ret = { ret = {
'name': name, 'name': name,
'changes': {}, 'changes': {},
'pchanges': {},
'result': True, 'result': True,
'comment': {} # { path: [comment, ...] } 'comment': {} # { path: [comment, ...] }
} }
@ -4063,7 +4058,6 @@ def retention_schedule(name, retain, strptime_format=None, timezone=None):
name = os.path.expanduser(name) name = os.path.expanduser(name)
ret = {'name': name, ret = {'name': name,
'changes': {'retained': [], 'deleted': [], 'ignored': []}, 'changes': {'retained': [], 'deleted': [], 'ignored': []},
'pchanges': {'retained': [], 'deleted': [], 'ignored': []},
'result': True, 'result': True,
'comment': ''} 'comment': ''}
if not name: if not name:
@ -4173,7 +4167,7 @@ def retention_schedule(name, retain, strptime_format=None, timezone=None):
'deleted': deletable_files, 'deleted': deletable_files,
'ignored': sorted(list(ignored_files), reverse=True), 'ignored': sorted(list(ignored_files), reverse=True),
} }
ret['pchanges'] = changes ret['changes'] = changes
# TODO: track and report how much space was / would be reclaimed # TODO: track and report how much space was / would be reclaimed
if __opts__['test']: if __opts__['test']:
@ -4314,7 +4308,6 @@ def line(name, content=None, match=None, mode=None, location=None,
name = os.path.expanduser(name) name = os.path.expanduser(name)
ret = {'name': name, ret = {'name': name,
'changes': {}, 'changes': {},
'pchanges': {},
'result': True, 'result': True,
'comment': ''} 'comment': ''}
if not name: 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, before=before, after=after, show_changes=show_changes,
backup=backup, quiet=quiet, indent=indent) backup=backup, quiet=quiet, indent=indent)
if changes: if changes:
ret['pchanges']['diff'] = changes ret['changes']['diff'] = changes
if __opts__['test']: if __opts__['test']:
ret['result'] = None ret['result'] = None
ret['comment'] = 'Changes would be made:\ndiff:\n{0}'.format(changes) ret['comment'] = 'Changes would be made'
else: else:
ret['result'] = True ret['result'] = True
ret['comment'] = 'Changes were made' ret['comment'] = 'Changes were made'
ret['changes'] = {'diff': changes}
else: else:
ret['result'] = True ret['result'] = True
ret['comment'] = 'No changes needed to be made' ret['comment'] = 'No changes needed to be made'
@ -4505,7 +4497,6 @@ def replace(name,
ret = {'name': name, ret = {'name': name,
'changes': {}, 'changes': {},
'pchanges': {},
'result': True, 'result': True,
'comment': ''} 'comment': ''}
if not name: if not name:
@ -4535,14 +4526,13 @@ def replace(name,
backslash_literal=backslash_literal) backslash_literal=backslash_literal)
if changes: if changes:
ret['pchanges']['diff'] = changes ret['changes']['diff'] = changes
if __opts__['test']: if __opts__['test']:
ret['result'] = None ret['result'] = None
ret['comment'] = 'Changes would have been made:\ndiff:\n{0}'.format(changes) ret['comment'] = 'Changes would have been made'
else: else:
ret['result'] = True ret['result'] = True
ret['comment'] = 'Changes were made' ret['comment'] = 'Changes were made'
ret['changes'] = {'diff': changes}
else: else:
ret['result'] = True ret['result'] = True
ret['comment'] = 'No changes needed to be made' ret['comment'] = 'No changes needed to be made'
@ -4764,7 +4754,6 @@ def blockreplace(
ret = {'name': name, ret = {'name': name,
'changes': {}, 'changes': {},
'pchanges': {},
'result': False, 'result': False,
'comment': ''} 'comment': ''}
if not name: if not name:
@ -4837,13 +4826,11 @@ def blockreplace(
return ret return ret
if changes: if changes:
ret['pchanges'] = {'diff': changes} ret['changes']['diff'] = changes
if __opts__['test']: if __opts__['test']:
ret['changes']['diff'] = ret['pchanges']['diff']
ret['result'] = None ret['result'] = None
ret['comment'] = 'Changes would be made' ret['comment'] = 'Changes would be made'
else: else:
ret['changes']['diff'] = ret['pchanges']['diff']
ret['result'] = True ret['result'] = True
ret['comment'] = 'Changes were made' ret['comment'] = 'Changes were made'
else: else:
@ -4894,7 +4881,6 @@ def comment(name, regex, char='#', backup='.bak'):
ret = {'name': name, ret = {'name': name,
'changes': {}, 'changes': {},
'pchanges': {},
'result': False, 'result': False,
'comment': ''} 'comment': ''}
if not name: if not name:
@ -4924,8 +4910,8 @@ def comment(name, regex, char='#', backup='.bak'):
else: else:
return _error(ret, '{0}: Pattern not found'.format(unanchor_regex)) return _error(ret, '{0}: Pattern not found'.format(unanchor_regex))
ret['pchanges'][name] = 'updated'
if __opts__['test']: if __opts__['test']:
ret['changes'][name] = 'updated'
ret['comment'] = 'File {0} is set to be updated'.format(name) ret['comment'] = 'File {0} is set to be updated'.format(name)
ret['result'] = None ret['result'] = None
return ret return ret
@ -5004,7 +4990,6 @@ def uncomment(name, regex, char='#', backup='.bak'):
ret = {'name': name, ret = {'name': name,
'changes': {}, 'changes': {},
'pchanges': {},
'result': False, 'result': False,
'comment': ''} 'comment': ''}
if not name: if not name:
@ -5031,26 +5016,20 @@ def uncomment(name, regex, char='#', backup='.bak'):
else: else:
return _error(ret, '{0}: Pattern not found'.format(regex)) return _error(ret, '{0}: Pattern not found'.format(regex))
ret['pchanges'][name] = 'updated'
if __opts__['test']: if __opts__['test']:
ret['changes'][name] = 'updated'
ret['comment'] = 'File {0} is set to be updated'.format(name) ret['comment'] = 'File {0} is set to be updated'.format(name)
ret['result'] = None ret['result'] = None
return ret return ret
with salt.utils.files.fopen(name, 'rb') as fp_: with salt.utils.files.fopen(name, 'rb') as fp_:
slines = fp_.read() slines = salt.utils.data.decode(fp_.readlines())
if six.PY3:
slines = slines.decode(__salt_system_encoding__)
slines = slines.splitlines(True)
# Perform the edit # Perform the edit
__salt__['file.comment_line'](name, regex, char, False, backup) __salt__['file.comment_line'](name, regex, char, False, backup)
with salt.utils.files.fopen(name, 'rb') as fp_: with salt.utils.files.fopen(name, 'rb') as fp_:
nlines = fp_.read() nlines = salt.utils.data.decode(fp_.readlines())
if six.PY3:
nlines = nlines.decode(__salt_system_encoding__)
nlines = nlines.splitlines(True)
# Check the result # Check the result
ret['result'] = __salt__['file.search']( ret['result'] = __salt__['file.search'](
@ -5214,10 +5193,9 @@ def append(name,
.. versionadded:: 0.9.5 .. versionadded:: 0.9.5
''' '''
ret = {'name': name, ret = {'name': name,
'changes': {}, 'changes': {},
'pchanges': {}, 'result': False,
'result': False, 'comment': ''}
'comment': ''}
if not name: if not name:
return _error(ret, 'Must provide name to file.append') return _error(ret, 'Must provide name to file.append')
@ -5252,12 +5230,12 @@ def append(name,
except CommandExecutionError as exc: except CommandExecutionError as exc:
return _error(ret, 'Drive {0} is not mapped'.format(exc.message)) return _error(ret, 'Drive {0} is not mapped'.format(exc.message))
if salt.utils.platform.is_windows(): check_res, check_msg, check_changes = _check_directory_win(dirname) \
check_res, check_msg, ret['pchanges'] = _check_directory_win(dirname) if salt.utils.platform.is_windows() \
else: else _check_directory(dirname)
check_res, check_msg, ret['pchanges'] = _check_directory(dirname)
if not check_res: if not check_res:
ret['changes'] = check_changes
return _error(ret, check_msg) return _error(ret, check_msg)
check_res, check_msg = _check_file(name) check_res, check_msg = _check_file(name)
@ -5506,7 +5484,6 @@ def prepend(name,
ret = {'name': name, ret = {'name': name,
'changes': {}, 'changes': {},
'pchanges': {},
'result': False, 'result': False,
'comment': ''} 'comment': ''}
if not name: if not name:
@ -5536,11 +5513,12 @@ def prepend(name,
except CommandExecutionError as exc: except CommandExecutionError as exc:
return _error(ret, 'Drive {0} is not mapped'.format(exc.message)) return _error(ret, 'Drive {0} is not mapped'.format(exc.message))
if salt.utils.platform.is_windows(): check_res, check_msg, check_changes = _check_directory_win(dirname) \
check_res, check_msg, ret['pchanges'] = _check_directory_win(dirname) if salt.utils.platform.is_windows() \
else: else _check_directory(dirname)
check_res, check_msg, ret['pchanges'] = _check_directory(dirname)
if not check_res: if not check_res:
ret['changes'] = check_changes
return _error(ret, check_msg) return _error(ret, check_msg)
check_res, check_msg = _check_file(name) check_res, check_msg = _check_file(name)
@ -7399,17 +7377,18 @@ def shortcut(
msg += '.' msg += '.'
return _error(ret, msg) return _error(ret, msg)
presult, pcomment, ret['pchanges'] = _shortcut_check(name, presult, pcomment, pchanges = _shortcut_check(name,
target, target,
arguments, arguments,
working_dir, working_dir,
description, description,
icon_location, icon_location,
force, force,
user) user)
if __opts__['test']: if __opts__['test']:
ret['result'] = presult ret['result'] = presult
ret['comment'] = pcomment ret['comment'] = pcomment
ret['changes'] = pchanges
return ret return ret
if not os.path.isdir(os.path.dirname(name)): if not os.path.isdir(os.path.dirname(name)):

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -94,8 +94,6 @@ def managed(name,
compliance_report: ``False`` compliance_report: ``False``
Return the compliance report in the comment. 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 .. versionadded:: 2017.7.3

View file

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

View file

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

View file

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

View file

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

View file

@ -156,8 +156,10 @@ def default_vsan_policy_configured(name, policy):
'\'{1}\''.format(name, vcenter)) '\'{1}\''.format(name, vcenter))
log.trace('policy = {0}'.format(policy)) log.trace('policy = {0}'.format(policy))
changes_required = False changes_required = False
ret = {'name': name, 'changes': {}, 'result': None, 'comment': None, ret = {'name': name,
'pchanges': {}} 'changes': {},
'result': None,
'comment': None}
comments = [] comments = []
changes = {} changes = {}
changes_required = False changes_required = False
@ -266,13 +268,11 @@ def default_vsan_policy_configured(name, policy):
'Nothing to be done.'.format(vcenter)), 'Nothing to be done.'.format(vcenter)),
'result': True}) 'result': True})
else: else:
ret.update({'comment': '\n'.join(comments)}) ret.update({
if __opts__['test']: 'comment': '\n'.join(comments),
ret.update({'pchanges': changes, 'changes': changes,
'result': None}) 'result': None if __opts__['test'] else True,
else: })
ret.update({'changes': changes,
'result': True})
return ret return ret
@ -286,8 +286,10 @@ def storage_policies_configured(name, policies):
comments = [] comments = []
changes = [] changes = []
changes_required = False changes_required = False
ret = {'name': name, 'changes': {}, 'result': None, 'comment': None, ret = {'name': name,
'pchanges': {}} 'changes': {},
'result': None,
'comment': None}
log.trace('policies = {0}'.format(policies)) log.trace('policies = {0}'.format(policies))
si = None si = None
try: try:
@ -430,13 +432,11 @@ def storage_policies_configured(name, policies):
'Nothing to be done.'.format(vcenter)), 'Nothing to be done.'.format(vcenter)),
'result': True}) 'result': True})
else: else:
ret.update({'comment': '\n'.join(comments)}) ret.update({
if __opts__['test']: 'comment': '\n'.join(comments),
ret.update({'pchanges': {'storage_policies': changes}, 'changes': {'storage_policies': changes},
'result': None}) 'result': None if __opts__['test'] else True,
else: })
ret.update({'changes': {'storage_policies': changes},
'result': True})
return ret return ret
@ -454,8 +454,10 @@ def default_storage_policy_assigned(name, policy, datastore):
''.format(name, policy, datastore)) ''.format(name, policy, datastore))
changes = {} changes = {}
changes_required = False changes_required = False
ret = {'name': name, 'changes': {}, 'result': None, 'comment': None, ret = {'name': name,
'pchanges': {}} 'changes': {},
'result': None,
'comment': None}
si = None si = None
try: try:
si = __salt__['vsphere.get_service_instance_via_proxy']() 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, ret.update({'comment': exc.strerror,
'result': False if not __opts__['test'] else None}) 'result': False if not __opts__['test'] else None})
return ret return ret
ret['comment'] = comment ret['comment'] = comment
if changes_required: if changes_required:
if __opts__['test']: ret.update({
ret.update({'result': None, 'changes': changes,
'pchanges': changes}) 'result': None if __opts__['test'] else True,
else: })
ret.update({'result': True,
'changes': changes})
else: else:
ret['result'] = True ret['result'] = True
return ret 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, {})) filename=file).get(file, {}))
if __opts__['test'] and status: if __opts__['test'] and status:
ret['pchanges'] = status ret['changes'] = status
ret['changes'] = ret['pchanges']
ret['comment'] = "{0} files changes are set to be undone".format(len(status.keys())) ret['comment'] = "{0} files changes are set to be undone".format(len(status.keys()))
ret['result'] = None ret['result'] = None
elif __opts__['test'] and not status: elif __opts__['test'] and not status:

View file

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

View file

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

View file

@ -212,10 +212,6 @@ def merge_subreturn(original_return, sub_return, subkey=None):
original_return.setdefault('changes', {}) original_return.setdefault('changes', {})
original_return['changes'][subkey] = sub_return['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 return original_return

View file

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

View file

@ -91,7 +91,7 @@ class BotoCloudfrontTestCase(TestCase, LoaderModuleMockMixin):
self.base_ret_with({ self.base_ret_with({
'result': None, 'result': None,
'comment': comment, '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({ self.base_ret_with({
'result': None, 'result': None,
'comment': '\n'.join([header, diff]), 'comment': '\n'.join([header, diff]),
'pchanges': {'diff': diff}, 'changes': {'diff': diff},
}), }),
) )

View file

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

View file

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

View file

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

View file

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

View file

@ -527,56 +527,6 @@ class UtilStateMergeSubreturnTestcase(TestCase):
'alarms': secondary_changes, '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): def test_merge_comments(self):
main_comment_1 = 'First primary comment.' main_comment_1 = 'First primary comment.'
main_comment_2 = 'Second primary comment.' main_comment_2 = 'Second primary comment.'