Merge branch '2018.3' into 'fluorine'

Conflicts:
  - doc/man/salt.7
This commit is contained in:
rallytime 2018-10-03 09:45:20 -04:00
commit 46c0e50638
No known key found for this signature in database
GPG key ID: E8F1A4B90D0DEA19
54 changed files with 80004 additions and 51023 deletions

View file

@ -54,6 +54,8 @@ timeout(time: 6, unit: 'HOURS') {
archiveArtifacts artifacts: 'artifacts/logs/salt-runtests.log'
}
}
} catch (Exception e) {
currentBuild.result = 'FAILURE'
} finally {
try {
junit 'artifacts/xml-unittests-output/*.xml'

View file

@ -54,6 +54,8 @@ timeout(time: 6, unit: 'HOURS') {
archiveArtifacts artifacts: 'artifacts/logs/salt-runtests.log'
}
}
} catch (Exception e) {
currentBuild.result = 'FAILURE'
} finally {
try {
junit 'artifacts/xml-unittests-output/*.xml'

View file

@ -54,6 +54,8 @@ timeout(time: 6, unit: 'HOURS') {
archiveArtifacts artifacts: 'artifacts/logs/salt-runtests.log'
}
}
} catch (Exception e) {
currentBuild.result = 'FAILURE'
} finally {
try {
junit 'artifacts/xml-unittests-output/*.xml'

View file

@ -54,6 +54,8 @@ timeout(time: 6, unit: 'HOURS') {
archiveArtifacts artifacts: 'artifacts/logs/salt-runtests.log'
}
}
} catch (Exception e) {
currentBuild.result = 'FAILURE'
} finally {
try {
junit 'artifacts/xml-unittests-output/*.xml'

View file

@ -54,6 +54,8 @@ timeout(time: 6, unit: 'HOURS') {
archiveArtifacts artifacts: 'artifacts/logs/salt-runtests.log'
}
}
} catch (Exception e) {
currentBuild.result = 'FAILURE'
} finally {
try {
junit 'artifacts/xml-unittests-output/*.xml'

View file

@ -54,6 +54,8 @@ timeout(time: 6, unit: 'HOURS') {
archiveArtifacts artifacts: 'artifacts/logs/salt-runtests.log'
}
}
} catch (Exception e) {
currentBuild.result = 'FAILURE'
} finally {
try {
junit 'artifacts/xml-unittests-output/*.xml'

View file

@ -70,6 +70,11 @@
# Set to zero if the minion should shutdown and not retry.
# retry_dns: 30
# Set the number of times to attempt to resolve
# the master hostname if name resolution fails. Defaults to None,
# which will attempt the resolution indefinitely.
# retry_dns_count: 3
# Set the port used by the master reply and authentication server.
#master_port: 4506

View file

@ -1,6 +1,6 @@
.\" Man page generated from reStructuredText.
.
.TH "SALT-API" "1" "Jun 14, 2018" "2018.3.2" "Salt"
.TH "SALT-API" "1" "Sep 21, 2018" "2018.3.3" "Salt"
.SH NAME
salt-api \- salt-api Command
.
@ -103,9 +103,9 @@ Logfile logging log level. One of \fBall\fP, \fBgarbage\fP, \fBtrace\fP,
.UNINDENT
.SH SEE ALSO
.sp
\fIsalt\-api(7)\fP
\fIsalt(7)\fP
\fIsalt\-master(1)\fP
\fBsalt\-api(7)\fP
\fBsalt(7)\fP
\fBsalt\-master(1)\fP
.SH AUTHOR
Thomas S. Hatch <thatch45@gmail.com> and many others, please see the Authors file
.\" Generated by docutils manpage writer.

View file

@ -1,6 +1,6 @@
.\" Man page generated from reStructuredText.
.
.TH "SALT-CALL" "1" "Jun 14, 2018" "2018.3.2" "Salt"
.TH "SALT-CALL" "1" "Sep 21, 2018" "2018.3.3" "Salt"
.SH NAME
salt-call \- salt-call Documentation
.
@ -265,9 +265,9 @@ output. Set to True or False. Default: none.
.UNINDENT
.SH SEE ALSO
.sp
\fIsalt(1)\fP
\fIsalt\-master(1)\fP
\fIsalt\-minion(1)\fP
\fBsalt(1)\fP
\fBsalt\-master(1)\fP
\fBsalt\-minion(1)\fP
.SH AUTHOR
Thomas S. Hatch <thatch45@gmail.com> and many others, please see the Authors file
.\" Generated by docutils manpage writer.

View file

@ -1,6 +1,6 @@
.\" Man page generated from reStructuredText.
.
.TH "SALT-CLOUD" "1" "Jun 14, 2018" "2018.3.2" "Salt"
.TH "SALT-CLOUD" "1" "Sep 21, 2018" "2018.3.3" "Salt"
.SH NAME
salt-cloud \- Salt Cloud Command
.
@ -387,10 +387,10 @@ salt\-cloud \-m /path/to/cloud.map \-Q
.UNINDENT
.SH SEE ALSO
.sp
\fIsalt\-cloud(7)\fP
\fIsalt(7)\fP
\fIsalt\-master(1)\fP
\fIsalt\-minion(1)\fP
\fBsalt\-cloud(7)\fP
\fBsalt(7)\fP
\fBsalt\-master(1)\fP
\fBsalt\-minion(1)\fP
.SH AUTHOR
Thomas S. Hatch <thatch45@gmail.com> and many others, please see the Authors file
.\" Generated by docutils manpage writer.

View file

@ -1,6 +1,6 @@
.\" Man page generated from reStructuredText.
.
.TH "SALT-CP" "1" "Jun 14, 2018" "2018.3.2" "Salt"
.TH "SALT-CP" "1" "Sep 21, 2018" "2018.3.3" "Salt"
.SH NAME
salt-cp \- salt-cp Documentation
.
@ -201,9 +201,9 @@ New in version 2016.3.7,2016.11.6,2017.7.0.
.UNINDENT
.SH SEE ALSO
.sp
\fIsalt(1)\fP
\fIsalt\-master(1)\fP
\fIsalt\-minion(1)\fP
\fBsalt(1)\fP
\fBsalt\-master(1)\fP
\fBsalt\-minion(1)\fP
.SH AUTHOR
Thomas S. Hatch <thatch45@gmail.com> and many others, please see the Authors file
.\" Generated by docutils manpage writer.

View file

@ -1,6 +1,6 @@
.\" Man page generated from reStructuredText.
.
.TH "SALT-KEY" "1" "Jun 14, 2018" "2018.3.2" "Salt"
.TH "SALT-KEY" "1" "Sep 21, 2018" "2018.3.3" "Salt"
.SH NAME
salt-key \- salt-key Documentation
.
@ -340,9 +340,9 @@ Auto\-create a signing key\-pair if it does not yet exist
.UNINDENT
.SH SEE ALSO
.sp
\fIsalt(7)\fP
\fIsalt\-master(1)\fP
\fIsalt\-minion(1)\fP
\fBsalt(7)\fP
\fBsalt\-master(1)\fP
\fBsalt\-minion(1)\fP
.SH AUTHOR
Thomas S. Hatch <thatch45@gmail.com> and many others, please see the Authors file
.\" Generated by docutils manpage writer.

View file

@ -1,6 +1,6 @@
.\" Man page generated from reStructuredText.
.
.TH "SALT-MASTER" "1" "Jun 14, 2018" "2018.3.2" "Salt"
.TH "SALT-MASTER" "1" "Sep 21, 2018" "2018.3.3" "Salt"
.SH NAME
salt-master \- salt-master Documentation
.
@ -108,9 +108,9 @@ Logfile logging log level. One of \fBall\fP, \fBgarbage\fP, \fBtrace\fP,
.UNINDENT
.SH SEE ALSO
.sp
\fIsalt(1)\fP
\fIsalt(7)\fP
\fIsalt\-minion(1)\fP
\fBsalt(1)\fP
\fBsalt(7)\fP
\fBsalt\-minion(1)\fP
.SH AUTHOR
Thomas S. Hatch <thatch45@gmail.com> and many others, please see the Authors file
.\" Generated by docutils manpage writer.

View file

@ -1,6 +1,6 @@
.\" Man page generated from reStructuredText.
.
.TH "SALT-MINION" "1" "Jun 14, 2018" "2018.3.2" "Salt"
.TH "SALT-MINION" "1" "Sep 21, 2018" "2018.3.3" "Salt"
.SH NAME
salt-minion \- salt-minion Documentation
.
@ -109,9 +109,9 @@ Logfile logging log level. One of \fBall\fP, \fBgarbage\fP, \fBtrace\fP,
.UNINDENT
.SH SEE ALSO
.sp
\fIsalt(1)\fP
\fIsalt(7)\fP
\fIsalt\-master(1)\fP
\fBsalt(1)\fP
\fBsalt(7)\fP
\fBsalt\-master(1)\fP
.SH AUTHOR
Thomas S. Hatch <thatch45@gmail.com> and many others, please see the Authors file
.\" Generated by docutils manpage writer.

View file

@ -1,6 +1,6 @@
.\" Man page generated from reStructuredText.
.
.TH "SALT-PROXY" "1" "Jun 14, 2018" "2018.3.2" "Salt"
.TH "SALT-PROXY" "1" "Sep 21, 2018" "2018.3.3" "Salt"
.SH NAME
salt-proxy \- salt-proxy Documentation
.
@ -116,10 +116,10 @@ Logfile logging log level. One of \fBall\fP, \fBgarbage\fP, \fBtrace\fP,
.UNINDENT
.SH SEE ALSO
.sp
\fIsalt(1)\fP
\fIsalt(7)\fP
\fIsalt\-master(1)\fP
\fIsalt\-minion(1)\fP
\fBsalt(1)\fP
\fBsalt(7)\fP
\fBsalt\-master(1)\fP
\fBsalt\-minion(1)\fP
.SH AUTHOR
Thomas S. Hatch <thatch45@gmail.com> and many others, please see the Authors file
.\" Generated by docutils manpage writer.

View file

@ -1,6 +1,6 @@
.\" Man page generated from reStructuredText.
.
.TH "SALT-RUN" "1" "Jun 14, 2018" "2018.3.2" "Salt"
.TH "SALT-RUN" "1" "Sep 21, 2018" "2018.3.3" "Salt"
.SH NAME
salt-run \- salt-run Documentation
.
@ -114,9 +114,9 @@ Logfile logging log level. One of \fBall\fP, \fBgarbage\fP, \fBtrace\fP,
.UNINDENT
.SH SEE ALSO
.sp
\fIsalt(1)\fP
\fIsalt\-master(1)\fP
\fIsalt\-minion(1)\fP
\fBsalt(1)\fP
\fBsalt\-master(1)\fP
\fBsalt\-minion(1)\fP
.SH AUTHOR
Thomas S. Hatch <thatch45@gmail.com> and many others, please see the Authors file
.\" Generated by docutils manpage writer.

View file

@ -1,6 +1,6 @@
.\" Man page generated from reStructuredText.
.
.TH "SALT-SSH" "1" "Jun 14, 2018" "2018.3.2" "Salt"
.TH "SALT-SSH" "1" "Sep 21, 2018" "2018.3.3" "Salt"
.SH NAME
salt-ssh \- salt-ssh Documentation
.
@ -348,9 +348,9 @@ output. Set to True or False. Default: none.
.UNINDENT
.SH SEE ALSO
.sp
\fIsalt(7)\fP
\fIsalt\-master(1)\fP
\fIsalt\-minion(1)\fP
\fBsalt(7)\fP
\fBsalt\-master(1)\fP
\fBsalt\-minion(1)\fP
.SH AUTHOR
Thomas S. Hatch <thatch45@gmail.com> and many others, please see the Authors file
.\" Generated by docutils manpage writer.

View file

@ -1,6 +1,6 @@
.\" Man page generated from reStructuredText.
.
.TH "SALT-SYNDIC" "1" "Jun 14, 2018" "2018.3.2" "Salt"
.TH "SALT-SYNDIC" "1" "Sep 21, 2018" "2018.3.3" "Salt"
.SH NAME
salt-syndic \- salt-syndic Documentation
.
@ -110,9 +110,9 @@ Logfile logging log level. One of \fBall\fP, \fBgarbage\fP, \fBtrace\fP,
.UNINDENT
.SH SEE ALSO
.sp
\fIsalt(1)\fP
\fIsalt\-master(1)\fP
\fIsalt\-minion(1)\fP
\fBsalt(1)\fP
\fBsalt\-master(1)\fP
\fBsalt\-minion(1)\fP
.SH AUTHOR
Thomas S. Hatch <thatch45@gmail.com> and many others, please see the Authors file
.\" Generated by docutils manpage writer.

View file

@ -1,6 +1,6 @@
.\" Man page generated from reStructuredText.
.
.TH "SALT-UNITY" "1" "Jun 14, 2018" "2018.3.2" "Salt"
.TH "SALT-UNITY" "1" "Sep 21, 2018" "2018.3.3" "Salt"
.SH NAME
salt-unity \- salt-unity Command
.
@ -50,17 +50,17 @@ invokes that script.
.SH OPTIONS
.SH SEE ALSO
.sp
\fIsalt\-api(1)\fP
\fIsalt\-call(1)\fP
\fIsalt\-cloud(1)\fP
\fIsalt\-cp(1)\fP
\fIsalt\-key(1)\fP
\fIsalt\-main(1)\fP
\fIsalt\-master(1)\fP
\fIsalt\-minion(1)\fP
\fIsalt\-run(1)\fP
\fIsalt\-ssh(1)\fP
\fIsalt\-syndic(1)\fP
\fBsalt\-api(1)\fP
\fBsalt\-call(1)\fP
\fBsalt\-cloud(1)\fP
\fBsalt\-cp(1)\fP
\fBsalt\-key(1)\fP
\fBsalt\-main(1)\fP
\fBsalt\-master(1)\fP
\fBsalt\-minion(1)\fP
\fBsalt\-run(1)\fP
\fBsalt\-ssh(1)\fP
\fBsalt\-syndic(1)\fP
.SH AUTHOR
Thomas S. Hatch <thatch45@gmail.com> and many others, please see the Authors file
.\" Generated by docutils manpage writer.

View file

@ -1,6 +1,6 @@
.\" Man page generated from reStructuredText.
.
.TH "SALT" "1" "Jun 14, 2018" "2018.3.2" "Salt"
.TH "SALT" "1" "Sep 21, 2018" "2018.3.3" "Salt"
.SH NAME
salt \- salt
.
@ -334,9 +334,9 @@ output. Set to True or False. Default: none.
.UNINDENT
.SH SEE ALSO
.sp
\fIsalt(7)\fP
\fIsalt\-master(1)\fP
\fIsalt\-minion(1)\fP
\fBsalt(7)\fP
\fBsalt\-master(1)\fP
\fBsalt\-minion(1)\fP
.SH AUTHOR
Thomas S. Hatch <thatch45@gmail.com> and many others, please see the Authors file
.\" Generated by docutils manpage writer.

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
.\" Man page generated from reStructuredText.
.
.TH "SPM" "1" "Jun 14, 2018" "2018.3.2" "Salt"
.TH "SPM" "1" "Sep 21, 2018" "2018.3.3" "Salt"
.SH NAME
spm \- Salt Package Manager Command
.
@ -132,9 +132,9 @@ in that directory which describes them.
.UNINDENT
.SH SEE ALSO
.sp
\fIsalt(1)\fP
\fIsalt\-master(1)\fP
\fIsalt\-minion(1)\fP
\fBsalt(1)\fP
\fBsalt\-master(1)\fP
\fBsalt\-minion(1)\fP
.SH AUTHOR
Thomas S. Hatch <thatch45@gmail.com> and many others, please see the Authors file
.\" Generated by docutils manpage writer.

View file

@ -351,6 +351,23 @@ Set to zero if the minion should shutdown and not retry.
retry_dns: 30
.. conf_minion:: retry_dns_count
``retry_dns_count``
-------------------
.. versionadded:: 2018.3.4
Default: ``None``
Set the number of attempts to perform when resolving
the master hostname if name resolution fails.
By default the minion will retry indefinitely.
.. code-block:: yaml
retry_dns_count: 3
.. conf_minion:: master_port
``master_port``

View file

@ -806,7 +806,7 @@ mod_python.sls
- require_in:
- service: httpd
Now the httpd server will only start if php or mod_python are first verified to
Now the httpd server will only start if both php and mod_python are first verified to
be installed. Thus allowing for a requisite to be defined "after the fact".

File diff suppressed because it is too large Load diff

View file

@ -340,6 +340,10 @@ class LocalClient(object):
raise SaltClientError(
'The salt master could not be contacted. Is master running?'
)
except AuthenticationError as err:
raise AuthenticationError(err)
except AuthorizationError as err:
raise AuthorizationError(err)
except Exception as general_exception:
# Convert to generic client error and pass along message
raise SaltClientError(general_exception)
@ -397,6 +401,10 @@ class LocalClient(object):
raise SaltClientError(
'The salt master could not be contacted. Is master running?'
)
except AuthenticationError as err:
raise AuthenticationError(err)
except AuthorizationError as err:
raise AuthorizationError(err)
except Exception as general_exception:
# Convert to generic client error and pass along message
raise SaltClientError(general_exception)

View file

@ -247,7 +247,7 @@ def filter_by(lookup_dict,
each case to be collected in the base and overridden by the grain
selection dictionary and the merge dictionary. Default is None.
.. versionadded:: 2015.8.11, 2016.3.2
.. versionadded:: 2015.8.11,2016.3.2
CLI Example:

View file

@ -50,6 +50,7 @@ from salt.exceptions import (
SaltCloudExecutionFailure,
SaltCloudExecutionTimeout
)
from salt.utils.stringutils import to_bytes
# Import 3rd-party libs
from salt.ext import six
@ -770,7 +771,7 @@ def _compute_signature(parameters, access_key_secret):
# All aliyun API only support GET method
stringToSign = 'GET&%2F&' + percent_encode(canonicalizedQueryString[1:])
h = hmac.new(access_key_secret + "&", stringToSign, sha1)
h = hmac.new(to_bytes(access_key_secret + "&"), stringToSign, sha1)
signature = base64.encodestring(h.digest()).strip()
return signature

View file

@ -522,6 +522,7 @@ VALID_OPTS = {
# The number of seconds to sleep between retrying an attempt to resolve the hostname of a
# salt master
'retry_dns': float,
'retry_dns_count': (type(None), int),
# In the case when the resolve of the salt master hostname fails, fall back to localhost
'resolve_dns_fallback': bool,
@ -1419,6 +1420,7 @@ DEFAULT_MINION_OPTS = {
'update_url': False,
'update_restart_services': [],
'retry_dns': 30,
'retry_dns_count': None,
'resolve_dns_fallback': True,
'recon_max': 10000,
'recon_default': 1000,

View file

@ -30,16 +30,16 @@ import salt.utils.event
# Import third-party libs
try:
import logstash
HAS_LOGSTASH = True
except ImportError:
HAS_LOGSTASH = False
logstash = None
__virtualname__ = 'logstash'
def __virtual__():
if not HAS_LOGSTASH:
return False
else:
return True
return __virtualname__ \
if logstash is not None \
else (False, 'python-logstash not installed')
log = logging.getLogger(__name__)

View file

@ -96,6 +96,12 @@ class SaltSyndicMasterError(SaltException):
'''
class SaltMasterUnresolvableError(SaltException):
'''
Problem resolving the name of the Salt master
'''
class MasterExit(SystemExit):
'''
Rise when the master exits

View file

@ -2,7 +2,7 @@
'''
Generate baseline proxy minion grains for ESXi hosts.
., versionadded:: 2015.8.4
.. versionadded:: 2015.8.4
'''

View file

@ -109,6 +109,7 @@ from salt.exceptions import (
SaltSystemExit,
SaltDaemonNotRunning,
SaltException,
SaltMasterUnresolvableError
)
@ -148,8 +149,13 @@ def resolve_dns(opts, fallback=True):
True,
opts['ipv6'])
except SaltClientError:
retry_dns_count = opts.get('retry_dns_count', None)
if opts['retry_dns']:
while True:
if retry_dns_count is not None:
if retry_dns_count == 0:
raise SaltMasterUnresolvableError
retry_dns_count -= 1
import salt.log
msg = ('Master hostname: \'{0}\' not found or not responsive. '
'Retrying in {1} seconds').format(opts['master'], opts['retry_dns'])
@ -964,7 +970,17 @@ class MinionManager(MinionBase):
loaded_base_name=loaded_base_name,
jid_queue=jid_queue)
def _spawn_minions(self):
def _check_minions(self):
'''
Check the size of self.minions and raise an error if it's empty
'''
if not self.minions:
err = ('Minion unable to successfully connect to '
'a Salt Master. Exiting.')
log.error(err)
raise SaltSystemExit(code=42, msg=err)
def _spawn_minions(self, timeout=60):
'''
Spawn all the coroutines which will sign in to masters
'''
@ -983,8 +999,9 @@ class MinionManager(MinionBase):
loaded_base_name='salt.loader.{0}'.format(s_opts['master']),
jid_queue=self.jid_queue,
)
self.minions.append(minion)
self.io_loop.spawn_callback(self._connect_minion, minion)
self._connect_minion(minion)
self.io_loop.call_later(timeout, self._check_minions)
@tornado.gen.coroutine
def _connect_minion(self, minion):
@ -1002,6 +1019,7 @@ class MinionManager(MinionBase):
minion.setup_scheduler(before_connect=True)
yield minion.connect_master(failed=failed)
minion.tune_in(start=False)
self.minions.append(minion)
break
except SaltClientError as exc:
failed = True
@ -1013,6 +1031,11 @@ class MinionManager(MinionBase):
if auth_wait < self.max_auth_wait:
auth_wait += self.auth_wait
yield tornado.gen.sleep(auth_wait) # TODO: log?
except SaltMasterUnresolvableError:
err = 'Master address: \'{0}\' could not be resolved. Invalid or unresolveable address. ' \
'Set \'master\' value in minion config.'.format(minion.opts['master'])
log.error(err)
break
except Exception as e:
failed = True
log.critical(

View file

@ -4467,7 +4467,7 @@ def check_perms(name, ret, user, group, mode, attrs=None, follow_symlinks=False)
try:
lattrs = lsattr(name)
except SaltInvocationError:
lsattrs = None
lattrs = None
if lattrs is not None:
# List attributes on file
perms['lattrs'] = ''.join(lattrs.get(name, ''))

View file

@ -263,7 +263,7 @@ def list_(pkg=None, dir=None, runas=None, env=None, depth=None):
depth
Limit the depth of the packages listed
.. versionadded:: 2016.11.6, 2017.7.0
.. versionadded:: 2016.11.6,2017.7.0
CLI Example:

View file

@ -178,7 +178,9 @@ def enable(iface):
'''
if is_enabled(iface):
return True
cmd = ['netsh', 'interface', 'set', 'interface', iface, 'admin=ENABLED']
cmd = ['netsh', 'interface', 'set', 'interface',
'name={0}'.format(iface),
'admin=ENABLED']
__salt__['cmd.run'](cmd, python_shell=False)
return is_enabled(iface)
@ -195,7 +197,9 @@ def disable(iface):
'''
if is_disabled(iface):
return True
cmd = ['netsh', 'interface', 'set', 'interface', iface, 'admin=DISABLED']
cmd = ['netsh', 'interface', 'set', 'interface',
'name={0}'.format(iface),
'admin=DISABLED']
__salt__['cmd.run'](cmd, python_shell=False)
return is_disabled(iface)
@ -319,6 +323,18 @@ def set_static_dns(iface, *addrs):
'''
Set static DNS configuration on a Windows NIC
Args:
iface (str): The name of the interface to set
addrs (*):
One or more DNS servers to be added. To clear the list of DNS
servers pass an empty list (``[]``). If undefined or ``None`` no
changes will be made.
Returns:
dict: A dictionary containing the new DNS settings
CLI Example:
.. code-block:: bash
@ -326,17 +342,31 @@ def set_static_dns(iface, *addrs):
salt -G 'os_family:Windows' ip.set_static_dns 'Local Area Connection' '192.168.1.1'
salt -G 'os_family:Windows' ip.set_static_dns 'Local Area Connection' '192.168.1.252' '192.168.1.253'
'''
if addrs is () or str(addrs[0]).lower() == 'none':
return {'Interface': iface, 'DNS Server': 'No Changes'}
# Clear the list of DNS servers if [] is passed
if str(addrs[0]).lower() == '[]':
log.debug('Clearing list of DNS servers')
cmd = ['netsh', 'interface', 'ip', 'set', 'dns',
'name={0}'.format(iface),
'source=static',
'address=none']
__salt__['cmd.run'](cmd, python_shell=False)
return {'Interface': iface, 'DNS Server': []}
addr_index = 1
for addr in addrs:
if addr_index == 1:
cmd = ['netsh', 'int', 'ip', 'set', 'dns',
iface, 'static', addrs[0], 'primary']
cmd = ['netsh', 'interface', 'ip', 'set', 'dns',
'name={0}'.format(iface),
'source=static',
'address={0}'.format(addr),
'register=primary']
__salt__['cmd.run'](cmd, python_shell=False)
addr_index = addr_index + 1
else:
cmd = ['netsh', 'interface', 'ip', 'add', 'dns',
'name={0}'.format(iface),
'addr={0}'.format(addr),
'address={0}'.format(addr),
'index={0}'.format(addr_index)]
__salt__['cmd.run'](cmd, python_shell=False)
addr_index = addr_index + 1

View file

@ -107,7 +107,7 @@ def _status_wait(service_name, end_time, service_states):
Helper function that will wait for the status of the service to match the
provided status before an end time expires. Used for service stop and start
.. versionadded:: 2017.7.9, 2018.3.4
.. versionadded:: 2017.7.9,2018.3.4
Args:
service_name (str):
@ -460,7 +460,7 @@ def start(name, timeout=90):
The time in seconds to wait for the service to start before
returning. Default is 90 seconds
.. versionadded:: 2017.7.9, 2018.3.4
.. versionadded:: 2017.7.9,2018.3.4
Returns:
bool: ``True`` if successful, otherwise ``False``. Also returns ``True``
@ -502,7 +502,7 @@ def stop(name, timeout=90):
The time in seconds to wait for the service to stop before
returning. Default is 90 seconds
.. versionadded:: 2017.7.9, 2018.3.4
.. versionadded:: 2017.7.9,2018.3.4
Returns:
bool: ``True`` if successful, otherwise ``False``. Also returns ``True``
@ -549,7 +549,7 @@ def restart(name, timeout=90):
then to the start command. A timeout of 90 could take up to 180
seconds if the service is long in stopping and starting
.. versionadded:: 2017.7.9, 2018.3.4
.. versionadded:: 2017.7.9,2018.3.4
Returns:
bool: ``True`` if successful, otherwise ``False``
@ -1212,7 +1212,7 @@ def delete(name, timeout=90):
returning. This is necessary because a service must be stopped
before it can be deleted. Default is 90 seconds
.. versionadded:: 2017.7.9, 2018.3.4
.. versionadded:: 2017.7.9,2018.3.4
Returns:
bool: ``True`` if successful, otherwise ``False``. Also returns ``True``

View file

@ -1103,13 +1103,15 @@ class SaltAPIHandler(BaseSaltAPIHandler): # pylint: disable=W0223
'''
Disbatch runner client commands
'''
full_return = chunk.pop('full_return', False)
pub_data = self.saltclients['runner'](chunk)
tag = pub_data['tag'] + '/ret'
try:
event = yield self.application.event_listener.get_event(self, tag=tag)
# only return the return data
raise tornado.gen.Return(event['data']['return'])
ret = event if full_return else event['data']['return']
raise tornado.gen.Return(ret)
except TimeoutException:
raise tornado.gen.Return('Timeout waiting for runner to execute')

View file

@ -38,6 +38,7 @@ import salt.utils.decorators.state
import salt.utils.dictupdate
import salt.utils.event
import salt.utils.files
import salt.utils.hashutils
import salt.utils.immutabletypes as immutabletypes
import salt.utils.platform
import salt.utils.process
@ -1763,7 +1764,9 @@ class State(object):
ret['duration'] = duration
troot = os.path.join(self.opts['cachedir'], self.jid)
tfile = os.path.join(troot, _clean_tag(tag))
tfile = os.path.join(
troot,
salt.utils.hashutils.sha1_digest(tag))
if not os.path.isdir(troot):
try:
os.makedirs(troot)
@ -2218,7 +2221,10 @@ class State(object):
proc = running[tag].get('proc')
if proc:
if not proc.is_alive():
ret_cache = os.path.join(self.opts['cachedir'], self.jid, _clean_tag(tag))
ret_cache = os.path.join(
self.opts['cachedir'],
self.jid,
salt.utils.hashutils.sha1_digest(tag))
if not os.path.isfile(ret_cache):
ret = {'result': False,
'comment': 'Parallel process failed to return',

View file

@ -1124,7 +1124,7 @@ def _get_template_texts(source_list=None,
tmplines = None
with salt.utils.files.fopen(rndrd_templ_fn, 'rb') as fp_:
tmplines = fp_.read()
tmplines = tmplines.decode(__salt_system_encoding__)
tmplines = salt.utils.stringutils.to_unicode(tmplines)
tmplines = tmplines.splitlines(True)
if not tmplines:
msg = 'Failed to read rendered template file {0} ({1})'

View file

@ -102,22 +102,20 @@ def _validate(dns_proto, dns_servers, ip_proto, ip_addrs, gateway):
if dns_servers is not None:
errors.append(
'The dns_servers param cannot be set if unless dns_proto is '
'set to \'static\'.'
'set to \'static\''
)
else:
if not dns_servers:
errors.append(
'The dns_servers param is required to set static DNS servers.'
)
if str(dns_servers).lower() in ['none', '[]']:
pass
elif not isinstance(dns_servers, list):
errors.append(
'The dns_servers param must be formatted as a list.'
'The dns_servers param must be formatted as a list'
)
else:
bad_ips = [x for x in dns_servers
if not salt.utils.validate.net.ipv4_addr(x)]
if bad_ips:
errors.append('Invalid DNS server IPs: {0}.'
errors.append('Invalid DNS server IPs: {0}'
.format(', '.join(bad_ips)))
# Validate IP configuration
@ -125,33 +123,33 @@ def _validate(dns_proto, dns_servers, ip_proto, ip_addrs, gateway):
if ip_addrs is not None:
errors.append(
'The ip_addrs param cannot be set if unless ip_proto is set '
'to \'static\'.'
'to \'static\''
)
if gateway is not None:
errors.append(
'A gateway IP cannot be set if unless ip_proto is set to '
'\'static\'.'
'\'static\''
)
else:
if not ip_addrs:
errors.append(
'The ip_addrs param is required to set static IPs.'
'The ip_addrs param is required to set static IPs'
)
elif not isinstance(ip_addrs, list):
errors.append(
'The ip_addrs param must be formatted as a list.'
'The ip_addrs param must be formatted as a list'
)
else:
bad_ips = [x for x in ip_addrs
if not salt.utils.validate.net.ipv4_addr(x)]
if bad_ips:
errors.append('The following static IPs are invalid: '
'{0}.'.format(', '.join(bad_ips)))
'{0}'.format(', '.join(bad_ips)))
# Validate default gateway
if gateway is not None:
if not salt.utils.validate.net.ipv4_addr(gateway):
errors.append('Gateway IP {0} is invalid.'.format(gateway))
errors.append('Gateway IP {0} is invalid'.format(gateway))
return errors
@ -178,7 +176,10 @@ def _changes(cur, dns_proto, dns_servers, ip_proto, ip_addrs, gateway):
else 'dhcp'
)
if cur_dns_proto == 'static':
cur_dns_servers = cur['Statically Configured DNS Servers']
if isinstance(cur['Statically Configured DNS Servers'], list):
cur_dns_servers = cur['Statically Configured DNS Servers']
else:
cur_dns_servers = [cur['Statically Configured DNS Servers']]
if set(dns_servers or ['None']) != set(cur_dns_servers):
changes['dns_servers'] = dns_servers
elif 'DNS servers configured through DHCP' in cur:
@ -216,37 +217,66 @@ def managed(name,
'''
Ensure that the named interface is configured properly.
name
The name of the interface to manage
Args:
dns_proto : None
Set to ``static`` and use the ``dns_servers`` parameter to provide a
list of DNS nameservers. set to ``dhcp`` to use DHCP to get the DNS
servers.
name (str):
The name of the interface to manage
dns_servers : None
A list of static DNS servers.
dns_proto (str): None
Set to ``static`` and use the ``dns_servers`` parameter to provide a
list of DNS nameservers. set to ``dhcp`` to use DHCP to get the DNS
servers.
ip_proto : None
Set to ``static`` and use the ``ip_addrs`` and (optionally) ``gateway``
parameters to provide a list of static IP addresses and the default
gateway. Set to ``dhcp`` to use DHCP.
dns_servers (list): None
A list of static DNS servers. To clear the list of DNS servers pass
an empty list (``[]``). ``None`` will make no changes.
ip_addrs : None
A list of static IP addresses.
ip_proto (str): None
Set to ``static`` and use the ``ip_addrs`` and (optionally)
``gateway`` parameters to provide a list of static IP addresses and
the default gateway. Set to ``dhcp`` to use DHCP.
gateway : None
A list of static IP addresses.
ip_addrs (list): None
A list of static IP addresses with netmask flag, ie: 192.168.0.11/24
enabled : True
Set to ``False`` to ensure that this interface is disabled.
gateway (str): None
The gateway to set for the interface
enabled (bool): True
Set to ``False`` to ensure that this interface is disabled.
Returns:
dict: A dictionary of old and new settings
Example:
.. code-block:: yaml
Ethernet1:
network.managed:
- dns_proto: static
- dns_servers:
- 8.8.8.8
- 8.8.8.4
- ip_proto: static
- ip_addrs:
- 192.168.0.100/24
Clear DNS entries example:
.. code-block:: yaml
Ethernet1:
network.managed:
- dns_proto: static
- dns_servers: []
- ip_proto: dhcp
'''
ret = {
'name': name,
'changes': {},
'result': True,
'comment': 'Interface \'{0}\' is up to date.'.format(name)
'comment': 'Interface \'{0}\' is up to date'.format(name)
}
dns_proto = six.text_type(dns_proto).lower()
@ -255,16 +285,16 @@ def managed(name,
errors = []
if dns_proto not in __VALID_PROTO:
ret['result'] = False
errors.append('dns_proto must be one of the following: {0}.'
errors.append('dns_proto must be one of the following: {0}'
.format(', '.join(__VALID_PROTO)))
if ip_proto not in __VALID_PROTO:
errors.append('ip_proto must be one of the following: {0}.'
errors.append('ip_proto must be one of the following: {0}'
.format(', '.join(__VALID_PROTO)))
if errors:
ret['result'] = False
ret['comment'] = ' '.join(errors)
ret['comment'] = '\n'.join(errors)
return ret
try:
@ -303,7 +333,7 @@ def managed(name,
if errors:
ret['result'] = False
ret['comment'] = ('The following SLS configuration errors were '
'detected: {0}'.format(' '.join(errors)))
'detected:\n- {0}'.format('\n- '.join(errors)))
return ret
old = __salt__['ip.get_interface'](name)
@ -319,49 +349,63 @@ def managed(name,
ip_proto,
ip_addrs,
gateway)
# If dns_servers is the default `None` make no changes
# To clear the list, pass an empty dict
if str(dns_servers).lower() == 'none':
changes.pop('dns_servers', None)
if not changes:
return ret
if __opts__['test']:
comments = []
if 'dns_proto' in changes:
comments.append('DNS protocol will be changed to: {0}.'
comments.append('DNS protocol will be changed to: {0}'
.format(changes['dns_proto']))
if dns_proto == 'static' and 'dns_servers' in changes:
comments.append(
'DNS servers will be set to the following: {0}.'
.format(', '.join(changes['dns_servers']))
)
if len(changes['dns_servers']) == 0:
comments.append('The list of DNS servers will be cleared')
else:
comments.append(
'DNS servers will be set to the following: {0}'
.format(', '.join(changes['dns_servers']))
)
if 'ip_proto' in changes:
comments.append('IP protocol will be changed to: {0}.'
comments.append('IP protocol will be changed to: {0}'
.format(changes['ip_proto']))
if ip_proto == 'static':
if 'ip_addrs' in changes:
comments.append(
'IP addresses will be set to the following: {0}.'
'IP addresses will be set to the following: {0}'
.format(', '.join(changes['ip_addrs']))
)
if 'gateway' in changes:
if changes['gateway'] is None:
comments.append('Default gateway will be removed.')
comments.append('Default gateway will be removed')
else:
comments.append(
'Default gateway will be set to {0}.'
'Default gateway will be set to {0}'
.format(changes['gateway'])
)
ret['result'] = None
ret['comment'] = ('The following changes will be made to '
'interface \'{0}\': {1}'
.format(name, ' '.join(comments)))
'interface \'{0}\':\n- {1}'
.format(name, '\n- '.join(comments)))
return ret
if changes.get('dns_proto') == 'dhcp':
__salt__['ip.set_dhcp_dns'](name)
elif changes.get('dns_servers'):
if changes.get('dns_servers'):
__salt__['ip.set_static_dns'](name, *changes['dns_servers'])
elif 'dns_servers' in changes:
if len(changes['dns_servers']) == 0:
# To clear the list of DNS servers you have to pass []. Later
# changes gets passed like *args and a single empty list is
# converted to an empty tuple. So, you have to add [] here
changes['dns_servers'] = [[]]
__salt__['ip.set_static_dns'](name, *changes['dns_servers'])
if changes.get('ip_proto') == 'dhcp':
__salt__['ip.set_dhcp_ip'](name)

View file

@ -791,10 +791,10 @@ def backup_minion(path, bkroot):
def get_encoding(path):
'''
Detect a file's encoding using the following:
- Check for ascii
- Check for Byte Order Marks (BOM)
- Check for UTF-8 Markers
- Check System Encoding
- Check for ascii
Args:
@ -867,10 +867,6 @@ def get_encoding(path):
except os.error:
raise CommandExecutionError('Failed to open file')
# Check for ASCII first
if check_ascii(data):
return 'ASCII'
# Check for Unicode BOM
encoding = check_bom(data)
if encoding:
@ -884,4 +880,8 @@ def get_encoding(path):
if check_system_encoding(data):
return __salt_system_encoding__
# Check for ASCII first
if check_ascii(data):
return 'ASCII'
raise CommandExecutionError('Could not detect file encoding')

View file

@ -93,6 +93,16 @@ def md5_digest(instr):
)
def sha1_digest(instr):
'''
Generate an sha1 hash of a given string.
'''
if six.PY3:
b = salt.utils.stringutils.to_bytes(instr)
return hashlib.sha1(b).hexdigest()
return hashlib.sha1(instr).hexdigest()
@jinja_filter('sha256')
def sha256_digest(instr):
'''

View file

@ -134,7 +134,8 @@ def get_vault_connection():
raise salt.exceptions.CommandExecutionError(errmsg)
if 'vault' in __opts__ and __opts__.get('__role', 'minion') == 'master':
return _use_local_config()
log.debug('Contacting master for Vault connection details')
return _get_token_and_url_from_master()
elif any((__opts__['local'], __opts__['file_client'] == 'local', __opts__['master_type'] == 'disable')):
return _use_local_config()
else:

View file

@ -0,0 +1 @@
{{unicode_string}}

View file

@ -0,0 +1,16 @@
somefile-exists:
file:
- managed
- name: {{ pillar['name'] }}
somefile-blockreplace:
file:
- blockreplace
- append_if_not_found: true
- name: {{ pillar['name'] }}
- template: jinja
- source: salt://issue-49043
- require:
- file: somefile-exists
- context:
unicode_string: "\xe4\xf6\xfc"

View file

@ -0,0 +1,9 @@
test_cmd_too_long:
cmd.run:
- name: {{ pillar['long_command'] }}
- parallel: True
test_cmd_not_found:
cmd.run:
- name: {{ pillar['short_command'] }}
- parallel: True

View file

@ -2,8 +2,10 @@
# Import Python libs
from __future__ import absolute_import, print_function, unicode_literals
import logging
import os
import shutil
import sys
import tempfile
import textwrap
import threading
@ -13,10 +15,11 @@ import time
from tests.support.case import ModuleCase
from tests.support.helpers import with_tempdir
from tests.support.unit import skipIf
from tests.support.paths import FILES, TMP, TMP_PILLAR_TREE
from tests.support.paths import BASE_FILES, TMP, TMP_PILLAR_TREE
from tests.support.mixins import SaltReturnAssertsMixin
# Import Salt libs
import salt.utils.atomicfile
import salt.utils.files
import salt.utils.path
import salt.utils.platform
@ -26,7 +29,6 @@ from salt.modules.virtualenv_mod import KNOWN_BINARY_NAMES
# Import 3rd-party libs
from salt.ext import six
import logging
log = logging.getLogger(__name__)
@ -68,14 +70,22 @@ class StateModuleTest(ModuleCase, SaltReturnAssertsMixin):
maxDiff = None
def setUp(self):
super(StateModuleTest, self).setUp()
destpath = os.path.join(FILES, 'file', 'base', 'testappend', 'firstif')
reline(destpath, destpath, force=True)
destpath = os.path.join(FILES, 'file', 'base', 'testappend', 'secondif')
reline(destpath, destpath, force=True)
sls = self.run_function('saltutil.sync_modules')
assert isinstance(sls, list)
@classmethod
def setUpClass(cls):
def _reline(path, ending=DEFAULT_ENDING):
'''
Normalize the line endings of a file.
'''
with salt.utils.files.fopen(path, 'rb') as fhr:
lines = fhr.read().splitlines()
with salt.utils.atomicfile.atomic_open(path, 'wb') as fhw:
for line in lines:
fhw.write(line + ending)
destpath = os.path.join(BASE_FILES, 'testappend', 'firstif')
_reline(destpath)
destpath = os.path.join(BASE_FILES, 'testappend', 'secondif')
_reline(destpath)
def test_show_highstate(self):
'''
@ -1830,18 +1840,50 @@ class StateModuleTest(ModuleCase, SaltReturnAssertsMixin):
test state.sls with saltenv using a nonbase environment
with a salt source
'''
file_name = os.path.join(TMP, 'nonbase_env')
state_run = self.run_function(
filename = os.path.join(TMP, 'nonbase_env')
try:
ret = self.run_function(
'state.sls',
mods='non-base-env',
saltenv='prod'
)
ret = ret[next(iter(ret))]
assert ret['result']
assert ret['comment'] == 'File {0} updated'.format(filename)
assert os.path.isfile(filename)
finally:
try:
os.remove(filename)
except OSError:
pass
@skipIf(sys.platform.startswith('win'), 'Skipped until parallel states can be fixed on Windows')
def test_parallel_state_with_long_tag(self):
'''
This tests the case where the state being executed has a long ID dec or
name and states are being run in parallel. The filenames used for the
parallel state cache were previously based on the tag for each chunk,
and longer ID decs or name params can cause the cache file to be longer
than the operating system's max file name length. To counter this we
instead generate a SHA1 hash of the chunk's tag to use as the cache
filename. This test will ensure that long tags don't cause caching
failures.
See https://github.com/saltstack/salt/issues/49738 for more info.
'''
short_command = 'helloworld'
long_command = short_command * 25
ret = self.run_function(
'state.sls',
mods='non-base-env',
saltenv='prod'
mods='issue-49738',
pillar={'short_command': short_command,
'long_command': long_command}
)
state_id = 'file_|-test_file_|-{0}_|-managed'.format(file_name)
self.assertEqual(state_run[state_id]['comment'],
'File {0} updated'.format(file_name))
self.assertTrue(
state_run['file_|-test_file_|-{0}_|-managed'.format(file_name)]['result'])
self.assertTrue(os.path.isfile(file_name))
comments = sorted([x['comment'] for x in six.itervalues(ret)])
expected = sorted(['Command "{0}" run'.format(x)
for x in (short_command, long_command)])
assert comments == expected, '{0} != {1}'.format(comments, expected)
def _add_runtime_pillar(self, pillar):
'''

View file

@ -239,7 +239,7 @@ class TestSaltAPIHandler(_SaltnadoIntegrationTestCase):
self.assertEqual(len(ret), 3) # make sure we got 3 responses
self.assertIn('jid', ret[0]) # the first 2 are regular returns
self.assertIn('jid', ret[1])
self.assertIn('Authentication error occurred.', ret[2]) # bad auth
self.assertIn('Failed to authenticate', ret[2]) # bad auth
self.assertEqual(ret[0]['minions'], sorted(['minion', 'sub_minion']))
self.assertEqual(ret[1]['minions'], sorted(['minion', 'sub_minion']))

View file

@ -3841,6 +3841,25 @@ class BlockreplaceTest(ModuleCase, SaltReturnAssertsMixin):
self._read(name),
self.with_matching_block_and_marker_end_not_after_newline)
@with_tempfile()
def test_issue_49043(self, name):
ret = self.run_function(
'state.sls',
mods='issue-49043',
pillar={'name': name},
)
log.error("ret = %s", repr(ret))
diff = '--- \n+++ \n@@ -0,0 +1,3 @@\n'
diff += dedent('''\
+#-- start managed zone --
+äöü
+#-- end managed zone --
''')
job = 'file_|-somefile-blockreplace_|-{}_|-blockreplace'.format(name)
self.assertEqual(
ret[job]['changes']['diff'],
diff)
class RemoteFileTest(ModuleCase, SaltReturnAssertsMixin):
'''

View file

@ -440,7 +440,8 @@ class SaltTestingParser(optparse.OptionParser):
if self.options.tests_logfile:
filehandler = logging.FileHandler(
mode='w', # Not preserved between re-runs
filename=self.options.tests_logfile
filename=self.options.tests_logfile,
encoding='utf-8',
)
# The logs of the file are the most verbose possible
filehandler.setLevel(logging.DEBUG)

View file

@ -13,7 +13,8 @@ from tests.support.mock import (
MagicMock,
patch,
NO_MOCK,
NO_MOCK_REASON
NO_MOCK_REASON,
call
)
# Import Salt Libs
@ -124,13 +125,21 @@ class WinShadowTestCase(TestCase, LoaderModuleMockMixin):
'''
Test if it enable an interface.
'''
mock_cmd = MagicMock(return_value=ETHERNET_ENABLE)
with patch.dict(win_ip.__salt__, {'cmd.run': mock_cmd}):
# Test with enabled interface
with patch.object(win_ip, 'is_enabled', return_value=True):
self.assertTrue(win_ip.enable('Ethernet'))
mock_cmd = MagicMock(return_value='Connect state: Disconnected')
with patch.dict(win_ip.__salt__, {'cmd.run': mock_cmd}):
self.assertFalse(win_ip.enable('Ethernet'))
mock_cmd = MagicMock()
with patch.object(win_ip, 'is_enabled', side_effect=[False, True]), \
patch.dict(win_ip.__salt__, {'cmd.run': mock_cmd}):
self.assertTrue(win_ip.enable('Ethernet'))
mock_cmd.called_once_with(
['netsh', 'interface', 'set', 'interface',
'name=Ethernet',
'admin=ENABLED'],
python_shell=False
)
# 'disable' function tests: 1
@ -138,14 +147,21 @@ class WinShadowTestCase(TestCase, LoaderModuleMockMixin):
'''
Test if it disable an interface.
'''
mock_cmd = MagicMock(return_value=ETHERNET_ENABLE)
with patch.dict(win_ip.__salt__, {'cmd.run': mock_cmd}):
self.assertFalse(win_ip.disable('Ethernet'))
mock_cmd = MagicMock(return_value='Connect state: Disconnected')
with patch.dict(win_ip.__salt__, {'cmd.run': mock_cmd}):
with patch.object(win_ip, 'is_disabled', return_value=True):
self.assertTrue(win_ip.disable('Ethernet'))
mock_cmd = MagicMock()
with patch.object(win_ip, 'is_disabled', side_effect=[False, True]),\
patch.dict(win_ip.__salt__, {'cmd.run': mock_cmd}):
self.assertTrue(win_ip.disable('Ethernet'))
mock_cmd.called_once_with(
['netsh', 'interface', 'set', 'interface',
'name=Ethernet',
'admin=DISABLED'],
python_shell=False
)
# 'get_subnet_length' function tests: 1
def test_get_subnet_length(self):
@ -203,7 +219,7 @@ class WinShadowTestCase(TestCase, LoaderModuleMockMixin):
'''
Test if it set static DNS configuration on a Windows NIC.
'''
mock_cmd = MagicMock(return_value=ETHERNET_CONFIG)
mock_cmd = MagicMock()
with patch.dict(win_ip.__salt__, {'cmd.run': mock_cmd}):
self.assertDictEqual(win_ip.set_static_dns('Ethernet',
'192.168.1.252',
@ -211,6 +227,54 @@ class WinShadowTestCase(TestCase, LoaderModuleMockMixin):
{'DNS Server': ('192.168.1.252',
'192.168.1.253'),
'Interface': 'Ethernet'})
mock_cmd.assert_has_calls([
call(['netsh', 'interface', 'ip', 'set', 'dns',
'name=Ethernet',
'source=static',
'address=192.168.1.252',
'register=primary'],
python_shell=False),
call(['netsh', 'interface', 'ip', 'add', 'dns',
'name=Ethernet',
'address=192.168.1.253',
'index=2'],
python_shell=False)]
)
def test_set_static_dns_clear(self):
'''
Test if it set static DNS configuration on a Windows NIC.
'''
mock_cmd = MagicMock()
with patch.dict(win_ip.__salt__, {'cmd.run': mock_cmd}):
self.assertDictEqual(win_ip.set_static_dns('Ethernet', []),
{'DNS Server': [],
'Interface': 'Ethernet'})
mock_cmd.assert_called_once_with(
['netsh', 'interface', 'ip', 'set', 'dns',
'name=Ethernet',
'source=static',
'address=none'],
python_shell=False
)
def test_set_static_dns_no_action(self):
'''
Test if it set static DNS configuration on a Windows NIC.
'''
# Test passing nothing
self.assertDictEqual(win_ip.set_static_dns('Ethernet'),
{'DNS Server': 'No Changes',
'Interface': 'Ethernet'})
# Test passing None
self.assertDictEqual(win_ip.set_static_dns('Ethernet', None),
{'DNS Server': 'No Changes',
'Interface': 'Ethernet'})
# Test passing string None
self.assertDictEqual(win_ip.set_static_dns('Ethernet', 'None'),
{'DNS Server': 'No Changes',
'Interface': 'Ethernet'})
# 'set_dhcp_dns' function tests: 1

View file

@ -28,93 +28,242 @@ class WinNetworkTestCase(TestCase, LoaderModuleMockMixin):
def setup_loader_modules(self):
return {win_network: {}}
def test_managed(self):
def test_managed_missing_parameters(self):
'''
Test to ensure that the named interface is configured properly.
Test to ensure that the named interface is configured properly.
'''
ret = {'name': 'salt',
'changes': {},
'result': False,
'comment': ''}
ret.update({'comment': 'dns_proto must be one of the following:'
' static, dhcp. ip_proto must be one of the following:'
' static, dhcp.'})
'comment': 'dns_proto must be one of the following: static, dhcp\n'
'ip_proto must be one of the following: static, dhcp'}
self.assertDictEqual(win_network.managed('salt'), ret)
def test_managed_static_enabled_false(self):
ret = {'name': 'salt',
'changes': {},
'result': True,
'comment': 'Interface \'salt\' is up to date (already disabled)'}
mock_false = MagicMock(return_value=False)
with patch.dict(win_network.__salt__, {"ip.is_enabled": mock_false}):
self.assertDictEqual(
win_network.managed(
'salt', dns_proto='static', ip_proto='static', enabled=False),
ret)
def test_managed_test_true(self):
ret = {'name': 'salt',
'changes': {},
'result': False,
'comment': 'Failed to enable interface \'salt\' to make changes'}
mock_false = MagicMock(return_value=False)
mock_true = MagicMock(return_value=True)
mock1 = MagicMock(side_effect=[False, True, True, True, True, True,
True])
mock2 = MagicMock(side_effect=[False, True, True, {'salt': 'True'},
{'salt': 'True'}])
with patch.dict(win_network.__salt__, {"ip.is_enabled": mock_false,
"ip.is_disabled": mock1,
"ip.enable": mock_false,
"ip.get_interface": mock2,
"ip.set_dhcp_dns": mock_false,
"ip.set_dhcp_ip": mock_false}):
ret.update({'comment': "Interface 'salt' is up to date."
" (already disabled)", 'result': True})
self.assertDictEqual(win_network.managed('salt',
dns_proto='static',
ip_proto='static',
enabled=False), ret)
"ip.enable": mock_false}), \
patch.dict(win_network.__opts__, {"test": False}):
self.assertDictEqual(
win_network.managed(
'salt', dns_proto='static', ip_proto='static'),
ret)
with patch.dict(win_network.__opts__, {"test": False}):
ret.update({'comment': "Failed to enable interface 'salt'"
" to make changes", 'result': False})
self.assertDictEqual(win_network.managed('salt',
dns_proto='static',
ip_proto='static'),
ret)
mock_false = MagicMock(side_effect=['True', False, False, False, False,
False])
def test_managed_validate_errors(self):
ret = {'name': 'salt',
'changes': {},
'result': False,
'comment': 'The following SLS configuration errors were '
'detected:\n'
'- First Error\n'
'- Second Error'}
mock_true = MagicMock(return_value=True)
mock_validate = MagicMock(return_value=['First Error', 'Second Error'])
with patch.dict(win_network.__salt__, {"ip.is_enabled": mock_true}),\
patch.object(win_network, '_validate', mock_validate):
self.assertDictEqual(
win_network.managed(
'salt', dns_proto='static', ip_proto='static'),
ret)
with patch.dict(win_network.__salt__, {"ip.is_enabled": mock_true}):
with patch.object(win_network, '_validate', mock_false):
ret.update({'comment': 'The following SLS configuration'
' errors were detected: T r u e'})
self.assertDictEqual(win_network.managed('salt',
dns_proto='static',
ip_proto='static'),
ret)
def test_managed_get_current_config_failed(self):
ret = {'name': 'salt',
'changes': {},
'result': False,
'comment': 'Unable to get current configuration for interface '
'\'salt\''}
mock_true = MagicMock(return_value=True)
mock_false = MagicMock(return_value=False)
mock_validate = MagicMock(return_value=[])
with patch.dict(win_network.__salt__, {'ip.is_enabled': mock_true,
'ip.get_interface': mock_false}), \
patch.object(win_network, '_validate', mock_validate):
ret.update({'comment': "Unable to get current"
" configuration for interface 'salt'",
'result': False})
self.assertDictEqual(win_network.managed('salt',
dns_proto='dhcp',
ip_proto='dhcp'),
ret)
self.assertDictEqual(
win_network.managed('salt', dns_proto='dhcp', ip_proto='dhcp'),
ret)
mock_false = MagicMock(side_effect=[False, [''],
{'dns_proto': 'dhcp',
'ip_proto': 'dhcp'},
{'dns_proto': 'dhcp',
'ip_proto': 'dhcp'}])
ret.update({'comment': "Interface 'salt' is up to date.",
'result': True})
with patch.object(win_network, '_changes', mock_false):
self.assertDictEqual(win_network.managed('salt',
dns_proto='dhcp',
ip_proto='dhcp'
), ret)
def test_managed_test_true_no_changes(self):
ret = {'name': 'salt',
'changes': {},
'result': True,
'comment': 'Interface \'salt\' is up to date'}
mock_true = MagicMock(return_value=True)
mock_validate = MagicMock(return_value=[])
mock_get_int = MagicMock(return_value={
'DHCP enabled': 'yes',
'DNS servers configured through DHCP': '192.168.0.10'})
with patch.dict(win_network.__salt__, {'ip.is_enabled': mock_true,
'ip.get_interface': mock_get_int}), \
patch.dict(win_network.__opts__, {"test": True}), \
patch.object(win_network, '_validate', mock_validate):
self.assertDictEqual(
win_network.managed('salt', dns_proto='dhcp', ip_proto='dhcp'),
ret)
ret.update({'comment': "The following changes will be made"
" to interface 'salt': ", 'result': None})
with patch.dict(win_network.__opts__, {"test": True}):
self.assertDictEqual(win_network.managed('salt',
dns_proto='dh'
'cp',
ip_proto='dhcp'
), ret)
def test_managed_test_true_changes(self):
ret = {'name': 'salt',
'changes': {},
'result': None,
'comment': 'The following changes will be made to interface '
'\'salt\':\n'
'- DNS protocol will be changed to: dhcp'}
mock_true = MagicMock(return_value=True)
mock_validate = MagicMock(return_value=[])
mock_get_int = MagicMock(return_value={
'DHCP enabled': 'no',
'Statically Configured DNS Servers': '192.168.0.10'})
with patch.dict(win_network.__salt__, {'ip.is_enabled': mock_true,
'ip.get_interface': mock_get_int}), \
patch.dict(win_network.__opts__, {"test": True}), \
patch.object(win_network, '_validate', mock_validate):
with patch.dict(win_network.__opts__, {"test": False}):
ret.update({'comment': "Failed to set desired"
" configuration settings for interface"
" 'salt'", 'result': False})
self.assertDictEqual(win_network.managed('salt',
dns_proto='dh'
'cp',
ip_proto='dhcp'
), ret)
self.assertDictEqual(
win_network.managed('salt', dns_proto='dhcp', ip_proto='dhcp'),
ret)
def test_managed_failed(self):
ret = {'name': 'salt',
'changes': {},
'result': False,
'comment': 'Failed to set desired configuration settings for '
'interface \'salt\''}
mock_true = MagicMock(return_value=True)
mock_validate = MagicMock(return_value=[])
mock_get_int = MagicMock(return_value={
'DHCP enabled': 'no',
'Statically Configured DNS Servers': '192.168.0.10'})
with patch.dict(win_network.__salt__, {'ip.is_enabled': mock_true,
'ip.get_interface': mock_get_int,
'ip.set_dhcp_dns': mock_true,
'ip.set_dhcp_ip': mock_true}), \
patch.dict(win_network.__opts__, {"test": False}), \
patch.object(win_network, '_validate', mock_validate):
self.assertDictEqual(
win_network.managed('salt', dns_proto='dhcp', ip_proto='dhcp'),
ret)
def test_managed(self):
ret = {'name': 'salt',
'changes': {
'DHCP enabled': {
'new': 'yes',
'old': 'no'},
'DNS servers configured through DHCP': {
'new': '192.168.0.10',
'old': ''},
'Statically Configured DNS Servers': {
'new': '',
'old': '192.168.0.10'
}
},
'result': True,
'comment': 'Successfully updated configuration for interface '
'\'salt\''}
mock_true = MagicMock(return_value=True)
mock_validate = MagicMock(return_value=[])
mock_get_int = MagicMock(side_effect=[
{'DHCP enabled': 'no', 'Statically Configured DNS Servers': '192.168.0.10'},
{'DHCP enabled': 'yes', 'DNS servers configured through DHCP': '192.168.0.10'},
])
with patch.dict(win_network.__salt__, {'ip.is_enabled': mock_true,
'ip.get_interface': mock_get_int,
'ip.set_dhcp_dns': mock_true,
'ip.set_dhcp_ip': mock_true}), \
patch.dict(win_network.__opts__, {"test": False}), \
patch.object(win_network, '_validate', mock_validate):
self.assertDictEqual(
win_network.managed('salt', dns_proto='dhcp', ip_proto='dhcp'),
ret)
def test_managed_static_dns_clear(self):
expected = {'name': 'salt',
'changes': {
'Statically Configured DNS Servers': {
'new': 'None',
'old': '192.168.0.10'
}
},
'result': True,
'comment': 'Successfully updated configuration for '
'interface \'salt\''}
mock_true = MagicMock(return_value=True)
mock_validate = MagicMock(return_value=[])
mock_get_int = MagicMock(side_effect=[
{'DHCP enabled': 'no', 'Statically Configured DNS Servers': '192.168.0.10'},
{'DHCP enabled': 'no', 'Statically Configured DNS Servers': 'None'},
])
with patch.dict(win_network.__salt__, {'ip.is_enabled': mock_true,
'ip.get_interface': mock_get_int,
'ip.set_static_dns': mock_true}), \
patch.dict(win_network.__opts__, {"test": False}), \
patch.object(win_network, '_validate', mock_validate):
ret = win_network.managed(
'salt', dns_proto='static', dns_servers=[], ip_proto='dhcp')
self.assertDictEqual(ret, expected)
def test_managed_static_dns(self):
expected = {'name': 'salt',
'changes': {
'Statically Configured DNS Servers': {
'new': '192.168.0.10',
'old': 'None'
}
},
'result': True,
'comment': 'Successfully updated configuration for '
'interface \'salt\''}
mock_true = MagicMock(return_value=True)
mock_validate = MagicMock(return_value=[])
mock_get_int = MagicMock(side_effect=[
{'DHCP enabled': 'no', 'Statically Configured DNS Servers': 'None'},
{'DHCP enabled': 'no', 'Statically Configured DNS Servers': '192.168.0.10'},
])
with patch.dict(win_network.__salt__, {'ip.is_enabled': mock_true,
'ip.get_interface': mock_get_int,
'ip.set_static_dns': mock_true}), \
patch.dict(win_network.__opts__, {"test": False}), \
patch.object(win_network, '_validate', mock_validate):
ret = win_network.managed(
'salt', dns_proto='static', dns_servers=['192.168.0.10'], ip_proto='dhcp')
self.assertDictEqual(ret, expected)
def test_managed_static_dns_no_action(self):
expected = {'name': 'salt',
'changes': {},
'result': True,
'comment': 'Interface \'salt\' is up to date'}
mock_true = MagicMock(return_value=True)
mock_validate = MagicMock(return_value=[])
mock_get_int = MagicMock(return_value={
'DHCP enabled': 'no',
'Statically Configured DNS Servers': '192.168.0.10'
})
with patch.dict(win_network.__salt__, {'ip.is_enabled': mock_true,
'ip.get_interface': mock_get_int,
'ip.set_static_dns': mock_true}), \
patch.dict(win_network.__opts__, {"test": False}), \
patch.object(win_network, '_validate', mock_validate):
# Don't pass dns_servers
ret = win_network.managed('salt', dns_proto='static', ip_proto='dhcp')
self.assertDictEqual(ret, expected)
# Pass dns_servers=None
ret = win_network.managed(
'salt', dns_proto='static', dns_servers=None, ip_proto='dhcp')
self.assertDictEqual(ret, expected)

View file

@ -16,7 +16,7 @@ from tests.support.helpers import skip_if_not_root
# Import salt libs
import salt.minion
import salt.utils.event as event
from salt.exceptions import SaltSystemExit
from salt.exceptions import SaltSystemExit, SaltMasterUnresolvableError
import salt.syspaths
import tornado
import tornado.testing
@ -282,6 +282,17 @@ class MinionTestCase(TestCase, AdaptedConfigurationTestCaseMixin):
finally:
minion.destroy()
def test_minion_retry_dns_count(self):
'''
Tests that the resolve_dns will retry dns look ups for a maximum of
3 times before raising a SaltMasterUnresolvableError exception.
'''
with patch.dict(__opts__, {'ipv6': False, 'master': 'dummy',
'master_port': '4555',
'retry_dns': 1, 'retry_dns_count': 3}):
self.assertRaises(SaltMasterUnresolvableError,
salt.minion.resolve_dns, __opts__)
@skipIf(NO_MOCK, NO_MOCK_REASON)
class MinionAsyncTestCase(TestCase, AdaptedConfigurationTestCaseMixin, tornado.testing.AsyncTestCase):