mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 00:55:19 +00:00
Merge branch '2018.3' into fix_vault_sdb_runner_test
This commit is contained in:
commit
444a4e525f
@ -25,6 +25,7 @@ execution modules
|
||||
aix_group
|
||||
aliases
|
||||
alternatives
|
||||
ansiblegate
|
||||
apache
|
||||
apcups
|
||||
apf
|
||||
|
6
doc/ref/modules/all/salt.modules.ansiblegate.rst
Normal file
6
doc/ref/modules/all/salt.modules.ansiblegate.rst
Normal file
@ -0,0 +1,6 @@
|
||||
========================
|
||||
salt.modules.ansiblegate
|
||||
========================
|
||||
|
||||
.. automodule:: salt.modules.ansiblegate
|
||||
:members:
|
@ -13,6 +13,7 @@ state modules
|
||||
acme
|
||||
alias
|
||||
alternatives
|
||||
ansiblegate
|
||||
apache
|
||||
apache_conf
|
||||
apache_module
|
||||
|
6
doc/ref/states/all/salt.states.ansiblegate.rst
Normal file
6
doc/ref/states/all/salt.states.ansiblegate.rst
Normal file
@ -0,0 +1,6 @@
|
||||
=======================
|
||||
salt.states.ansiblegate
|
||||
=======================
|
||||
|
||||
.. automodule:: salt.states.ansiblegate
|
||||
:members:
|
@ -35,8 +35,8 @@ NAPALM
|
||||
NAPALM (Network Automation and Programmability Abstraction Layer with
|
||||
Multivendor support) is an opensourced Python library that implements a set of
|
||||
functions to interact with different router vendor devices using a unified API.
|
||||
Begin vendor-agnostic simplifies the operations, as the configuration
|
||||
and the interaction with the network device does not rely on a particular vendor.
|
||||
Being vendor-agnostic simplifies operations, as the configuration and
|
||||
interaction with the network device does not rely on a particular vendor.
|
||||
|
||||
.. image:: /_static/napalm_logo.png
|
||||
|
||||
|
@ -420,7 +420,9 @@ def get_url(path, dest='', saltenv='base', makedirs=False, source_hash=None):
|
||||
result = _client().get_url(
|
||||
path, None, makedirs, saltenv, no_cache=True, source_hash=source_hash)
|
||||
if not result:
|
||||
log.error('Unable to fetch file %s from saltenv %s.', path, saltenv)
|
||||
log.error('Unable to fetch file %s from saltenv %s.',
|
||||
salt.utils.url.redact_http_basic_auth(path),
|
||||
saltenv)
|
||||
return result
|
||||
|
||||
|
||||
|
@ -4119,7 +4119,7 @@ def get_managed(
|
||||
msg = (
|
||||
'Unable to verify upstream hash of source file {0}, '
|
||||
'please set source_hash or set skip_verify to True'
|
||||
.format(source)
|
||||
.format(salt.utils.url.redact_http_basic_auth(source))
|
||||
)
|
||||
return '', {}, msg
|
||||
|
||||
@ -4151,12 +4151,14 @@ def get_managed(
|
||||
except Exception as exc:
|
||||
# A 404 or other error code may raise an exception, catch it
|
||||
# and return a comment that will fail the calling state.
|
||||
return '', {}, 'Failed to cache {0}: {1}'.format(source, exc)
|
||||
_source = salt.utils.url.redact_http_basic_auth(source)
|
||||
return '', {}, 'Failed to cache {0}: {1}'.format(_source, exc)
|
||||
|
||||
# If cache failed, sfn will be False, so do a truth check on sfn first
|
||||
# as invoking os.path.exists() on a bool raises a TypeError.
|
||||
if not sfn or not os.path.exists(sfn):
|
||||
return sfn, {}, 'Source file \'{0}\' not found'.format(source)
|
||||
_source = salt.utils.url.redact_http_basic_auth(source)
|
||||
return sfn, {}, 'Source file \'{0}\' not found'.format(_source)
|
||||
if sfn == name:
|
||||
raise SaltInvocationError(
|
||||
'Source file cannot be the same as destination'
|
||||
|
@ -50,7 +50,7 @@ def _atrun_enabled():
|
||||
Check to see if atrun is enabled on the system
|
||||
'''
|
||||
name = 'com.apple.atrun'
|
||||
services = salt.utils.mac_utils.available_services()
|
||||
services = __utils__['mac_utils.available_services']()
|
||||
label = None
|
||||
|
||||
if name in services:
|
||||
|
@ -392,55 +392,63 @@ def _present(name,
|
||||
{'old': zones,
|
||||
'new': name}})
|
||||
|
||||
block_icmp = block_icmp or []
|
||||
new_icmp_types = []
|
||||
old_icmp_types = []
|
||||
try:
|
||||
_valid_icmp_types = __salt__['firewalld.get_icmp_types'](
|
||||
permanent=True)
|
||||
_current_icmp_blocks = __salt__['firewalld.list_icmp_block'](name,
|
||||
permanent=True)
|
||||
except CommandExecutionError as err:
|
||||
ret['comment'] = 'Error: {0}'.format(err)
|
||||
return ret
|
||||
if block_icmp or prune_block_icmp:
|
||||
block_icmp = block_icmp or []
|
||||
new_icmp_types = []
|
||||
old_icmp_types = []
|
||||
|
||||
new_icmp_types = set(block_icmp) - set(_current_icmp_blocks)
|
||||
old_icmp_types = []
|
||||
try:
|
||||
_current_icmp_blocks = __salt__['firewalld.list_icmp_block'](name,
|
||||
permanent=True)
|
||||
except CommandExecutionError as err:
|
||||
ret['comment'] = 'Error: {0}'.format(err)
|
||||
return ret
|
||||
|
||||
for icmp_type in new_icmp_types:
|
||||
if icmp_type in _valid_icmp_types:
|
||||
if not __opts__['test']:
|
||||
try:
|
||||
__salt__['firewalld.block_icmp'](name, icmp_type,
|
||||
permanent=True)
|
||||
except CommandExecutionError as err:
|
||||
ret['comment'] = 'Error: {0}'.format(err)
|
||||
return ret
|
||||
else:
|
||||
log.error('%s is an invalid ICMP type', icmp_type)
|
||||
if block_icmp:
|
||||
try:
|
||||
_valid_icmp_types = __salt__['firewalld.get_icmp_types'](
|
||||
permanent=True)
|
||||
except CommandExecutionError as err:
|
||||
ret['comment'] = 'Error: {0}'.format(err)
|
||||
return ret
|
||||
|
||||
if prune_block_icmp:
|
||||
old_icmp_types = set(_current_icmp_blocks) - set(block_icmp)
|
||||
for icmp_type in old_icmp_types:
|
||||
# no need to check against _valid_icmp_types here, because all
|
||||
# elements in old_icmp_types are guaranteed to be in
|
||||
# _current_icmp_blocks, whose elements are inherently valid
|
||||
if not __opts__['test']:
|
||||
try:
|
||||
__salt__['firewalld.allow_icmp'](name, icmp_type,
|
||||
permanent=True)
|
||||
except CommandExecutionError as err:
|
||||
ret['comment'] = 'Error: {0}'.format(err)
|
||||
return ret
|
||||
# log errors for invalid ICMP types in block_icmp input
|
||||
for icmp_type in set(block_icmp) - set(_valid_icmp_types):
|
||||
log.error('%s is an invalid ICMP type', icmp_type)
|
||||
block_icmp.remove(icmp_type)
|
||||
|
||||
if new_icmp_types or old_icmp_types:
|
||||
# If we're not pruning, include current items in new output so it's clear
|
||||
# that they're still present
|
||||
if not prune_block_icmp:
|
||||
block_icmp = list(new_icmp_types | set(_current_icmp_blocks))
|
||||
ret['changes'].update({'icmp_types':
|
||||
{'old': _current_icmp_blocks,
|
||||
'new': block_icmp}})
|
||||
new_icmp_types = set(block_icmp) - set(_current_icmp_blocks)
|
||||
for icmp_type in new_icmp_types:
|
||||
if not __opts__['test']:
|
||||
try:
|
||||
__salt__['firewalld.block_icmp'](name, icmp_type,
|
||||
permanent=True)
|
||||
except CommandExecutionError as err:
|
||||
ret['comment'] = 'Error: {0}'.format(err)
|
||||
return ret
|
||||
|
||||
if prune_block_icmp:
|
||||
old_icmp_types = set(_current_icmp_blocks) - set(block_icmp)
|
||||
for icmp_type in old_icmp_types:
|
||||
# no need to check against _valid_icmp_types here, because all
|
||||
# elements in old_icmp_types are guaranteed to be in
|
||||
# _current_icmp_blocks, whose elements are inherently valid
|
||||
if not __opts__['test']:
|
||||
try:
|
||||
__salt__['firewalld.allow_icmp'](name, icmp_type,
|
||||
permanent=True)
|
||||
except CommandExecutionError as err:
|
||||
ret['comment'] = 'Error: {0}'.format(err)
|
||||
return ret
|
||||
|
||||
if new_icmp_types or old_icmp_types:
|
||||
# If we're not pruning, include current items in new output so it's clear
|
||||
# that they're still present
|
||||
if not prune_block_icmp:
|
||||
block_icmp = list(new_icmp_types | set(_current_icmp_blocks))
|
||||
ret['changes'].update({'icmp_types':
|
||||
{'old': _current_icmp_blocks,
|
||||
'new': block_icmp}})
|
||||
|
||||
# that's the only parameter that can't be permanent or runtime, it's
|
||||
# directly both
|
||||
@ -461,292 +469,290 @@ def _present(name,
|
||||
{'old': default_zone,
|
||||
'new': name}})
|
||||
|
||||
if masquerade:
|
||||
try:
|
||||
masquerade_ret = __salt__['firewalld.get_masquerade'](name,
|
||||
permanent=True)
|
||||
except CommandExecutionError as err:
|
||||
ret['comment'] = 'Error: {0}'.format(err)
|
||||
return ret
|
||||
if not masquerade_ret:
|
||||
if not __opts__['test']:
|
||||
try:
|
||||
__salt__['firewalld.add_masquerade'](name, permanent=True)
|
||||
except CommandExecutionError as err:
|
||||
ret['comment'] = 'Error: {0}'.format(err)
|
||||
return ret
|
||||
ret['changes'].update({'masquerade':
|
||||
{'old': '',
|
||||
'new': 'Masquerading successfully set.'}})
|
||||
|
||||
if not masquerade:
|
||||
try:
|
||||
masquerade_ret = __salt__['firewalld.get_masquerade'](name,
|
||||
permanent=True)
|
||||
except CommandExecutionError as err:
|
||||
ret['comment'] = 'Error: {0}'.format(err)
|
||||
return ret
|
||||
if masquerade_ret:
|
||||
if not __opts__['test']:
|
||||
try:
|
||||
__salt__['firewalld.remove_masquerade'](name,
|
||||
permanent=True)
|
||||
except CommandExecutionError as err:
|
||||
ret['comment'] = 'Error: {0}'.format(err)
|
||||
return ret
|
||||
ret['changes'].update({'masquerade':
|
||||
{'old': '',
|
||||
'new': 'Masquerading successfully '
|
||||
'disabled.'}})
|
||||
|
||||
ports = ports or []
|
||||
try:
|
||||
_current_ports = __salt__['firewalld.list_ports'](name, permanent=True)
|
||||
except CommandExecutionError as err:
|
||||
ret['comment'] = 'Error: {0}'.format(err)
|
||||
return ret
|
||||
|
||||
new_ports = set(ports) - set(_current_ports)
|
||||
old_ports = []
|
||||
|
||||
for port in new_ports:
|
||||
if not __opts__['test']:
|
||||
try:
|
||||
# TODO: force_masquerade to be removed in future release
|
||||
__salt__['firewalld.add_port'](name, port, permanent=True, force_masquerade=False)
|
||||
except CommandExecutionError as err:
|
||||
ret['comment'] = 'Error: {0}'.format(err)
|
||||
return ret
|
||||
|
||||
if prune_ports:
|
||||
old_ports = set(_current_ports) - set(ports)
|
||||
for port in old_ports:
|
||||
if not __opts__['test']:
|
||||
try:
|
||||
__salt__['firewalld.remove_port'](name, port, permanent=True)
|
||||
except CommandExecutionError as err:
|
||||
ret['comment'] = 'Error: {0}'.format(err)
|
||||
return ret
|
||||
|
||||
if new_ports or old_ports:
|
||||
# If we're not pruning, include current items in new output so it's clear
|
||||
# that they're still present
|
||||
if not prune_ports:
|
||||
ports = list(new_ports | set(_current_ports))
|
||||
ret['changes'].update({'ports':
|
||||
{'old': _current_ports,
|
||||
'new': ports}})
|
||||
|
||||
port_fwd = port_fwd or []
|
||||
try:
|
||||
_current_port_fwd = __salt__['firewalld.list_port_fwd'](name,
|
||||
permanent=True)
|
||||
except CommandExecutionError as err:
|
||||
ret['comment'] = 'Error: {0}'.format(err)
|
||||
return ret
|
||||
|
||||
port_fwd = [_parse_forward(fwd) for fwd in port_fwd]
|
||||
_current_port_fwd = [
|
||||
ForwardingMapping(
|
||||
srcport=fwd['Source port'],
|
||||
destport=fwd['Destination port'],
|
||||
protocol=fwd['Protocol'],
|
||||
destaddr=fwd['Destination address']
|
||||
) for fwd in _current_port_fwd]
|
||||
|
||||
new_port_fwd = set(port_fwd) - set(_current_port_fwd)
|
||||
old_port_fwd = []
|
||||
|
||||
for fwd in new_port_fwd:
|
||||
if not __opts__['test']:
|
||||
try:
|
||||
# TODO: force_masquerade to be removed in future release
|
||||
__salt__['firewalld.add_port_fwd'](name, fwd.srcport,
|
||||
fwd.destport, fwd.protocol, fwd.destaddr, permanent=True,
|
||||
force_masquerade=False)
|
||||
except CommandExecutionError as err:
|
||||
ret['comment'] = 'Error: {0}'.format(err)
|
||||
return ret
|
||||
|
||||
if prune_port_fwd:
|
||||
old_port_fwd = set(_current_port_fwd) - set(port_fwd)
|
||||
for fwd in old_port_fwd:
|
||||
if not __opts__['test']:
|
||||
try:
|
||||
__salt__['firewalld.remove_port_fwd'](name, fwd.srcport,
|
||||
fwd.destport, fwd.protocol, fwd.destaddr, permanent=True)
|
||||
except CommandExecutionError as err:
|
||||
ret['comment'] = 'Error: {0}'.format(err)
|
||||
return ret
|
||||
|
||||
if new_port_fwd or old_port_fwd:
|
||||
# If we're not pruning, include current items in new output so it's clear
|
||||
# that they're still present
|
||||
if not prune_port_fwd:
|
||||
port_fwd = list(new_port_fwd | set(_current_port_fwd))
|
||||
ret['changes'].update({'port_fwd':
|
||||
{'old': [fwd.todict() for fwd in
|
||||
_current_port_fwd],
|
||||
'new': [fwd.todict() for fwd in port_fwd]}})
|
||||
|
||||
services = services or []
|
||||
try:
|
||||
_current_services = __salt__['firewalld.list_services'](name,
|
||||
masquerade_ret = __salt__['firewalld.get_masquerade'](name,
|
||||
permanent=True)
|
||||
except CommandExecutionError as err:
|
||||
ret['comment'] = 'Error: {0}'.format(err)
|
||||
return ret
|
||||
|
||||
new_services = set(services) - set(_current_services)
|
||||
old_services = []
|
||||
|
||||
for new_service in new_services:
|
||||
if masquerade and not masquerade_ret:
|
||||
if not __opts__['test']:
|
||||
try:
|
||||
__salt__['firewalld.add_service'](new_service, name,
|
||||
permanent=True)
|
||||
__salt__['firewalld.add_masquerade'](name, permanent=True)
|
||||
except CommandExecutionError as err:
|
||||
ret['comment'] = 'Error: {0}'.format(err)
|
||||
return ret
|
||||
ret['changes'].update({'masquerade':
|
||||
{'old': '',
|
||||
'new': 'Masquerading successfully set.'}})
|
||||
elif not masquerade and masquerade_ret:
|
||||
if not __opts__['test']:
|
||||
try:
|
||||
__salt__['firewalld.remove_masquerade'](name,
|
||||
permanent=True)
|
||||
except CommandExecutionError as err:
|
||||
ret['comment'] = 'Error: {0}'.format(err)
|
||||
return ret
|
||||
ret['changes'].update({'masquerade':
|
||||
{'old': '',
|
||||
'new': 'Masquerading successfully '
|
||||
'disabled.'}})
|
||||
|
||||
if prune_services:
|
||||
old_services = set(_current_services) - set(services)
|
||||
for old_service in old_services:
|
||||
if ports or prune_ports:
|
||||
ports = ports or []
|
||||
try:
|
||||
_current_ports = __salt__['firewalld.list_ports'](name, permanent=True)
|
||||
except CommandExecutionError as err:
|
||||
ret['comment'] = 'Error: {0}'.format(err)
|
||||
return ret
|
||||
|
||||
new_ports = set(ports) - set(_current_ports)
|
||||
old_ports = []
|
||||
|
||||
for port in new_ports:
|
||||
if not __opts__['test']:
|
||||
try:
|
||||
__salt__['firewalld.remove_service'](old_service, name,
|
||||
permanent=True)
|
||||
# TODO: force_masquerade to be removed in future release
|
||||
__salt__['firewalld.add_port'](name, port, permanent=True, force_masquerade=False)
|
||||
except CommandExecutionError as err:
|
||||
ret['comment'] = 'Error: {0}'.format(err)
|
||||
return ret
|
||||
|
||||
if new_services or old_services:
|
||||
# If we're not pruning, include current items in new output so it's clear
|
||||
# that they're still present
|
||||
if not prune_services:
|
||||
services = list(new_services | set(_current_services))
|
||||
ret['changes'].update({'services':
|
||||
{'old': _current_services,
|
||||
'new': services}})
|
||||
if prune_ports:
|
||||
old_ports = set(_current_ports) - set(ports)
|
||||
for port in old_ports:
|
||||
if not __opts__['test']:
|
||||
try:
|
||||
__salt__['firewalld.remove_port'](name, port, permanent=True)
|
||||
except CommandExecutionError as err:
|
||||
ret['comment'] = 'Error: {0}'.format(err)
|
||||
return ret
|
||||
|
||||
interfaces = interfaces or []
|
||||
try:
|
||||
_current_interfaces = __salt__['firewalld.get_interfaces'](name,
|
||||
permanent=True)
|
||||
except CommandExecutionError as err:
|
||||
ret['comment'] = 'Error: {0}'.format(err)
|
||||
return ret
|
||||
if new_ports or old_ports:
|
||||
# If we're not pruning, include current items in new output so it's clear
|
||||
# that they're still present
|
||||
if not prune_ports:
|
||||
ports = list(new_ports | set(_current_ports))
|
||||
ret['changes'].update({'ports':
|
||||
{'old': _current_ports,
|
||||
'new': ports}})
|
||||
|
||||
new_interfaces = set(interfaces) - set(_current_interfaces)
|
||||
old_interfaces = []
|
||||
if port_fwd or prune_port_fwd:
|
||||
port_fwd = port_fwd or []
|
||||
try:
|
||||
_current_port_fwd = __salt__['firewalld.list_port_fwd'](name,
|
||||
permanent=True)
|
||||
except CommandExecutionError as err:
|
||||
ret['comment'] = 'Error: {0}'.format(err)
|
||||
return ret
|
||||
|
||||
for interface in new_interfaces:
|
||||
if not __opts__['test']:
|
||||
try:
|
||||
__salt__['firewalld.add_interface'](name, interface,
|
||||
permanent=True)
|
||||
except CommandExecutionError as err:
|
||||
ret['comment'] = 'Error: {0}'.format(err)
|
||||
return ret
|
||||
port_fwd = [_parse_forward(fwd) for fwd in port_fwd]
|
||||
_current_port_fwd = [
|
||||
ForwardingMapping(
|
||||
srcport=fwd['Source port'],
|
||||
destport=fwd['Destination port'],
|
||||
protocol=fwd['Protocol'],
|
||||
destaddr=fwd['Destination address']
|
||||
) for fwd in _current_port_fwd]
|
||||
|
||||
if prune_interfaces:
|
||||
old_interfaces = set(_current_interfaces) - set(interfaces)
|
||||
for interface in old_interfaces:
|
||||
new_port_fwd = set(port_fwd) - set(_current_port_fwd)
|
||||
old_port_fwd = []
|
||||
|
||||
for fwd in new_port_fwd:
|
||||
if not __opts__['test']:
|
||||
try:
|
||||
__salt__['firewalld.remove_interface'](name, interface,
|
||||
permanent=True)
|
||||
# TODO: force_masquerade to be removed in future release
|
||||
__salt__['firewalld.add_port_fwd'](name, fwd.srcport,
|
||||
fwd.destport, fwd.protocol, fwd.destaddr, permanent=True,
|
||||
force_masquerade=False)
|
||||
except CommandExecutionError as err:
|
||||
ret['comment'] = 'Error: {0}'.format(err)
|
||||
return ret
|
||||
|
||||
if new_interfaces or old_interfaces:
|
||||
# If we're not pruning, include current items in new output so it's clear
|
||||
# that they're still present
|
||||
if not prune_interfaces:
|
||||
interfaces = list(new_interfaces | set(_current_interfaces))
|
||||
ret['changes'].update({'interfaces':
|
||||
{'old': _current_interfaces,
|
||||
'new': interfaces}})
|
||||
if prune_port_fwd:
|
||||
old_port_fwd = set(_current_port_fwd) - set(port_fwd)
|
||||
for fwd in old_port_fwd:
|
||||
if not __opts__['test']:
|
||||
try:
|
||||
__salt__['firewalld.remove_port_fwd'](name, fwd.srcport,
|
||||
fwd.destport, fwd.protocol, fwd.destaddr, permanent=True)
|
||||
except CommandExecutionError as err:
|
||||
ret['comment'] = 'Error: {0}'.format(err)
|
||||
return ret
|
||||
|
||||
sources = sources or []
|
||||
try:
|
||||
_current_sources = __salt__['firewalld.get_sources'](name,
|
||||
if new_port_fwd or old_port_fwd:
|
||||
# If we're not pruning, include current items in new output so it's clear
|
||||
# that they're still present
|
||||
if not prune_port_fwd:
|
||||
port_fwd = list(new_port_fwd | set(_current_port_fwd))
|
||||
ret['changes'].update({'port_fwd':
|
||||
{'old': [fwd.todict() for fwd in
|
||||
_current_port_fwd],
|
||||
'new': [fwd.todict() for fwd in port_fwd]}})
|
||||
|
||||
if services or prune_services:
|
||||
services = services or []
|
||||
try:
|
||||
_current_services = __salt__['firewalld.list_services'](name,
|
||||
permanent=True)
|
||||
except CommandExecutionError as err:
|
||||
ret['comment'] = 'Error: {0}'.format(err)
|
||||
return ret
|
||||
|
||||
new_services = set(services) - set(_current_services)
|
||||
old_services = []
|
||||
|
||||
for new_service in new_services:
|
||||
if not __opts__['test']:
|
||||
try:
|
||||
__salt__['firewalld.add_service'](new_service, name,
|
||||
permanent=True)
|
||||
except CommandExecutionError as err:
|
||||
ret['comment'] = 'Error: {0}'.format(err)
|
||||
return ret
|
||||
|
||||
if prune_services:
|
||||
old_services = set(_current_services) - set(services)
|
||||
for old_service in old_services:
|
||||
if not __opts__['test']:
|
||||
try:
|
||||
__salt__['firewalld.remove_service'](old_service, name,
|
||||
permanent=True)
|
||||
except CommandExecutionError as err:
|
||||
ret['comment'] = 'Error: {0}'.format(err)
|
||||
return ret
|
||||
except CommandExecutionError as err:
|
||||
ret['comment'] = 'Error: {0}'.format(err)
|
||||
return ret
|
||||
|
||||
new_sources = set(sources) - set(_current_sources)
|
||||
old_sources = []
|
||||
if new_services or old_services:
|
||||
# If we're not pruning, include current items in new output so it's clear
|
||||
# that they're still present
|
||||
if not prune_services:
|
||||
services = list(new_services | set(_current_services))
|
||||
ret['changes'].update({'services':
|
||||
{'old': _current_services,
|
||||
'new': services}})
|
||||
|
||||
for source in new_sources:
|
||||
if not __opts__['test']:
|
||||
try:
|
||||
__salt__['firewalld.add_source'](name, source, permanent=True)
|
||||
except CommandExecutionError as err:
|
||||
ret['comment'] = 'Error: {0}'.format(err)
|
||||
return ret
|
||||
if interfaces or prune_interfaces:
|
||||
interfaces = interfaces or []
|
||||
try:
|
||||
_current_interfaces = __salt__['firewalld.get_interfaces'](name,
|
||||
permanent=True)
|
||||
except CommandExecutionError as err:
|
||||
ret['comment'] = 'Error: {0}'.format(err)
|
||||
return ret
|
||||
|
||||
if prune_sources:
|
||||
old_sources = set(_current_sources) - set(sources)
|
||||
for source in old_sources:
|
||||
new_interfaces = set(interfaces) - set(_current_interfaces)
|
||||
old_interfaces = []
|
||||
|
||||
for interface in new_interfaces:
|
||||
if not __opts__['test']:
|
||||
try:
|
||||
__salt__['firewalld.remove_source'](name, source,
|
||||
__salt__['firewalld.add_interface'](name, interface,
|
||||
permanent=True)
|
||||
except CommandExecutionError as err:
|
||||
ret['comment'] = 'Error: {0}'.format(err)
|
||||
return ret
|
||||
|
||||
if new_sources or old_sources:
|
||||
# If we're not pruning, include current items in new output so it's clear
|
||||
# that they're still present
|
||||
if not prune_sources:
|
||||
sources = list(new_sources | set(_current_sources))
|
||||
ret['changes'].update({'sources':
|
||||
{'old': _current_sources,
|
||||
'new': sources}})
|
||||
if prune_interfaces:
|
||||
old_interfaces = set(_current_interfaces) - set(interfaces)
|
||||
for interface in old_interfaces:
|
||||
if not __opts__['test']:
|
||||
try:
|
||||
__salt__['firewalld.remove_interface'](name, interface,
|
||||
permanent=True)
|
||||
except CommandExecutionError as err:
|
||||
ret['comment'] = 'Error: {0}'.format(err)
|
||||
return ret
|
||||
|
||||
rich_rules = rich_rules or []
|
||||
try:
|
||||
_current_rich_rules = __salt__['firewalld.get_rich_rules'](name,
|
||||
permanent=True)
|
||||
except CommandExecutionError as err:
|
||||
ret['comment'] = 'Error: {0}'.format(err)
|
||||
return ret
|
||||
if new_interfaces or old_interfaces:
|
||||
# If we're not pruning, include current items in new output so it's clear
|
||||
# that they're still present
|
||||
if not prune_interfaces:
|
||||
interfaces = list(new_interfaces | set(_current_interfaces))
|
||||
ret['changes'].update({'interfaces':
|
||||
{'old': _current_interfaces,
|
||||
'new': interfaces}})
|
||||
|
||||
new_rich_rules = set(rich_rules) - set(_current_rich_rules)
|
||||
old_rich_rules = []
|
||||
if sources or prune_sources:
|
||||
sources = sources or []
|
||||
try:
|
||||
_current_sources = __salt__['firewalld.get_sources'](name,
|
||||
permanent=True)
|
||||
except CommandExecutionError as err:
|
||||
ret['comment'] = 'Error: {0}'.format(err)
|
||||
return ret
|
||||
|
||||
for rich_rule in new_rich_rules:
|
||||
if not __opts__['test']:
|
||||
try:
|
||||
__salt__['firewalld.add_rich_rule'](name, rich_rule,
|
||||
permanent=True)
|
||||
except CommandExecutionError as err:
|
||||
ret['comment'] = 'Error: {0}'.format(err)
|
||||
return ret
|
||||
new_sources = set(sources) - set(_current_sources)
|
||||
old_sources = []
|
||||
|
||||
if prune_rich_rules:
|
||||
old_rich_rules = set(_current_rich_rules) - set(rich_rules)
|
||||
for rich_rule in old_rich_rules:
|
||||
for source in new_sources:
|
||||
if not __opts__['test']:
|
||||
try:
|
||||
__salt__['firewalld.remove_rich_rule'](name, rich_rule,
|
||||
permanent=True)
|
||||
__salt__['firewalld.add_source'](name, source, permanent=True)
|
||||
except CommandExecutionError as err:
|
||||
ret['comment'] = 'Error: {0}'.format(err)
|
||||
return ret
|
||||
|
||||
if new_rich_rules or old_rich_rules:
|
||||
# If we're not pruning, include current items in new output so it's clear
|
||||
# that they're still present
|
||||
if not prune_rich_rules:
|
||||
rich_rules = list(new_rich_rules | set(_current_rich_rules))
|
||||
ret['changes'].update({'rich_rules':
|
||||
{'old': _current_rich_rules,
|
||||
'new': rich_rules}})
|
||||
if prune_sources:
|
||||
old_sources = set(_current_sources) - set(sources)
|
||||
for source in old_sources:
|
||||
if not __opts__['test']:
|
||||
try:
|
||||
__salt__['firewalld.remove_source'](name, source,
|
||||
permanent=True)
|
||||
except CommandExecutionError as err:
|
||||
ret['comment'] = 'Error: {0}'.format(err)
|
||||
return ret
|
||||
|
||||
if new_sources or old_sources:
|
||||
# If we're not pruning, include current items in new output so it's clear
|
||||
# that they're still present
|
||||
if not prune_sources:
|
||||
sources = list(new_sources | set(_current_sources))
|
||||
ret['changes'].update({'sources':
|
||||
{'old': _current_sources,
|
||||
'new': sources}})
|
||||
|
||||
if rich_rules or prune_rich_rules:
|
||||
rich_rules = rich_rules or []
|
||||
try:
|
||||
_current_rich_rules = __salt__['firewalld.get_rich_rules'](name,
|
||||
permanent=True)
|
||||
except CommandExecutionError as err:
|
||||
ret['comment'] = 'Error: {0}'.format(err)
|
||||
return ret
|
||||
|
||||
new_rich_rules = set(rich_rules) - set(_current_rich_rules)
|
||||
old_rich_rules = []
|
||||
|
||||
for rich_rule in new_rich_rules:
|
||||
if not __opts__['test']:
|
||||
try:
|
||||
__salt__['firewalld.add_rich_rule'](name, rich_rule,
|
||||
permanent=True)
|
||||
except CommandExecutionError as err:
|
||||
ret['comment'] = 'Error: {0}'.format(err)
|
||||
return ret
|
||||
|
||||
if prune_rich_rules:
|
||||
old_rich_rules = set(_current_rich_rules) - set(rich_rules)
|
||||
for rich_rule in old_rich_rules:
|
||||
if not __opts__['test']:
|
||||
try:
|
||||
__salt__['firewalld.remove_rich_rule'](name, rich_rule,
|
||||
permanent=True)
|
||||
except CommandExecutionError as err:
|
||||
ret['comment'] = 'Error: {0}'.format(err)
|
||||
return ret
|
||||
|
||||
if new_rich_rules or old_rich_rules:
|
||||
# If we're not pruning, include current items in new output so it's clear
|
||||
# that they're still present
|
||||
if not prune_rich_rules:
|
||||
rich_rules = list(new_rich_rules | set(_current_rich_rules))
|
||||
ret['changes'].update({'rich_rules':
|
||||
{'old': _current_rich_rules,
|
||||
'new': rich_rules}})
|
||||
|
||||
# No changes
|
||||
if ret['changes'] == {}:
|
||||
|
@ -334,7 +334,7 @@ def _check_key_type(key_str, key_type=None):
|
||||
value = __salt__['pillar.get'](key_str, None)
|
||||
if value is None:
|
||||
return None
|
||||
elif type(value) is not key_type and key_type is not None:
|
||||
elif key_type is not None and not isinstance(value, key_type):
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
@ -415,7 +415,7 @@ def check_pillar(name,
|
||||
checks[int] = integer
|
||||
# those should be str:
|
||||
string = _if_str_then_list(string)
|
||||
checks[str] = string
|
||||
checks[six.string_types] = string
|
||||
# those should be list:
|
||||
listing = _if_str_then_list(listing)
|
||||
checks[list] = listing
|
||||
|
@ -488,11 +488,7 @@ def query(url,
|
||||
data = _urlencode(data)
|
||||
|
||||
if verify_ssl:
|
||||
# tornado requires a str, cannot be unicode str in py2
|
||||
if ca_bundle is None:
|
||||
req_kwargs['ca_certs'] = ca_bundle
|
||||
else:
|
||||
req_kwargs['ca_certs'] = salt.utils.stringutils.to_str(ca_bundle)
|
||||
req_kwargs['ca_certs'] = ca_bundle
|
||||
|
||||
max_body = opts.get('http_max_body', salt.config.DEFAULT_MINION_OPTS['http_max_body'])
|
||||
timeout = opts.get('http_request_timeout', salt.config.DEFAULT_MINION_OPTS['http_request_timeout'])
|
||||
@ -530,30 +526,35 @@ def query(url,
|
||||
|
||||
supports_max_body_size = 'max_body_size' in client_argspec.args
|
||||
|
||||
req_kwargs.update({
|
||||
'method': method,
|
||||
'headers': header_dict,
|
||||
'auth_username': username,
|
||||
'auth_password': password,
|
||||
'body': data,
|
||||
'validate_cert': verify_ssl,
|
||||
'allow_nonstandard_methods': True,
|
||||
'streaming_callback': streaming_callback,
|
||||
'header_callback': header_callback,
|
||||
'request_timeout': timeout,
|
||||
'proxy_host': proxy_host,
|
||||
'proxy_port': proxy_port,
|
||||
'proxy_username': proxy_username,
|
||||
'proxy_password': proxy_password,
|
||||
'raise_error': raise_error,
|
||||
'decompress_response': False,
|
||||
})
|
||||
|
||||
# Unicode types will cause a TypeError when Tornado's curl HTTPClient
|
||||
# invokes setopt. Therefore, make sure all arguments we pass which
|
||||
# contain strings are str types.
|
||||
req_kwargs = salt.utils.data.decode(req_kwargs, to_str=True)
|
||||
|
||||
try:
|
||||
download_client = HTTPClient(max_body_size=max_body) \
|
||||
if supports_max_body_size \
|
||||
else HTTPClient()
|
||||
result = download_client.fetch(
|
||||
url_full,
|
||||
method=method,
|
||||
headers=header_dict,
|
||||
auth_username=username,
|
||||
auth_password=password,
|
||||
body=data,
|
||||
validate_cert=verify_ssl,
|
||||
allow_nonstandard_methods=True,
|
||||
streaming_callback=streaming_callback,
|
||||
header_callback=header_callback,
|
||||
request_timeout=timeout,
|
||||
proxy_host=proxy_host,
|
||||
proxy_port=proxy_port,
|
||||
proxy_username=proxy_username,
|
||||
proxy_password=proxy_password,
|
||||
raise_error=raise_error,
|
||||
decompress_response=False,
|
||||
**req_kwargs
|
||||
)
|
||||
result = download_client.fetch(url_full, **req_kwargs)
|
||||
except tornado.httpclient.HTTPError as exc:
|
||||
ret['status'] = exc.code
|
||||
ret['error'] = six.text_type(exc)
|
||||
|
@ -19,6 +19,8 @@ from tests.support.mock import (
|
||||
# Import Salt Libs
|
||||
from salt.exceptions import SaltInvocationError
|
||||
import salt.states.test as test
|
||||
from salt.utils.odict import OrderedDict
|
||||
from salt.ext import six
|
||||
|
||||
|
||||
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||
@ -310,6 +312,48 @@ class TestTestCase(TestCase, LoaderModuleMockMixin):
|
||||
with patch.dict(test.__salt__, {'pillar.get': pillar_mock}):
|
||||
self.assertEqual(test.check_pillar('salt', present='my_pillar'), ret)
|
||||
|
||||
def test_check_pillar_string(self):
|
||||
'''
|
||||
Test to ensure the check_pillar function
|
||||
works properly with the 'key_type' checks,
|
||||
using the string key_type.
|
||||
'''
|
||||
ret = {
|
||||
'name': 'salt',
|
||||
'changes': {},
|
||||
'result': True,
|
||||
'comment': ''
|
||||
}
|
||||
pillar_return = 'I am a pillar.'
|
||||
pillar_mock = MagicMock(return_value=pillar_return)
|
||||
with patch.dict(test.__salt__, {'pillar.get': pillar_mock}):
|
||||
self.assertEqual(test.check_pillar('salt', string='my_pillar'), ret)
|
||||
# With unicode (py2) or str (py3) strings
|
||||
pillar_return = six.text_type('I am a pillar.')
|
||||
pillar_mock = MagicMock(return_value=pillar_return)
|
||||
with patch.dict(test.__salt__, {'pillar.get': pillar_mock}):
|
||||
self.assertEqual(test.check_pillar('salt', string='my_pillar'), ret)
|
||||
# With a dict
|
||||
pillar_return = {'this': 'dictionary'}
|
||||
pillar_mock = MagicMock(return_value=pillar_return)
|
||||
with patch.dict(test.__salt__, {'pillar.get': pillar_mock}):
|
||||
self.assertFalse(test.check_pillar('salt', string='my_pillar')['result'])
|
||||
# With a list
|
||||
pillar_return = ['I am a pillar.']
|
||||
pillar_mock = MagicMock(return_value=pillar_return)
|
||||
with patch.dict(test.__salt__, {'pillar.get': pillar_mock}):
|
||||
self.assertFalse(test.check_pillar('salt', string='my_pillar')['result'])
|
||||
# With a boolean
|
||||
pillar_return = True
|
||||
pillar_mock = MagicMock(return_value=pillar_return)
|
||||
with patch.dict(test.__salt__, {'pillar.get': pillar_mock}):
|
||||
self.assertFalse(test.check_pillar('salt', string='my_pillar')['result'])
|
||||
# With an int
|
||||
pillar_return = 1
|
||||
pillar_mock = MagicMock(return_value=pillar_return)
|
||||
with patch.dict(test.__salt__, {'pillar.get': pillar_mock}):
|
||||
self.assertFalse(test.check_pillar('salt', string='my_pillar')['result'])
|
||||
|
||||
def test_check_pillar_dictionary(self):
|
||||
'''
|
||||
Test to ensure the check_pillar function
|
||||
@ -326,3 +370,28 @@ class TestTestCase(TestCase, LoaderModuleMockMixin):
|
||||
pillar_mock = MagicMock(return_value=pillar_return)
|
||||
with patch.dict(test.__salt__, {'pillar.get': pillar_mock}):
|
||||
self.assertEqual(test.check_pillar('salt', dictionary='my_pillar'), ret)
|
||||
# With an ordered dict
|
||||
pillar_return = OrderedDict({'this': 'dictionary'})
|
||||
pillar_mock = MagicMock(return_value=pillar_return)
|
||||
with patch.dict(test.__salt__, {'pillar.get': pillar_mock}):
|
||||
self.assertEqual(test.check_pillar('salt', dictionary='my_pillar'), ret)
|
||||
# With a string
|
||||
pillar_return = 'I am a pillar.'
|
||||
pillar_mock = MagicMock(return_value=pillar_return)
|
||||
with patch.dict(test.__salt__, {'pillar.get': pillar_mock}):
|
||||
self.assertFalse(test.check_pillar('salt', dictionary='my_pillar')['result'])
|
||||
# With a list
|
||||
pillar_return = ['I am a pillar.']
|
||||
pillar_mock = MagicMock(return_value=pillar_return)
|
||||
with patch.dict(test.__salt__, {'pillar.get': pillar_mock}):
|
||||
self.assertFalse(test.check_pillar('salt', dictionary='my_pillar')['result'])
|
||||
# With a boolean
|
||||
pillar_return = True
|
||||
pillar_mock = MagicMock(return_value=pillar_return)
|
||||
with patch.dict(test.__salt__, {'pillar.get': pillar_mock}):
|
||||
self.assertFalse(test.check_pillar('salt', dictionary='my_pillar')['result'])
|
||||
# With an int
|
||||
pillar_return = 1
|
||||
pillar_mock = MagicMock(return_value=pillar_return)
|
||||
with patch.dict(test.__salt__, {'pillar.get': pillar_mock}):
|
||||
self.assertFalse(test.check_pillar('salt', dictionary='my_pillar')['result'])
|
||||
|
Loading…
Reference in New Issue
Block a user